Skip to content

Commit 3a1f1b5

Browse files
authored
Merge pull request #959 from Code4GovTech/feat/c4gt-2024-navbar
C4GT 2024 Frontend
2 parents b5c4524 + e818b62 commit 3a1f1b5

24 files changed

+1439
-26
lines changed

.github/workflows/deploy.yml

Lines changed: 130 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,142 @@
1-
name: Test and deploy
1+
name: Build
2+
3+
env:
4+
APP_NAME: CMS-FE
5+
PROJECT_NAME: CMS-FE
6+
DOCKER_COMPOSE_PATH: /root/app/docker-compose.yml
7+
REGISTRY: ghcr.io
8+
DOCKER_REGISTRY: ghcr.io/code4govtech/dmp-cms-fe
9+
DOT_ENV_FILE_NAME: env.dmp-cms-fe
210

311
on:
12+
workflow_dispatch:
413
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
14+
branches:
15+
- dev
16+
- main
17+
18+
permissions:
19+
contents: write
20+
packages: write
21+
822

923
jobs:
10-
build:
24+
set_vars:
25+
name: Set Environment Variables
26+
runs-on: ubuntu-latest
27+
outputs:
28+
TAG_LATEST: ${{ steps.tag_values.outputs.TAG_LATEST }}
29+
TAG_ENV_COMMIT: ${{ steps.tag_values.outputs.TAG_ENV_COMMIT }}
30+
APP_ENV: ${{ steps.tag_values.outputs.APP_ENV }}
31+
steps:
32+
- name: Set Docker Image Tags
33+
id: tag_values
34+
run: |
35+
case "${{ github.ref }}" in
36+
'refs/heads/main')
37+
echo "TAG_LATEST=prod-latest" >> $GITHUB_OUTPUT
38+
echo "TAG_ENV_COMMIT=prod-${GITHUB_SHA:0:5}" >> $GITHUB_OUTPUT
39+
echo "APP_ENV=PROD" >> $GITHUB_OUTPUT
40+
;;
41+
'refs/heads/devops')
42+
echo "TAG_LATEST=dev-latest" >> $GITHUB_OUTPUT
43+
echo "TAG_ENV_COMMIT=dev-${GITHUB_SHA:0:5}" >> $GITHUB_OUTPUT
44+
echo "APP_ENV=DEV" >> $GITHUB_OUTPUT
45+
;;
46+
'refs/heads/dev')
47+
echo "TAG_LATEST=dev-latest" >> $GITHUB_OUTPUT
48+
echo "TAG_ENV_COMMIT=dev-${GITHUB_SHA:0:5}" >> $GITHUB_OUTPUT
49+
echo "APP_ENV=DEV" >> $GITHUB_OUTPUT
50+
;;
51+
esac
1152
53+
build:
54+
name: Build
1255
runs-on: ubuntu-latest
56+
needs: [set_vars]
57+
permissions:
58+
contents: read
59+
packages: write
60+
env:
61+
TAG_LATEST: ${{ needs.set_vars.outputs.TAG_LATEST }}
62+
TAG_ENV_COMMIT: ${{ needs.set_vars.outputs.TAG_ENV_COMMIT }}
63+
API_BASE_URL: ${{ vars[format('APP_{0}_API_BASE_URL', needs.set_vars.outputs.APP_ENV)] }}
64+
API_AUTH_KEY: ${{ secrets[format('APP_{0}_API_AUTH_KEY', needs.set_vars.outputs.APP_ENV)] }}
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v2
1368

14-
strategy:
15-
matrix:
16-
node-version: [16.x]
69+
# - name: Login to GitHub Packages
70+
# run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
1771

