-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (208 loc) ยท 8.05 KB
/
dcellar-web-ui-prod-testnet-cicd.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: Frontend CI/CD for Testnet Environment
on:
workflow_call:
inputs:
app_name:
description: "App name in gitops"
required: true
type: string
default: ""
env:
description: "Specify the deployment environment"
required: true
type: string
default: "testnet"
ref:
description: "Specify the branch, tag or SHA to deploy"
required: true
default: "main"
type: string
tag_field:
description: "Nodereal-app tag field"
required: false
type: string
default: ".nodereal-app.image.tag"
git_sync_path:
description: "Git sync path"
required: false
type: string
default: "prod/gitops/tf-nodereal-prod-noderealus/web-ui/dcellar-web-ui/values.yaml"
jobs:
CI:
runs-on: [prod-cicd-runners]
steps:
- name: Checkout ๐๏ธ
uses: actions/checkout@v4
with:
ref: ${{inputs.ref}}
fetch-depth: 0
- name: Get Commit SHA
id: commit_sha
run: |
echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache Rush Dependencies
uses: actions/cache@v4
with:
path: |
common/temp/install-run
common/temp/build-cache
~/.rush
key: ${{ runner.os }}-${{ hashFiles('rush.json') }}
- name: Cache PNPM Dependencies
uses: actions/cache@v4
with:
path: |
common/temp/pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Install Rush Dependencies
run: |
node common/scripts/install-run-rush.js install -t ${{ inputs.app_name }}
- name: Build Rush Project
run: |
COMMIT_SHA=${{ steps.commit_sha.outputs.COMMIT_SHA }} node common/scripts/install-run-rush.js build -t ${{ inputs.app_name }}
- name: Deploy Rush Project
run: |
node common/scripts/install-run-rush.js deploy -p ${{ inputs.app_name }}
- name: Build and Push Docker Image to ECR
id: image
env:
REGION: ${{ secrets.REGION }}
ECR_REGISTRY_ID: ${{ secrets.ECR_REGISTRY_ID }}
APP_NAME: ${{ inputs.app_name }}
run: |
IMAGE_NAME="${ECR_REGISTRY_ID}.dkr.ecr.${REGION}.amazonaws.com/${APP_NAME}:${{ steps.commit_sha.outputs.COMMIT_SHA }}"
aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY_ID}.dkr.ecr.${REGION}.amazonaws.com
DOCKER_BUILDKIT=1 docker build -f apps/${APP_NAME}/Dockerfile . -t ${IMAGE_NAME}
docker push ${IMAGE_NAME}
echo "image_id=$IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Upload Static Files to Prod S3 Bucket
env:
APP_NAME: ${{ inputs.app_name }}
STATIC_BUCKET: ${{ secrets.PROD_S3_BUCKET }}
run: |
aws s3 cp apps/${APP_NAME}/.next/static s3://${STATIC_BUCKET}/static/${APP_NAME}/_next/static --recursive --cache-control "public, max-age=31536000"
aws s3 cp apps/${APP_NAME}/public s3://${STATIC_BUCKET}/static/${APP_NAME} --recursive --cache-control "public, max-age=31536000"
- name: Checkout GitOps Repository for Diff Commits ๐๏ธ
uses: actions/checkout@v4
with:
repository: node-real/nodereal-app
token: ${{ secrets.GO_MODULES_TOKEN }}
path: nodereal-app
- name: Retrieve Online Version Commit ID
id: get_online_commit_id
run: |
COMMIT_ID=$(yq eval "${{ inputs.tag_field }}" "nodereal-app/${{ inputs.git_sync_path }}")
echo "commit_id=${COMMIT_ID}" >> $GITHUB_OUTPUT
- name: Checkout ๐๏ธ
uses: actions/checkout@v4
with:
ref: ${{inputs.ref}}
fetch-depth: 0
- name: Retrieve Release Diff Commits
id: get_diff_commits
continue-on-error: true
run: |
CURRENT_HASH=${{ steps.commit_sha.outputs.COMMIT_SHA }}
LAST_BUILD_HASH=${{steps.get_online_commit_id.outputs.commit_id}}
DIFF=""
if [ -z "$LAST_BUILD_HASH" ]
then
echo "Unable to find last commit by bot, skipping diff gen"
else
DIFF=$(git log ${LAST_BUILD_HASH}...${CURRENT_HASH} --pretty=format:%s )
echo $DIFF
fi
echo 'DIFF<<EOF' >> $GITHUB_ENV
echo "${DIFF}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Checkout Public Github workflows ๐๏ธ
uses: actions/checkout@v4
with:
repository: 'node-real/public-github-workflows'
token: ${{ secrets.GO_MODULES_TOKEN }}
- name: Prune Commit Messages
id: prune_commit_msg
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const diff_commits = `${{env.DIFF}}`
const script = require("${{ github.workspace }}/.github/utils/parse-diff-commits.js");
await script({diff_commits, core});
- name: Checkout ๐๏ธ
uses: actions/checkout@v4
with:
ref: ${{inputs.ref}}
fetch-depth: 0
- name: Generate Artifacts
run: |
mkdir temp
echo "${{ steps.prune_commit_msg.outputs.commits }}" > temp/commit_changes
echo "${{ steps.commit_sha.outputs.COMMIT_SHA }}" > temp/commit_sha
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ github.event.issue.number }}_prod_artifacts"
path: temp
if-no-files-found: error
CD:
runs-on: [prod-cicd-runners]
needs: [CI]
steps:
- name: Checkout GitOps Config Repository ๐๏ธ
uses: actions/checkout@v4
with:
repository: node-real/nodereal-app
token: ${{ secrets.GO_MODULES_TOKEN }}
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: "${{ github.event.issue.number }}_prod_artifacts"
path: ./artifacts
- name: Output Commit Changes
id: output_commits_changes
run: |
DIFF=$(cat artifacts/commit_changes)
echo 'DIFF<<EOF' >> $GITHUB_ENV
echo "${DIFF}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Output Commit SHA
id: output_commit_sha
run: |
COMMIT_SHA=$(cat artifacts/commit_sha)
echo "commit_sha=${COMMIT_SHA}" >> $GITHUB_OUTPUT
- name: Clear Artifacts
uses: geekyeggo/delete-artifact@v5
with:
name: "${{ github.event.issue.number }}_prod_artifacts"
- name: Clean Local Artifacts
run: |
rm -rf artifacts
- name: update image tag in gitops config repo
run: |
yq e "${{ inputs.tag_field }} = \"${{ steps.output_commit_sha.outputs.commit_sha }}\"" -i "${{ inputs.git_sync_path}}"
- name: Set Pull Request Branch Name
id: vars
run: echo "branch-name=github-action-patches/${{ inputs.app_name }}-${{ inputs.env }}/${{ steps.output_commit_sha.outputs.commit_sha }}" >> $GITHUB_OUTPUT
- name: Echo build id
id: echo_build
run: |
echo "build_id=${{ steps.output_commit_sha.outputs.commit_sha }}" >> $GITHUB_OUTPUT
- name: Create Pull Request for Image Update
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GO_MODULES_TOKEN }}
commit-message: Update Image Tag
title: "[web-ui:${{ inputs.app_name }}-${{ inputs.env }}] bot auto-PR by submitted ${{ github.triggering_actor || github.event.issue.user.login }}"
body: |
${{ env.DIFF }}
## Other Info
- Original Code Changes: ${{ github.event.issue.html_url || github.event.pull_request._links.html.href || 'main' }}
- Build Id: ${{ steps.output_commit_sha.outputs.commit_sha }}
branch: ${{ steps.vars.outputs.branch-name }}
labels: |
prod