Merge pull request #13 from sprinthubmobile/feat/gvm #66
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: | |
# https://github.com/actions/setup-java#cache-segment-restore-timeout | |
SEGMENT_DOWNLOAD_TIMEOUT_MINS: '4' | |
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: | | |
echo "${{ secrets.GCLOUD_SERVICE_KEY }}" > cred.json | |
- name: Build Image | |
run: docker build -t web . --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 ${{vars.DOCKER_CRED_HELPER}}/${{vars.IMAGE_PATH}} \ | |
&& docker push ${{vars.DOCKER_CRED_HELPER}}/${{vars.IMAGE_PATH}} | |
- name: Update VM with new image | |
run: | | |
gcloud compute instances update-container ${{vars.VM_NAME}} --zone=${{vars.ZONE}} \ | |
--container-image=${{vars.DOCKER_CRED_HELPER}}/${{vars.IMAGE_PATH}} |