Skip to content

Commit db2e65d

Browse files
committed
refactor: replace nginx-serve with web-app-serve
1 parent 95b91f1 commit db2e65d

File tree

6 files changed

+38
-186
lines changed

6 files changed

+38
-186
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ build/Release
107107

108108
# Dependency directories
109109
node_modules
110+
**/node_modules
110111
jspm_packages
111112

112113
# Typescript v1 declaration files
@@ -145,4 +146,4 @@ Dockerfile
145146
.dockerignore
146147

147148
# git
148-
.gitignore
149+
.gitignore
Lines changed: 5 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Helm
1+
name: Publish web app serve
22

33
on:
44
workflow_dispatch:
@@ -10,138 +10,14 @@ on:
1010
permissions:
1111
packages: write
1212

13-
1413
jobs:
1514
publish_image:
1615
name: Publish Docker Image
1716
runs-on: ubuntu-latest
18-
19-
outputs:
20-
docker_image_name: ${{ steps.prep.outputs.tagged_image_name }}
21-
docker_image_tag: ${{ steps.prep.outputs.tag }}
22-
docker_image: ${{ steps.prep.outputs.tagged_image }}
23-
2417
steps:
25-
- uses: actions/checkout@main
26-
27-
- name: Login to GitHub Container Registry
28-
uses: docker/login-action@v3
29-
with:
30-
registry: ghcr.io
31-
username: ${{ github.actor }}
32-
password: ${{ secrets.GITHUB_TOKEN }}
33-
34-
- name: 🐳 Prepare Docker
35-
id: prep
36-
env:
37-
IMAGE_NAME: ghcr.io/${{ github.repository }}
38-
run: |
39-
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|[/:]|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
40-
41-
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
42-
if [[ "$BRANCH_NAME" == *"/"* ]]; then
43-
# XXX: Change the docker image package to -alpha
44-
IMAGE_NAME="$IMAGE_NAME-alpha"
45-
TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GITHUB_SHA | head -c7)"
46-
else
47-
TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)"
48-
fi
49-
50-
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
51-
echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
52-
echo "tag=${TAG}" >> $GITHUB_OUTPUT
53-
echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT
54-
echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}"
55-
56-
- name: 🐳 Set up Docker Buildx
57-
id: buildx
58-
uses: docker/setup-buildx-action@v3
59-
60-
- name: 🐳 Cache Docker layers
61-
uses: actions/cache@v4
62-
with:
63-
path: /tmp/.buildx-cache
64-
key: ${{ runner.os }}-buildx-${{ github.ref }}
65-
restore-keys: |
66-
${{ runner.os }}-buildx-refs/develop
67-
${{ runner.os }}-buildx-
18+
- uses: actions/checkout@v4
6819