18-
steps:
19-
- name: Checkout repository
20-
uses: actions/checkout@v2
72+
- name: Log in to the Container registry
73+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
74+
with:
75+
registry: ${{ env.REGISTRY }}
76+
username: ${{ github.actor }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
2178

22-
- name: Set up Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v1
24-
with:
25-
node-version: ${{ matrix.node-version }}
79+
- name: Set Docker Tags
80+
uses: actions/setup-node@v2
2681

27-
- name: Install dependencies
28-
run: yarn install --frozen-lockfile
82+
- name: Read Secrets
83+
run: |
84+
echo "API_BASE_URL=${API_BASE_URL}" >> .env
85+
echo "API_AUTH_KEY=${API_AUTH_KEY}" >> .env
86+
cp .env ${{ env.DOT_ENV_FILE_NAME }}
87+
88+
- name: Copy env file to DEV Server
89+
uses: appleboy/[email protected]
90+
if: needs.set_vars.outputs.APP_ENV == 'DEV'
91+
with:
92+
host: ${{ vars.DEV_SERVER_HOST }}
93+
username: ${{ vars.DEV_SERVER_USERNAME }}
94+
key: ${{ secrets.DEV_SSH_PRIVATE_KEY }}
95+
port: ${{ vars.DEV_SERVER_PORT }}
96+
source: "${{ env.DOT_ENV_FILE_NAME }}"
97+
target: /root/app/
98+
99+
- name: Build ${{ env.APP_NAME }} Docker image
100+
run: |
101+
docker build --build-arg API_BASE_URL=$API_BASE_URL --build-arg API_AUTH_KEY=$API_AUTH_KEY -t ${{ env.DOCKER_REGISTRY }}:${{ env.TAG_LATEST }} .
102+
103+
- name: Add tag to Docker image
104+
run: |
105+
echo ${{ github.sha }}
106+
docker tag ${{ env.DOCKER_REGISTRY }}:${{ env.TAG_LATEST }} ${{ env.DOCKER_REGISTRY }}:${{ env.TAG_ENV_COMMIT }}
107+
108+
- name: Push Docker image to GitHub Packages
109+
run: |
110+
docker push ${{ env.DOCKER_REGISTRY }}:${{ env.TAG_LATEST }}
111+
docker push ${{ env.DOCKER_REGISTRY }}:${{ env.TAG_ENV_COMMIT }}
112+
113+
deploy:
114+
name: Deployment
115+
runs-on: ubuntu-latest
116+
needs: build
117+
if: github.event_name == 'push' && github.ref_type == 'branch'
118+
119+
steps:
120+
- name: Deploy to DevOps/Dev Environment
121+
if: github.ref == 'refs/heads/devops' || github.ref == 'refs/heads/dev'
122+
uses: appleboy/[email protected]
123+
env:
124+
DOCKER_COMPOSE_PATH: ${{ env.DOCKER_COMPOSE_PATH }}
125+
APP_NAME: ${{ env.APP_NAME }}
126+
DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }}
127+
with:
128+
host: ${{ vars.DEV_SERVER_HOST }}
129+
username: ${{ vars.DEV_SERVER_USERNAME }}
130+
key: ${{ secrets.DEV_SSH_PRIVATE_KEY }}
131+
port: ${{ vars.DEV_SERVER_PORT }}
132+
allenvs: true
133+
script_stop: true
134+
envs: DOCKER_COMPOSE_PATH,APP_NAME,DOCKER_REGISTRY
135+
script: |
136+
echo "Docker Compose Path $DOCKER_COMPOSE_PATH"
137+
docker compose -f $DOCKER_COMPOSE_PATH pull
138+
docker compose -f $DOCKER_COMPOSE_PATH up -d
29139
30-
- name: Build
31-
run: yarn build
140+
- name: Deploy to Prod environment
141+
if: github.ref == 'refs/heads/main'
142+
run: echo "Deploying to Kubernetes"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ npm-shrinkwrap.json
1717

1818
# Misc
1919
.DS_Store
20+
.env
2021
.env.local
2122
.env.development.local
2223
.env.test.local

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# syntax=docker/dockerfile:1
2+
3+
## Start with a base image containing NodeJS so we can build Docusaurus.
4+
FROM node:lts as base
5+
## Disable colour output from yarn to make logs easier to read.
6+
ENV FORCE_COLOR=0
7+
## Enable corepack.
8+
RUN corepack enable
9+
## Set the working directory to `/opt/docusaurus`.
10+
WORKDIR /opt/docusaurus
11+
12+
# Stage 2b: Production build mode.
13+
FROM base as prod
14+
## Set the working directory to `/opt/docusaurus`.
15+
WORKDIR /opt/docusaurus
16+
## Copy over the source code.
17+
COPY . /opt/docusaurus/
18+
## Install dependencies with `--immutable` to ensure reproducibility.
19+
RUN npm ci
20+
21+
ARG API_BASE_URL
22+
ARG API_AUTH_KEY
23+
24+
ENV API_BASE_URL=$API_BASE_URL
25+
ENV API_AUTH_KEY=$API_AUTH_KEY
26+
27+
## Build the static site.
28+
RUN npm run build
29+
30+
# Stage 3a: Serve with `docusaurus serve`.
31+
FROM prod as serve
32+
## Expose the port that Docusaurus will run on.
33+
EXPOSE 3000
34+
35+
ENV NODE_ENV=production
36+
ENV API_BASE_URL=$API_BASE_URL
37+
ENV API_AUTH_KEY=$API_AUTH_KEY
38+
## Run the production server.
39+
CMD ["npm", "run", "serve", "--", "--host", "0.0.0.0"]

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "docusaurus"
2+
services:
3+
serve:
4+
build:
5+
context: .
6+
args:
7+
API_BASE_URL: ${API_BASE_URL}
8+
API_AUTH_KEY: ${API_AUTH_KEY}
9+
target: serve
10+
ports:
11+
- "3000:3000"
12+
environment:
13+
- NODE_ENV=production
14+
- API_BASE_URL=${API_BASE_URL}
15+
- API_AUTH_KEY=${API_AUTH_KEY}

0 commit comments

Comments
 (0)