-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (111 loc) · 4.97 KB
/
build.yaml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Build Playground API
on:
workflow_dispatch:
inputs:
image_tag:
description: 'Docker image tag'
required: true
default: 'latest'
jobs:
build_on_master:
runs-on: ubuntu-latest
environment: develop
permissions:
contents: 'read'
id-token: 'write'
outputs:
develop_image_tag: ${{ steps.set-tag.outputs.develop_image_tag }}
steps:
- uses: 'google-github-actions/auth@v2'
if: ${{ github.ref == 'refs/heads/master' }}
with:
workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDP }}
service_account: ${{ vars.GCP_IDP_SERVICE_ACCOUNT_ARTIFACT_REGISTRY }}
- name: 'Set up Cloud SDK'
if: ${{ github.ref == 'refs/heads/master' }}
uses: 'google-github-actions/setup-gcloud@v2'
with:
version: '>= 363.0.0'
- name: Configure Docker to use gcloud as a credential helper
if: ${{ github.ref == 'refs/heads/master' }}
run: |
gcloud auth configure-docker ${{ vars.GCP_ARTIFACT_ID }}
- name: Pull the develop Docker image
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker pull ${{ vars.GCP_ARTIFACT_REPOSITORY }}/playground/playground-api:${{ github.event.inputs.image_tag }}
- id: set-tag
name: Set docker image tag output
run: echo "develop_image_tag=${{ vars.GCP_ARTIFACT_REPOSITORY }}/playground/playground-api:${{ github.event.inputs.image_tag }}" >> "$GITHUB_OUTPUT"
- name: Save Docker image as tar
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker save -o /tmp/playground-api_${{ github.event.inputs.image_tag }}.tar ${{ vars.GCP_ARTIFACT_REPOSITORY }}/playground/playground-api:${{ github.event.inputs.image_tag }}
- name: Upload artifact
if: ${{ github.ref == 'refs/heads/master' }}
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.inputs.image_tag }}
path: /tmp/playground-api${{ github.event.inputs.image_tag }}.tar
retention-days: 1
deploy:
environment: ${{
github.ref == 'refs/heads/master' && 'production' ||
'develop' }}
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- env:
DEVELOP_IMAGE_TAG: ${{ needs.build_on_master.outputs.develop_image_tag }}
run: echo "$DEVELOP_IMAGE_TAG"
- name: Download artifact
uses: actions/download-artifact@v4
if: ${{ github.ref == 'refs/heads/master' }}
with:
name: ${{ github.event.inputs.image_tag }}
path: /tmp
- name: Load image
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker load --input /tmp/playground-api_${{ github.event.inputs.image_tag }}.tar
docker image ls -a
- name: Checkout code
uses: actions/checkout@v4
with:
repository: 'hedera-dev/playground-backend'
ref: ${{ github.ref }}
- uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: ${{ vars.GCP_PLAYGROUND_WORKLOAD_IDP }}
service_account: ${{ vars.GCP_PLAYGROUND_SERVICE_ACCOUNT }}
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
with:
version: '>= 363.0.0'
- name: Configure Docker to use gcloud as a credential helper
run: |
gcloud auth configure-docker ${{ vars.GCP_ARTIFACT_ID }}
- name: Build or Tag Docker image
run: |
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
echo "Tagging image: ${{ needs.build_on_master.outputs.develop_image_tag }} - to - ${{ vars.GCP_ARTIFACT_REPOSITORY }}/playground/playground-api:${{ github.event.inputs.image_tag }}"
docker tag ${{ needs.build_on_master.outputs.develop_image_tag }} ${{ vars.GCP_ARTIFACT_REPOSITORY }}/playground/playground-api:${{ github.event.inputs.image_tag }}
else
echo "Building image for develop branch"
docker build -t ${{ vars.GCP_ARTIFACT_REPOSITORY }}/playground/playground-api:${{ github.event.inputs.image_tag }} ./app/playground-api/.
fi
- name: Push Docker image to Google Artifact Registry
run: |
docker push ${{ vars.GCP_ARTIFACT_REPOSITORY }}/playground/playground-api:${{ github.event.inputs.image_tag }}
# Should we tag?
#- name: Create and push a new git tag
# if: ${{ github.ref == 'refs/heads/develop' && github.event.inputs.image_tag != 'latest' }}
# run: |
# git config --global user.name 'github-actions[bot]'
# git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# git fetch --all
# git checkout develop
# git tag -a "v${{ github.event.inputs.image_tag }}" -m "Version ${{ github.event.inputs.image_tag }}"
# git push origin "v${{ github.event.inputs.image_tag }}"