-
Notifications
You must be signed in to change notification settings - Fork 315
204 lines (168 loc) · 6.68 KB
/
image-push.yml
File metadata and controls
204 lines (168 loc) · 6.68 KB
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
name: Portal Build and Push Docker Image
on:
push:
tags:
- '*'
env:
NODE_VERSION: '18.20.*'
PYTHON: /usr/bin/python3.7
BUILD_CDN_ASSETS: ${{ vars.BUILD_CDN_ASSETS || 'false' }}
CDN_URL: ${{ secrets.CDN_URL }}
BUILD_DOCKER_IMAGE: ${{ vars.BUILD_DOCKER_IMAGE || 'true' }}
jobs:
build-client:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Create app_dist folder
run: |
cd src/app
mkdir -p app_dist/
rm -rf dist-cdn
- name: Update Browserslist DB
working-directory: src/app/client
run: |
echo "Updating browserslist/caniuse-lite database to include latest browser versions"
# This updates caniuse-lite so Browserslist knows about the newest browser versions
npx browserslist@latest --update-db --no-progress || true
- name: Install Client Dependencies
working-directory: src/app/client
run: |
echo "Installing client dependencies fresh from package.json"
yarn install --prefer-offline --no-progress --production=true
- name: Build Client
working-directory: src/app/client
run: |
if [[ "${{ env.BUILD_DOCKER_IMAGE }}" == "true" ]]; then
npm run build
cd ..
mv app_dist/dist/index.html app_dist/dist/index.ejs
fi
if [[ "${{ env.BUILD_CDN_ASSETS }}" == "true" ]]; then
cd client
npm run build-cdn -- --base-href=${{ env.CDN_URL }}
export sunbird_portal_cdn_url=${{ env.CDN_URL }}
npm run inject-cdn-fallback
fi
- name: List app_dist contents after build-client
run: |
echo "Contents of app_dist after build-client job:"
ls -la src/app/app_dist/
- name: Upload app_dist
uses: actions/upload-artifact@v4
with:
name: client-app-dist
path: src/app/app_dist
retention-days: 1
compression-level: 6
build-server:
runs-on: ubuntu-latest
steps:
- name: Check if BUILD_DOCKER_IMAGE is true
if: ${{ env.BUILD_DOCKER_IMAGE == 'true' }}
run: echo "BUILD_DOCKER_IMAGE is true, proceeding with build-server job."
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Create app_dist folder
run: |
cd src/app
mkdir -p app_dist/
rm -rf dist-cdn
- name: Install and Build Server
run: |
cd src/app
cp -R libs helpers proxy resourcebundles package.json framework.config.js sunbird-plugins routes constants controllers server.js ./../../Dockerfile app_dist
cd app_dist
echo "Installing server dependencies fresh from package.json"
yarn install --prefer-offline --ignore-engines --no-progress --production=true
node helpers/resourceBundles/build.js -task="phraseAppPull"
- name: List app_dist contents after build-server
run: |
echo "Contents of app_dist after build-server job:"
ls -la src/app/app_dist/
- name: Upload app_dist
uses: actions/upload-artifact@v4
with:
name: server-app-dist
path: src/app/app_dist
retention-days: 1
compression-level: 6
docker-build:
needs: [build-server, build-client]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create app_dist directory structure
run: |
mkdir -p src/app/app_dist
mkdir -p temp/client
mkdir -p temp/server
- name: Download client artifact
uses: actions/download-artifact@v4
with:
name: client-app-dist
path: temp/client
- name: Download server artifact
uses: actions/download-artifact@v4
with:
name: server-app-dist
path: temp/server
- name: Merge artifacts into common app_dist
run: |
# Copy client files
cp -r temp/client/* src/app/app_dist/ 2>/dev/null || true
# Copy server files (this will merge, not overwrite everything)
cp -r temp/server/* src/app/app_dist/ 2>/dev/null || true
echo "Final merged contents:"
ls -la src/app/app_dist/
- name: Build Docker Image
run: |
IMAGE_NAME="player"
IMAGE_TAG=$(echo "${{ github.ref_name }}_$(echo $GITHUB_SHA | cut -c1-7)" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} ./src/app/app_dist
- name: Login Docker Registry
if: ${{ env.BUILD_DOCKER_IMAGE == 'true' }}
run: |
echo "Pushing Docker image: ${IMAGE_NAME}:${IMAGE_TAG}"
case "${{ vars.REGISTRY_PROVIDER }}" in
"gcp")
echo "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}" | base64 --decode > $HOME/gcloud-key.json
gcloud auth activate-service-account --key-file=$HOME/gcloud-key.json
gcloud auth configure-docker ${{ secrets.REGISTRY_NAME }}
REGISTRY_URL=$(echo "${{ secrets.REGISTRY_URL }}" | tr '[:upper:]' '[:lower:]')
;;
"azure" | "dockerhub")
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${{ secrets.REGISTRY_NAME }}" \
--username "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
REGISTRY_URL=$(echo "${{ secrets.REGISTRY_URL }}" | tr '[:upper:]' '[:lower:]')
;;
*)
REPO_NAME_LOWERCASE=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
REGISTRY_URL="ghcr.io/$REPO_NAME_LOWERCASE"
;;
esac
echo "REGISTRY_URL=${REGISTRY_URL}" >> $GITHUB_ENV
- name: Push Docker image
if: ${{ env.BUILD_DOCKER_IMAGE == 'true' }}
run: |
docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}
docker push ${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}
echo "Docker image pushed successfully: ${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}"