Skip to content

Merge pull request #18 #70

Merge pull request #18

Merge pull request #18 #70

Workflow file for this run

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
name: Build and Deploy
on:
push:
branches:
- main
# tags: [ "v*.*.*" ]
jobs:
deploy:
env:
IMAGE_NAME: ${{vars.DOCKER_CRED_HELPER}}/${{vars.IMAGE_PATH}}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Authenticate Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCLOUD_SERVICE_KEY }}
- name: Set up Gcloud CLI
uses: google-github-actions/setup-gcloud@v2
with:
version: '>= 363.0.0'
- name: Authenticate Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create Google Default credentials file
run: |
cp ${{ env.GOOGLE_APPLICATION_CREDENTIALS }} cred.json
- name: Build Image
run: docker build -t web -f ${{vars.DOCKER_FILE_NAME}} . --build-arg PROJECT_ID=${{vars.PROJECT_ID}}
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{vars.DOCKER_CRED_HELPER}} -q
- name: Tag and push Docker Image
run: |
docker tag web ${{env.IMAGE_NAME}} \
&& docker push ${{env.IMAGE_NAME}}
- name: Restart VM with new image
run: |
gcloud compute instances update-container ${{vars.VM_NAME}} --zone=${{vars.ZONE}} \
--container-image=${{env.IMAGE_NAME}}