Vendaweb-portal/gitea/workflows/deploy.yml

62 lines
1.7 KiB
YAML

name: Build and Deploy Vendaweb React
on:
push:
branches:
- main
jobs:
build-and-push:
name: Build Docker Image and Push to Harbor
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Harbor Registry
run: echo "${{ secrets.HARBOR_PASSWORD }}" | docker login 10.1.1.124:8082 -u ${{ secrets.HARBOR_USERNAME }} --password-stdin
- name: Extract Branch Name
id: extract_branch
run: |
BRANCH=${GITHUB_REF#refs/heads/}
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
run: |
REPO="10.1.1.124:8082/library/vendaweb-react"
VERSION="v${{ gitea.run_number }}"
BRANCH="${{ steps.extract_branch.outputs.branch }}"
COMMIT_SHA="${{ gitea.sha }}"
SHORT_SHA="${COMMIT_SHA:0:7}"
docker buildx build \
--cache-from=$REPO:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--tag $REPO:$VERSION \
--tag $REPO:latest \
--tag $REPO:$BRANCH \
--tag $REPO:$SHORT_SHA \
--platform linux/amd64 \
--push \
.
- name: Trigger Portainer Webhook
if: success()
run: |
RESPONSE=$(curl -X POST "${{ secrets.PORTAINER_WEBHOOK_FRONT }}" -w "\n%{http_code}" -s -o /dev/null)
if [ "$RESPONSE" -eq 200 ] || [ "$RESPONSE" -eq 201 ]; then
exit 0
else
exit 1
fi
- name: Cleanup
if: always()
run: |
docker logout 10.1.1.124:8082
docker system prune -f --volumes || true