Skip to content

Commit 8894f3c

Browse files
authored
Merge pull request #1447 from IFRCGo/project/alpha-nginx-serve
Project/alpha nginx serve
2 parents a5ad667 + 2f58e53 commit 8894f3c

File tree

17 files changed

+608
-3
lines changed

17 files changed

+608
-3
lines changed

.dockerignore

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Swap files
2+
*.swp
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
env
15+
build
16+
develop-eggs
17+
dist
18+
downloads
19+
eggs
20+
.eggs
21+
lib
22+
lib64
23+
parts
24+
sdist
25+
var
26+
*.egg-info
27+
.installed.cfg
28+
*.egg
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov
42+
.tox
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*,cover
49+
.hypothesis
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
58+
# Sphinx documentation
59+
docs/_build
60+
61+
# PyBuilder
62+
target
63+
64+
#Ipython Notebook
65+
.ipynb_checkpoints
66+
67+
# SASS cache
68+
.sass-cache
69+
media_test
70+
71+
# Rope project settings
72+
.ropeproject
73+
74+
# Logs
75+
logs
76+
*.log
77+
npm-debug.log*
78+
yarn-debug.log*
79+
yarn-error.log*
80+
81+
# Runtime data
82+
pids
83+
*.pid
84+
*.seed
85+
*.pid.lock
86+
87+
# Directory for instrumented libs generated by jscoverage/JSCover
88+
lib-cov
89+
90+
# Coverage directory used by tools like istanbul
91+
coverage
92+
93+
# nyc test coverage
94+
.nyc_output
95+
96+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
97+
.grunt
98+
99+
# Bower dependency directory (https://bower.io/)
100+
bower_components
101+
102+
# node-waf configuration
103+
.lock-wscript
104+
105+
# Compiled binary addons (http://nodejs.org/api/addons.html)
106+
build/Release
107+
108+
# Dependency directories
109+
node_modules
110+
jspm_packages
111+
112+
# Typescript v1 declaration files
113+
typings
114+
115+
# Optional npm cache directory
116+
.npm
117+
118+
# Optional eslint cache
119+
.eslintcache
120+
121+
# Optional REPL history
122+
.node_repl_history
123+
124+
# Output of 'npm pack'
125+
*.tgz
126+
127+
# Yarn Integrity file
128+
.yarn-integrity
129+
130+
# dotenv environment variables file
131+
.env
132+
.env*
133+
134+
# Sensitive Deploy Files
135+
deploy/eb/
136+
137+
# tox
138+
./.tox
139+
140+
# Helm
141+
.helm-charts/

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,19 @@ jobs:
217217
- name: Build
218218
run: yarn build
219219
working-directory: app
220+
221+
validate_helm:
222+
name: Validate Helm
223+
runs-on: ubuntu-latest
224+
225+
steps:
226+
- uses: actions/checkout@main
227+
228+
- name: Install Helm
229+
uses: azure/setup-helm@v4
230+
231+
- name: 🐳 Helm lint
232+
run: helm lint ./nginx-serve/helm --values ./nginx-serve/helm/values-test.yaml
233+
234+
- name: 🐳 Helm template
235+
run: helm template ./nginx-serve/helm --values ./nginx-serve/helm/values-test.yaml
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Publish nginx serve image
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- project/*
8+
9+
permissions:
10+
packages: write
11+
12+
13+
jobs:
14+
publish_image:
15+
name: Publish Docker Image
16+
runs-on: ubuntu-latest
17+
18+
outputs:
19+
docker_image_name: ${{ steps.prep.outputs.tagged_image_name }}
20+
docker_image_tag: ${{ steps.prep.outputs.tag }}
21+
docker_image: ${{ steps.prep.outputs.tagged_image }}
22+
23+
steps:
24+
- uses: actions/checkout@main
25+
26+
- name: Login to GitHub Container Registry
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: 🐳 Prepare Docker
34+
id: prep
35+
env:
36+
IMAGE_NAME: ghcr.io/${{ github.repository }}
37+
run: |
38+
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|:|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
39+
40+
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
41+
if [[ "$BRANCH_NAME" == *"/"* ]]; then
42+
# XXX: Change the docker image package to -alpha
43+
IMAGE_NAME="$IMAGE_NAME-alpha"
44+
TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GITHUB_SHA | head -c7)"
45+
else
46+
TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)"
47+
fi
48+
49+
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
50+
echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
51+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
52+
echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT
53+
echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}"
54+
55+
- name: 🐳 Set up Docker Buildx
56+
id: buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
- name: 🐳 Cache Docker layers
60+
uses: actions/cache@v4
61+
with:
62+
path: /tmp/.buildx-cache
63+
key: ${{ runner.os }}-buildx-${{ github.ref }}
64+
restore-keys: |
65+
${{ runner.os }}-buildx-refs/develop
66+
${{ runner.os }}-buildx-
67+
68+
- name: 🐳 Docker build
69+
uses: docker/build-push-action@v6
70+
with:
71+
context: .
72+
builder: ${{ steps.buildx.outputs.name }}
73+
file: nginx-serve/Dockerfile
74+
target: nginx-serve
75+
load: true
76+
push: true
77+
tags: ${{ steps.prep.outputs.tagged_image }}
78+
cache-from: type=local,src=/tmp/.buildx-cache
79+
cache-to: type=local,dest=/tmp/.buildx-cache-new
80+
build-args: |
81+
"APP_SENTRY_TRACES_SAMPLE_RATE=0.8"
82+
"APP_SENTRY_REPLAYS_SESSION_SAMPLE_RATE=0.8"
83+
"APP_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE=0.8"
84+
85+
- name: 🐳 Move docker cache
86+
run: |
87+
rm -rf /tmp/.buildx-cache
88+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
89+
90+
publish_helm:
91+
name: Publish Helm
92+
needs: publish_image
93+
runs-on: ubuntu-latest
94+
95+
steps:
96+
- name: Checkout code
97+
uses: actions/checkout@v4
98+
99+
- name: Login to GitHub Container Registry
100+
uses: docker/login-action@v3
101+
with:
102+
registry: ghcr.io
103+
username: ${{ github.actor }}
104+
password: ${{ secrets.GITHUB_TOKEN }}
105+
106+
- name: Install Helm
107+
uses: azure/setup-helm@v3
108+
109+
- name: Tag docker image in Helm Chart values.yaml
110+
env:
111+
IMAGE_NAME: ${{ needs.publish_image.outputs.docker_image_name }}
112+
IMAGE_TAG: ${{ needs.publish_image.outputs.docker_image_tag }}
113+
run: |
114+
# Update values.yaml with latest docker image
115+
sed -i "s|SET-BY-CICD-IMAGE|$IMAGE_NAME|" nginx-serve/helm/values.yaml
116+
sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" nginx-serve/helm/values.yaml
117+
118+
- name: Package Helm Chart
119+
id: set-variables
120+
run: |
121+
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
122+
if [[ "$GITHUB_REF_NAME" == *"/"* ]]; then
123+
# XXX: Change the helm chart to <chart-name>-alpha
124+
sed -i 's/^name: \(.*\)/name: \1-alpha/' nginx-serve/helm/Chart.yaml
125+
fi
126+
127+
SHA_SHORT=$(git rev-parse --short HEAD)
128+
sed -i "s/SET-BY-CICD/$SHA_SHORT/g" nginx-serve/helm/Chart.yaml
129+
helm package ./nginx-serve/helm -d .helm-charts
130+
131+
- name: Push Helm Chart
132+
env:
133+
IMAGE: ${{ needs.publish_image.outputs.docker_image }}
134+
OCI_REPO: oci://ghcr.io/${{ github.repository }}
135+
run: |
136+
OCI_REPO=$(echo $OCI_REPO | tr '[:upper:]' '[:lower:]')
137+
PACKAGE_FILE=$(ls .helm-charts/*.tgz | head -n 1)
138+
echo "# Helm Chart" >> $GITHUB_STEP_SUMMARY
139+
echo "" >> $GITHUB_STEP_SUMMARY
140+
echo "Tagged Image: **$IMAGE**" >> $GITHUB_STEP_SUMMARY
141+
echo "" >> $GITHUB_STEP_SUMMARY
142+
echo "Helm push output" >> $GITHUB_STEP_SUMMARY
143+
echo "" >> $GITHUB_STEP_SUMMARY
144+
echo '```bash' >> $GITHUB_STEP_SUMMARY
145+
helm push "$PACKAGE_FILE" $OCI_REPO >> $GITHUB_STEP_SUMMARY
146+
echo '```' >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ generated/
3737
coverage/
3838

3939
# storybook build
40-
storybook-static/
40+
storybook-static/
41+
42+
# Helm
43+
.helm-charts/

app/env.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { defineConfig, Schema } from '@julr/vite-plugin-validate-env';
33
export default defineConfig({
44
APP_TITLE: Schema.string(),
55
APP_ENVIRONMENT: (key, value) => {
6-
const regex = /^production|staging|testing|alpha-\d+|development$/;
6+
// NOTE: APP_ENVIRONMENT_PLACEHOLDER is meant to be used with image builds
7+
// The value will be later replaced with the actual value
8+
const regex = /^production|staging|testing|alpha-\d+|development|APP_ENVIRONMENT_PLACEHOLDER$/;
79
const valid = !!value && (value.match(regex) !== null);
810
if (!valid) {
911
throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`);
1012
}
11-
return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development');
13+
if (value === 'APP_ENVIRONMENT_PLACEHOLDER') {
14+
console.warn(`Using ${value} for app environment. Make sure to not use this for builds without helm chart`)
15+
}
16+
return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development' | 'APP_ENVIRONMENT_PLACEHOLDER');
1217
},
1318
APP_API_ENDPOINT: Schema.string({ format: 'url', protocol: true, tld: false }),
1419
APP_ADMIN_URL: Schema.string.optional({ format: 'url', protocol: true }),

collaborating/repository-structure.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ The `packages/go-ui-storybook` directory contains the stories for the IFRC GO UI
4747

4848
- **`src/stories/`**: Houses all the UI component stories.
4949
- **`.storybook/`**: Contains the configuration for Storybook.
50+
51+
### `nginx-serve` Directory
52+
53+
The `nginx-serve` directory contains nginx config and helm charts to run the web application.
54+
55+
> NOTE: We need to add more information later.

0 commit comments

Comments
 (0)