Skip to content

refactor(deploy): fix versioning Dockerhub #83

refactor(deploy): fix versioning Dockerhub

refactor(deploy): fix versioning Dockerhub #83

Workflow file for this run

# GitHub Actions Workflow: Build and Deploy to VPS
# - Triggers on push to the master branch.
# - Caches the Maven dependencies.
# - Builds and pushes a Docker image to Docker Hub.
# - Deploys the Docker Compose file to a remote VPS.
# - Starts the application on the VPS.
name: Build and Deploy to VPS (test)
on:
push:
branches:
- test-deploy
jobs:
docker:
runs-on: ubuntu-latest
environment: gzgestaoprod
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract version from pom.xml
id: extract_version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('**/mvnw') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build and push to Docker Hub
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/gzgestao:latest
${{ secrets.DOCKERHUB_USERNAME }}/gzgestao:${{ env.VERSION }}