Vendaweb-portal/.gitea/workflows/deploy.yml

75 lines
2.2 KiB
YAML

name: Build and Deploy Vendaweb React
on:
push:
branches:
- main
workflow_dispatch:
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
with:
driver-opts: |
network=host
config-inline: |
[registry."10.1.1.124:8082"]
http = true
insecure = true
- 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: Notificar Portainer via Webhook
if: success()
run: |
if [ -z "${{ secrets.PORTAINER_WEBHOOK_FRONT }}" ]; then
echo "Error: PORTAINER_WEBHOOK_FRONT secret is not set."
exit 1
fi
echo "Notificando Portainer para atualizar o container..."
curl -f -X POST "${{ secrets.PORTAINER_WEBHOOK_FRONT }}" \
--max-time 30 \
--retry 3 \
--retry-delay 2 \
-v
echo "Webhook do Portainer executado com sucesso!"
- name: Cleanup
if: always()
run: |
docker logout 10.1.1.124:8082
docker system prune -f --volumes || true