69-
- name: 🐳 Docker build
70-
uses: docker/build-push-action@v6
20+
- name: Publish web-app-serve
21+
uses: toggle-corp/web-app-serve/.github/actions/[email protected]
7122
with:
72-
context: .
73-
builder: ${{ steps.buildx.outputs.name }}
74-
file: nginx-serve/Dockerfile
75-
target: nginx-serve
76-
load: true
77-
push: true
78-
tags: ${{ steps.prep.outputs.tagged_image }}
79-
cache-from: type=local,src=/tmp/.buildx-cache
80-
cache-to: type=local,dest=/tmp/.buildx-cache-new
81-
build-args: |
82-
"APP_SENTRY_TRACES_SAMPLE_RATE=0.8"
83-
"APP_SENTRY_REPLAYS_SESSION_SAMPLE_RATE=0.8"
84-
"APP_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE=0.8"
85-
86-
- name: 🐳 Move docker cache
87-
run: |
88-
rm -rf /tmp/.buildx-cache
89-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
90-
91-
publish_helm:
92-
name: Publish Helm
93-
needs: publish_image
94-
runs-on: ubuntu-latest
95-
96-
steps:
97-
- name: Checkout code
98-
uses: actions/checkout@v4
99-
100-
- name: Login to GitHub Container Registry
101-
uses: docker/login-action@v3
102-
with:
103-
registry: ghcr.io
104-
username: ${{ github.actor }}
105-
password: ${{ secrets.GITHUB_TOKEN }}
106-
107-
- name: Install Helm
108-
uses: azure/setup-helm@v3
109-
110-
- name: Tag docker image in Helm Chart values.yaml
111-
env:
112-
IMAGE_NAME: ${{ needs.publish_image.outputs.docker_image_name }}
113-
IMAGE_TAG: ${{ needs.publish_image.outputs.docker_image_tag }}
114-
run: |
115-
# Update values.yaml with latest docker image
116-
sed -i "s|SET-BY-CICD-IMAGE|$IMAGE_NAME|" nginx-serve/helm/values.yaml
117-
sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" nginx-serve/helm/values.yaml
118-
119-
- name: Package Helm Chart
120-
id: set-variables
121-
run: |
122-
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
123-
if [[ "$GITHUB_REF_NAME" == *"/"* ]]; then
124-
# XXX: Change the helm chart to <chart-name>-alpha
125-
sed -i 's/^name: \(.*\)/name: \1-alpha/' nginx-serve/helm/Chart.yaml
126-
fi
127-
128-
SHA_SHORT=$(git rev-parse --short HEAD)
129-
sed -i "s/SET-BY-CICD/$SHA_SHORT/g" nginx-serve/helm/Chart.yaml
130-
helm package ./nginx-serve/helm -d .helm-charts
131-
132-
- name: Push Helm Chart
133-
env:
134-
IMAGE: ${{ needs.publish_image.outputs.docker_image }}
135-
OCI_REPO: oci://ghcr.io/${{ github.repository }}
136-
run: |
137-
OCI_REPO=$(echo $OCI_REPO | tr '[:upper:]' '[:lower:]')
138-
PACKAGE_FILE=$(ls .helm-charts/*.tgz | head -n 1)
139-
echo "# Helm Chart" >> $GITHUB_STEP_SUMMARY
140-
echo "" >> $GITHUB_STEP_SUMMARY
141-
echo "Tagged Image: **$IMAGE**" >> $GITHUB_STEP_SUMMARY
142-
echo "" >> $GITHUB_STEP_SUMMARY
143-
echo "Helm push output" >> $GITHUB_STEP_SUMMARY
144-
echo "" >> $GITHUB_STEP_SUMMARY
145-
echo '```bash' >> $GITHUB_STEP_SUMMARY
146-
helm push "$PACKAGE_FILE" $OCI_REPO >> $GITHUB_STEP_SUMMARY
147-
echo '```' >> $GITHUB_STEP_SUMMARY
23+
github_token: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN corepack enable
1010
WORKDIR /code
1111

1212
# -------------------------- Nginx - Builder --------------------------------
13-
FROM dev AS nginx-build
13+
FROM dev AS web-app-build
1414

1515
# NOTE: --parents is not yet available in stable syntax, using docker/dockerfile:1-labs
1616
COPY --parents package.json pnpm-lock.yaml pnpm-workspace.yaml ./**/package.json patches/ /code/
@@ -42,16 +42,14 @@ ENV APP_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE=${APP_SENTRY_REPLAYS_ON_ERROR_SAMPLE
4242
RUN pnpm build
4343

4444
# ---------------------------------------------------------------------------
45-
FROM nginx:bookworm AS nginx-serve
45+
FROM ghcr.io/toggle-corp/web-app-serve:v0.1.1 AS web-app-serve
4646

4747
LABEL maintainer="IFRC"
4848
LABEL org.opencontainers.image.source="https://github.com/IFRCGo/go-web-app"
4949

50-
COPY ./nginx-serve/apply-config.sh /docker-entrypoint.d/
51-
COPY ./nginx-serve/nginx.conf.template /etc/nginx/templates/default.conf.template
52-
COPY --from=nginx-build /code/build /code/build
53-
5450
# NOTE: Used by apply-config.sh
51+
ENV APPLY_CONFIG__APPLY_CONFIG_PATH=/code/apply-config.sh
5552
ENV APPLY_CONFIG__SOURCE_DIRECTORY=/code/build/
56-
ENV APPLY_CONFIG__DESTINATION_DIRECTORY=/usr/share/nginx/html/
57-
ENV APPLY_CONFIG__OVERWRITE_DESTINATION=true
53+
54+
COPY --from=web-app-build /code/build "$APPLY_CONFIG__SOURCE_DIRECTORY"
55+
COPY ./web-app-serve/apply-config.sh "$APPLY_CONFIG__APPLY_CONFIG_PATH"

web-app-serve/apply-config.sh

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
#!/bin/bash -xe
22

3-
SOURCE_DIRECTORY=${APPLY_CONFIG__SOURCE_DIRECTORY?Required}
4-
DESTINATION_DIRECTORY=${APPLY_CONFIG__DESTINATION_DIRECTORY?Required}
5-
6-
# Parse arguments for --overwrite option
7-
OVERWRITE_DESTINATION=${APPLY_CONFIG__OVERWRITE_DESTINATION:-false}
8-
for arg in "$@"; do
9-
if [[ "$arg" == "--overwrite" ]]; then
10-
OVERWRITE_DESTINATION=true
11-
fi
12-
done
13-
14-
if [ -d "$DESTINATION_DIRECTORY" ]; then
15-
if [ "$OVERWRITE_DESTINATION" == "true" ]; then
16-
echo "Destination directory <$DESTINATION_DIRECTORY> already exists. Force deleting..."
17-
rm -rf "$DESTINATION_DIRECTORY"
18-
else
19-
echo "Destination directory <$DESTINATION_DIRECTORY> already exists. Please delete and try again, or use --overwrite to force delete."
20-
exit 1
21-
fi
22-
fi
23-
24-
mkdir -p $(dirname "$DESTINATION_DIRECTORY")
25-
cp -r --no-target-directory "$SOURCE_DIRECTORY" "$DESTINATION_DIRECTORY"
26-
273
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<APP_TITLE_PLACEHOLDER\>|$APP_TITLE|g" {} +
284
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<APP_ENVIRONMENT_PLACEHOLDER\>|$APP_ENVIRONMENT|g" {} +
295
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<APP_MAPBOX_ACCESS_TOKEN_PLACEHOLDER\>|$APP_MAPBOX_ACCESS_TOKEN|g" {} +
@@ -34,9 +10,3 @@ find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<https://APP-API-ENDPOINT
3410
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<https://APP-RISK-API-ENDPOINT-PLACEHOLDER.COM/|$APP_RISK_API_ENDPOINT|g" {} +
3511
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<https://APP-SDT-URL-PLACEHOLDER.COM/|$APP_SDT_URL|g" {} +
3612
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<https://APP-SENTRY-DSN-PLACEHOLDER.COM\>|$APP_SENTRY_DSN|g" {} +
37-
38-
# Show diffs (Useful to debug issues)
39-
set +xe
40-
find "$SOURCE_DIRECTORY" -type f -printf '%P\n' | while IFS= read -r file; do
41-
diff -W 100 <(fold -w 100 "$SOURCE_DIRECTORY/$file") <(fold -w 100 "$DESTINATION_DIRECTORY/$file") --suppress-common-lines
42-
done

web-app-serve/docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: go-api-web-app-serve
2+
3+
services:
4+
web-app-serve:
5+
build:
6+
context: ../
7+
target: web-app-serve
8+
environment:
9+
APPLY_CONFIG__ENABLE_DEBUG: true
10+
# App configs (Placeholder replacement)
11+
APP_TITLE: ${APP_TITLE:-GO API}
12+
APP_ENVIRONMENT: ${APP_ENVIRONMENT:-Staging}
13+
APP_MAPBOX_ACCESS_TOKEN: ${APP_MAPBOX_ACCESS_TOKEN:-my-secret-mapbox-access-token}
14+
APP_TINY_API_KEY: ${APP_TINY_API_KEY:-my-secret-tiny-api-key}
15+
APP_API_ENDPOINT: ${APP_API_ENDPOINT:-https://goadmin-stage.ifrc.org/api/}
16+
APP_RISK_API_ENDPOINT: ${APP_RISK_API_ENDPOINT:-https://go-risk-staging.northeurope.cloudapp.azure.com/api/}
17+
APP_SDT_URL: ${APP_SDT_URL:-https://surveydesigner-stage-api.ifrc.org}
18+
APP_SENTRY_DSN: ${APP_SENTRY_DSN:-https://[email protected]/123}
19+
ports:
20+
- '8001:80'
21+
develop:
22+
watch:
23+
- action: sync+restart
24+
path: ./apply-config.sh
25+
target: /code/apply-config.sh

web-app-serve/nginx.conf.template

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)