-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (156 loc) · 5.32 KB
/
build-and-push.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Build, Push, and Deploy
concurrency:
group: $${{ github.ref_name }}
on:
push:
branches:
- 'develop'
- 'master'
tags:
- 'v*'
pull_request:
types:
- 'opened'
- 'synchronize'
- 'reopened'
- 'closed'
branches:
- 'develop'
- 'master'
jobs:
build:
name: Build Container Image
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.deploy-tag.outputs.image_tag }}
image_name: ${{ steps.deploy-tag.outputs.image_name }}
environment_name: ${{ steps.deploy-info.outputs.environment_name }}
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Parse deployment info
id: deploy-info
run: |
# Determine environment to deploy to
if ${{ github.ref == 'master' || github.base_ref == 'master'}}; then
environment_name="int"
credentials_json='${{ secrets.SKYVIEWER_INT_SERVICE_ACCOUNT }}'
elif ${{ github.ref_type == 'tag'}}; then
environment_name="prod"
credentials_json='${{ secrets.PIPELINE_EPO_PROD_PROJECT }}'
else
environment_name="dev"
credentials_json='${{ secrets.DEV_SA_KEY }}'
fi
echo environment_name=$environment_name >> "$GITHUB_OUTPUT"
echo credentials_json=$credentials_json >> "$GITHUB_OUTPUT"
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
gcr.io/skyviewer/rubinobs-client,enable=${{ steps.deploy-info.outputs.environment_name == 'dev' }}
gcr.io/edc-int-6c5e/rubinobs-client,enable=${{ steps.deploy-info.outputs.environment_name == 'int' }}
gcr.io/edc-prod-eef0/rubinobs-client,enable=${{ steps.deploy-info.outputs.environment_name == 'prod' }}
flavor: |
latest=${{ github.event_name == 'push'}}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
build-args: |
RUN_BUILD=false
-
name: Get deploy tag
id: deploy-tag
run: |
# Parse container image tag to deploy
full_tag=$(echo "$DOCKER_METADATA_OUTPUT_JSON" | jq -r '.tags[] | limit(1; select(. | test(":sha-|:v.")))')
echo "Will use tag \"$full_tag\" for deployment."
echo image_tag=$(echo "$full_tag" | cut -f2 -d:) >> "$GITHUB_OUTPUT"
echo image_name=$(echo "$full_tag" | cut -f1 -d:) >> "$GITHUB_OUTPUT"
echo full_tag=$full_tag >> "$GITHUB_OUTPUT"
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to GCP
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ steps.deploy-info.outputs.credentials_json }}
-
name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
-
run: gcloud --quiet auth configure-docker
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-to: |
type=gha
cache-from: |
type=gha
build-args: |
RUN_BUILD=false
-
name: Summary
run: |
cat <<-EOT >> "$GITHUB_STEP_SUMMARY"
# Container Build Completed
## Tags
${{ steps.meta.outputs.tags }}
EOT
deploy:
name: Trigger deploy to ${{ needs.build.outputs.environment_name }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Generate Webhook Payload
id: payload
run: |-
PARAMETERS=(
client.image.tag=${{ needs.build.outputs.image_tag }}
client.image.repository=${{ needs.build.outputs.image_name }}
)
DATA="{
\"app_name\": \"rubinobs-site\",
\"environment_name\": \"${{ needs.build.outputs.environment_name }}\",
\"parameters\": $(jq -c -n '$ARGS.positional' --args ${PARAMETERS[@]})
}"
echo "data=$(echo $DATA | jq -rc '.')" >> "$GITHUB_OUTPUT"
- uses: lasith-kg/[email protected]
id: dispatch
name: Trigger Deployment
with:
dispatch-method: repository_dispatch
repo: edc-deploy
owner: lsst-epo
event-type: app_update_values
token: ${{ secrets.EDC_DEPLOY_GITHUB_TOKEN_FOR_REST_API }}
workflow-inputs: ${{ steps.payload.outputs.data }}
discover: true
- name: Await Run ID ${{ steps.dispatch.outputs.run-id }}
uses: Codex-/[email protected]
with:
token: ${{ secrets.EDC_DEPLOY_GITHUB_TOKEN_FOR_REST_API }}
repo: edc-deploy
owner: lsst-epo
run_id: ${{ steps.dispatch.outputs.run-id }}
run_timeout_seconds: 1500