|
1 | | -name: build |
| 1 | +name: deploy |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
7 | 7 |
|
| 8 | + workflow_dispatch: |
| 9 | + |
8 | 10 | # Environment variables available to all jobs and steps in this workflow |
| 11 | +# NOTE: these aren't really secret, but there aren't non-secret settings |
9 | 12 | env: |
10 | 13 | RUN_PROJECT: ${{ secrets.RUN_PROJECT }} |
11 | 14 | RUN_REGION: ${{ secrets.RUN_REGION }} |
12 | 15 | RUN_SERVICE: ${{ secrets.RUN_SERVICE }} |
13 | 16 |
|
14 | 17 | jobs: |
15 | | - setup-build-deploy: |
16 | | - name: Setup, Build, and Deploy |
| 18 | + deploy: |
| 19 | + name: Deploy to CloudRun |
17 | 20 | runs-on: ubuntu-latest |
18 | 21 |
|
19 | 22 | steps: |
20 | 23 | - name: Checkout |
21 | | - uses: actions/checkout@v1 |
| 24 | + uses: actions/checkout@v4 |
22 | 25 |
|
23 | | - - name: Set up JDK 1.8 |
24 | | - uses: actions/setup-java@v1 |
| 26 | + - name: gcloud auth |
| 27 | + id: 'auth' |
| 28 | + uses: 'google-github-actions/auth@v2' |
25 | 29 | with: |
26 | | - java-version: 1.8 |
27 | | - |
28 | | - - name: Set COMMIT and LASTMOD |
29 | | - run: | |
30 | | - sudo apt-get install -y xmlstarlet |
31 | | - xmlstarlet edit --inplace --update "//_:web-app/_:context-param/_:param-name[text()='COMMIT']/parent::*/_:param-value" -v ${GITHUB_SHA:0:7} www/WEB-INF/web.xml |
32 | | - xmlstarlet edit --inplace --update "//_:web-app/_:context-param/_:param-name[text()='LASTMOD']/parent::*/_:param-value" -v "$(date -u +%Y-%m-%dT%H:%M:%SZ)" www/WEB-INF/web.xml |
| 30 | + credentials_json: '${{ secrets.GCP_SA_KEY }}' |
33 | 31 |
|
34 | 32 | # Setup gcloud CLI |
35 | | - - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master |
36 | | - with: |
37 | | - version: '275.0.0' |
38 | | - service_account_email: ${{ secrets.GCP_SA_EMAIL }} |
39 | | - service_account_key: ${{ secrets.GCP_SA_KEY }} |
| 33 | + - name: gcloud setup |
| 34 | + uses: google-github-actions/setup-gcloud@v2 |
40 | 35 |
|
41 | | - # Configure gcloud CLI |
42 | | - - name: gcloud Set up |
43 | | - run: | |
44 | | - gcloud config set project $RUN_PROJECT |
| 36 | + - name: gcloud docker-auth |
| 37 | + run: gcloud auth configure-docker |
45 | 38 |
|
46 | 39 | # Build and push image to Google Container Registry |
47 | | - - name: Docker Build |
| 40 | + - name: Build |
48 | 41 | run: | |
49 | | - docker build -t gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA . |
| 42 | + docker build \ |
| 43 | + --build-arg COMMIT=${GITHUB_SHA:0:7} \ |
| 44 | + --build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \ |
| 45 | + --tag gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \ |
| 46 | + . |
50 | 47 |
|
51 | 48 | - name: GCloud auth to docker |
52 | 49 | run: | |
53 | 50 | gcloud auth configure-docker |
54 | 51 |
|
55 | 52 | - name: Push to registry |
56 | 53 | run: | |
57 | | - docker push gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA |
| 54 | + docker push gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA |
58 | 55 |
|
59 | 56 | # Deploy image to Cloud Run |
60 | 57 | - name: Deploy |
61 | 58 | run: | |
62 | | - gcloud run deploy $RUN_SERVICE \ |
| 59 | + gcloud run deploy ${RUN_SERVICE} \ |
63 | 60 | --allow-unauthenticated \ |
64 | | - --image gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA \ |
| 61 | + --image gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \ |
65 | 62 | --platform managed \ |
66 | 63 | --project ${RUN_PROJECT} \ |
67 | | - --region $RUN_REGION |
| 64 | + --region ${RUN_REGION} |
0 commit comments