-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (46 loc) · 1.67 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- 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: Build with Maven
run: mvn -B package -DskipTests
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{vars.DOCKER_CRED_HELPER}} -q
- 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}}