Skip to content

Commit d374cab

Browse files
authored
Merge pull request #1635 from IFRCGo/feature/deploy-storybook
Add helm charts and docker image to deploy IFRC GO UI storybook
2 parents 3132809 + db732fd commit d374cab

File tree

16 files changed

+327
-165
lines changed

16 files changed

+327
-165
lines changed

.changeset/real-olives-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"go-ui-storybook": patch
3+
---
4+
5+
Add Dockerfile and Helm chart to deploy Storybook

.github/workflows/publish-nginx-serve.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish nginx serve image
1+
name: Publish Helm
22

33
on:
44
workflow_dispatch:
@@ -36,7 +36,7 @@ jobs:
3636
env:
3737
IMAGE_NAME: ghcr.io/${{ github.repository }}
3838
run: |
39-
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|:|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
39+
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|[/:]|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
4040
4141
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
4242
if [[ "$BRANCH_NAME" == *"/"* ]]; then
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Publish Storybook Helm
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- develop
8+
- feature/deploy-storybook #TODO remove before PR is merged
9+
10+
permissions:
11+
packages: write
12+
13+
14+
jobs:
15+
publish_image:
16+
name: 🐳 Publish Docker Image
17+
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+
24+
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 }}/go-ui-storybook
38+
run: |
39+
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|[/:]|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
40+
TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)"
41+
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
42+
echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
43+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
44+
echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT
45+
echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}"
46+
47+
- name: 🐳 Set up Docker Buildx
48+
id: buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: 🐳 Cache Docker layers
52+
uses: actions/cache@v4
53+
with:
54+
path: /tmp/.buildx-cache
55+
key: ${{ runner.os }}-buildx-${{ github.ref }}
56+
restore-keys: |
57+
${{ runner.os }}-buildx-refs/develop
58+
${{ runner.os }}-buildx-
59+
60+
- name: 🐳 Docker build
61+
uses: docker/build-push-action@v6
62+
with:
63+
context: .
64+
builder: ${{ steps.buildx.outputs.name }}
65+
file: packages/go-ui-storybook/nginx-serve/Dockerfile
66+
target: nginx-serve
67+
load: true
68+
push: true
69+
tags: ${{ steps.prep.outputs.tagged_image }}
70+
cache-from: type=local,src=/tmp/.buildx-cache
71+
cache-to: type=local,dest=/tmp/.buildx-cache-new
72+
73+
- name: 🐳 Move docker cache
74+
run: |
75+
rm -rf /tmp/.buildx-cache
76+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
77+
78+
publish_helm:
79+
name: ⎈ Publish Helm
80+
needs: publish_image
81+
runs-on: ubuntu-latest
82+
83+
steps:
84+
- name: Checkout code
85+
uses: actions/checkout@v4
86+
87+
- name: Login to GitHub Container Registry
88+
uses: docker/login-action@v3
89+
with:
90+
registry: ghcr.io
91+
username: ${{ github.actor }}
92+
password: ${{ secrets.GITHUB_TOKEN }}
93+
94+
- name: ⎈ Install Helm
95+
uses: azure/setup-helm@v3
96+
97+
- name: ⎈ Tag docker image in Helm Chart values.yaml
98+
env:
99+
IMAGE_NAME: ${{ needs.publish_image.outputs.docker_image_name }}
100+
IMAGE_TAG: ${{ needs.publish_image.outputs.docker_image_tag }}
101+
run: |
102+
# Update values.yaml with latest docker image
103+
sed -i "s|SET-BY-CICD-IMAGE|$IMAGE_NAME|" packages/go-ui-storybook/nginx-serve/helm/values.yaml
104+
sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" packages/go-ui-storybook/nginx-serve/helm/values.yaml
105+
106+
- name: ⎈ Package Helm Chart
107+
id: set-variables
108+
run: |
109+
SHA_SHORT=$(git rev-parse --short HEAD)
110+
sed -i "s/SET-BY-CICD/$SHA_SHORT/g" packages/go-ui-storybook/nginx-serve/helm/Chart.yaml
111+
helm package ./packages/go-ui-storybook/nginx-serve/helm -d .helm-charts
112+
113+
- name: ⎈ Push Helm Chart
114+
env:
115+
IMAGE: ${{ needs.publish_image.outputs.docker_image }}
116+
OCI_REPO: oci://ghcr.io/${{ github.repository }}
117+
run: |
118+
OCI_REPO=$(echo $OCI_REPO | tr '[:upper:]' '[:lower:]')
119+
PACKAGE_FILE=$(ls .helm-charts/*.tgz | head -n 1)
120+
echo "## 🚀 IFRC GO UI Helm Chart 🚀" >> $GITHUB_STEP_SUMMARY
121+
echo "" >> $GITHUB_STEP_SUMMARY
122+
echo "🐳 Tagged Image: **$IMAGE**" >> $GITHUB_STEP_SUMMARY
123+
echo "" >> $GITHUB_STEP_SUMMARY
124+
echo "⎈ Helm push output" >> $GITHUB_STEP_SUMMARY
125+
echo "" >> $GITHUB_STEP_SUMMARY
126+
echo '```bash' >> $GITHUB_STEP_SUMMARY
127+
helm push "$PACKAGE_FILE" $OCI_REPO >> $GITHUB_STEP_SUMMARY
128+
echo '```' >> $GITHUB_STEP_SUMMARY

app/.dockerignore

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

app/Dockerfile

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

app/docker-compose.yml

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"generate:type": "pnpm -F go-web-app generate:type",
1919
"preview": "pnpm -F go-web-app preview",
2020
"storybook": "pnpm -F go-ui-storybook storybook",
21-
"build-storybook": "pnpm -F go-ui-storybook build-storybook",
21+
"build-storybook": "pnpm build:ui && pnpm -F go-ui-storybook build-storybook",
2222
"chromatic": "pnpm -F go-ui-storybook chromatic"
2323
},
2424
"engines": {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# syntax=docker/dockerfile:1-labs
2+
3+
# -------------------------- Dev ---------------------------------------
4+
FROM node:20-bullseye AS dev
5+
6+
RUN apt-get update -y \
7+
&& apt-get install -y --no-install-recommends \
8+
git bash g++ make \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
RUN npm install -g pnpm
12+
13+
ENV PNPM_HOME="/pnpm"
14+
ENV PATH="$PNPM_HOME:$PATH"
15+
RUN corepack enable
16+
17+
WORKDIR /code
18+
19+
RUN git config --global --add safe.directory /code
20+
21+
# -------------------------- Nginx - Builder --------------------------------
22+
FROM dev AS nginx-build
23+
24+
# NOTE: --parents is not yet available in stable syntax, using docker/dockerfile:1-labs
25+
COPY --parents package.json pnpm-lock.yaml pnpm-workspace.yaml ./**/package.json patches/ /code/
26+
27+
RUN corepack prepare --activate
28+
29+
RUN pnpm install
30+
31+
COPY ./packages/ui /code/packages/ui
32+
COPY ./packages/go-ui-storybook /code/packages/go-ui-storybook
33+
34+
RUN pnpm build-storybook
35+
36+
# ---------------------------------------------------------------------------
37+
FROM nginx:alpine AS nginx-serve
38+
39+
LABEL maintainer="IFRC"
40+
LABEL org.opencontainers.image.source="https://github.com/IFRCGo/go-web-app/tree/develop/packages/go-ui-storybook"
41+
42+
COPY ./packages/go-ui-storybook/nginx-serve/nginx.conf.template /etc/nginx/templates/default.conf.template
43+
COPY --from=nginx-build /code/packages/go-ui-storybook/storybook-static /usr/share/nginx/html
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v2
2+
name: ifrcgo-ui-storybook-nginx-serve
3+
description: "Helm Chart to deploy the IFRC GO UI Storybook"
4+
type: application
5+
version: 0.0.1-SET-BY-CICD
6+
sources:
7+
- https://github.com/IFRCGo/go-web-app/tree/develop/packages/go-ui-storybook

0 commit comments

Comments
 (0)