name: Build and Deploy on: push: branches: [main] workflow_dispatch: jobs: build-and-deploy: runs-on: ubuntu-latest container: image: openjdk:21 options: -v /var/run/docker.sock:/var/run/docker.sock steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Maven cache uses: actions/cache@v4 with: path: ~/.m2/repository key: maven-${{ hashFiles('pom.xml') }} restore-keys: maven- - name: Build with Maven run: mvn clean install -Dmaven.test.skip=true - name: Build Docker image run: | docker build -t auth-backend:latest -t auth-backend:${{ github.sha }} . - name: Deploy run: | docker stop auth-backend-container || true docker rm auth-backend-container || true docker run -d \ --name auth-backend-container \ --network nginx \ -p 9001:9001 \ --restart unless-stopped \ auth-backend:latest