-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up docker containerization of frontend for deployment (#64)
* chore: refactored code base to get arguments at runtime * feat: added compose file for better testing * refactored docker runtime code * refactored docker runtime code to support multiple variables * chore: refactored code to accept multiple env variables at runtime passed using docker-compose * chore: removed gh-pages deployment entirely * testing container deployment * testing container deployment * testing container deployment * testing container deployment * fix: fixed lint formatting and failing tests * fix: cleanup after testing * fix: cleanup after testing * testing staging environment backend url * testing staging environment backend url * testing staging environment backend url * testing staging environment backend url * testing staging environment backend url --------- Co-authored-by: Stephane Segning Lambou <[email protected]>
- Loading branch information
1 parent
c88c10d
commit ae018c5
Showing
15 changed files
with
153 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -ex | ||
|
||
sh /docker-entrypoint.sh "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
server { | ||
listen 80; | ||
server_name 127.0.0.1 localhost; | ||
|
||
root /usr/share/nginx/html; | ||
index index.html index.html; | ||
|
||
charset utf-8; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.html; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Compression. | ||
gzip on; | ||
gzip_disable msie6; | ||
gzip_proxied any; | ||
gzip_comp_level 6; | ||
gzip_min_length 0; | ||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf; | ||
|
8 changes: 8 additions & 0 deletions
8
.docker/app/nginx/init-scripts/100-init-project-env-variables.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -ex | ||
|
||
projectEnvVariables=$(ls -t /usr/share/nginx/html/assets/projectEnvVariables*.js | head -n1) | ||
envsubst < "$projectEnvVariables" > ./projectEnvVariables_temp | ||
cp ./projectEnvVariables_temp "$projectEnvVariables" | ||
rm ./projectEnvVariables_temp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
user nginx; | ||
worker_processes auto; | ||
|
||
error_log /var/log/nginx/error.log notice; | ||
pid /var/run/nginx.pid; | ||
|
||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
types { | ||
application/manifest+json webmanifest; | ||
} | ||
|
||
default_type application/octet-stream; | ||
|
||
sendfile on; | ||
|
||
keepalive_timeout 65; | ||
|
||
include /etc/nginx/conf.d/*.conf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_BACKEND_URL="FALLBACK_URL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM node:20-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json package-lock.json ./ | ||
|
||
RUN npm ci | ||
|
||
COPY . . | ||
|
||
ARG NODE_ENV=production | ||
ENV NODE_ENV=${NODE_ENV} | ||
|
||
RUN npm run build | ||
|
||
FROM nginx:alpine | ||
|
||
ARG VITE_BACKEND_URL | ||
|
||
ENV VITE_BACKEND_URL=${VITE_BACKEND_URL} | ||
|
||
ARG PORT=80 | ||
ENV NGINX_PORT=${PORT} | ||
ENV NGINX_HOST=localhost | ||
|
||
EXPOSE ${PORT} | ||
|
||
COPY .docker/app/nginx/nginx.conf /etc/nginx/nginx.conf | ||
COPY .docker/app/nginx/conf.d/ /etc/nginx/conf.d/ | ||
COPY .docker/app/entrypoint.sh /entrypoint.sh | ||
COPY .docker/app/nginx/init-scripts/ /docker-entrypoint.d/ | ||
|
||
WORKDIR /usr/share/nginx/html | ||
|
||
COPY --from=builder /app/dist ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
test-frontend: | ||
build: | ||
context: ./ | ||
ports: | ||
- "2456:80" | ||
environment: | ||
VITE_BACKEND_URL: 'http://localhost:8555' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
type ProjectEnvVariablesType = Pick<ImportMetaEnv, "VITE_BACKEND_URL">; | ||
|
||
const projectEnvVariables: ProjectEnvVariablesType = { | ||
VITE_BACKEND_URL: "${VITE_BACKEND_URL}", | ||
}; | ||
|
||
interface ProjectEnvVariables { | ||
envVariables: ProjectEnvVariablesType; | ||
} | ||
|
||
export const getProjectEnvVariables = (): ProjectEnvVariables => { | ||
return { | ||
envVariables: { | ||
VITE_BACKEND_URL: !projectEnvVariables.VITE_BACKEND_URL.includes("VITE_") | ||
? projectEnvVariables.VITE_BACKEND_URL | ||
: import.meta.env.VITE_BACKEND_URL, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters