Skip to content

Commit

Permalink
Merge commit 'cd6e31ccd9cfbd8cbb688685851a7d1d962ea340' into subsette…
Browse files Browse the repository at this point in the history
…r_front
  • Loading branch information
devincowan committed Jan 12, 2024
2 parents c614b63 + cd6e31c commit 1f69c40
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
dockerfile: ./frontend/Dockerfile
context: ./
ports:
- 8080:5003
- 8080:8080
restart: unless-stopped
depends_on:
- api
Expand Down
1 change: 1 addition & 0 deletions app/env.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ VITE_APP_ORIGIN=https://localhost
# for nested static deployment, set VITE_APP_BASE=/domain-subsetter/
VITE_APP_BASE=/

# note must end with trailing slash due to vite_app_base
# VITE_APP_FULL_URL=${VITE_APP_ORIGIN}${VITE_APP_BASE}
VITE_APP_FULL_URL=https://localhost/

Expand Down
43 changes: 32 additions & 11 deletions app/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,35 @@ RUN npm install
ADD frontend .
RUN npm run build

FROM nginx:1.24.0 as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
# COPY --from=build-stage .env .env
COPY --from=build-stage /app/nginx.conf /etc/nginx/nginx.conf

# Allow substitution of env vars at runtime
COPY frontend/docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 5003
# FROM nginx:1.24.0 as production-stage
# RUN mkdir /app
# COPY --from=build-stage /app/dist /app
# # COPY --from=build-stage .env .env
# COPY --from=build-stage /app/nginx.conf /etc/nginx/nginx.conf

# # Allow substitution of env vars at runtime
# COPY frontend/docker-entrypoint.sh /
# RUN chmod +x /docker-entrypoint.sh
# ENTRYPOINT ["/docker-entrypoint.sh"]
# EXPOSE 5003
# CMD ["nginx" "-g" "daemon off;"]

# Production layer
FROM caddy:2.7.6-alpine as prod

# Install envsubst command for replacing __env files
# RUN set -x \
# && apk add gettext libintl

COPY frontend/docker-entrypoint.sh /usr/local/bin/

# Copy config
COPY frontend/caddy.docker.json /etc/caddy/caddy.json

# Copy source dist
COPY --from=build-stage /app/dist /srv

EXPOSE 8080

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["caddy", "run", "--config", "/etc/caddy/caddy.json"]
58 changes: 58 additions & 0 deletions app/frontend/caddy.docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"apps":
{
"http":
{
"servers":
{
"web":
{
"automatic_https":
{
"disable": true
},
"listen":
[
":8080"
],
"routes":
[
{
"handle":
[
{
"handler": "file_server",
"root": "/srv"
}
],
"match":
[
{
"path_regexp":
{
"name": "asset",
"pattern": "\\.(br|css|gz|ico|jpg|js|mp3|mp4|png|svg)$"
}
}
],
"terminal": true
},
{
"handle":
[
{
"handler": "rewrite",
"uri": "/index.html"
},
{
"handler": "file_server",
"root": "/srv"
}
]
}
]
}
}
}
}
}
5 changes: 2 additions & 3 deletions app/frontend/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
ROOT_DIR=/app
ROOT_DIR=/srv
# Replace env vars in files served by NGINX
for file in $ROOT_DIR/assets/*.js $ROOT_DIR/index.html;
do
Expand All @@ -10,5 +10,4 @@ do
sed -i 's|VITE_APP_BASE_PLACEHOLDER|'${VITE_APP_BASE}'|g' $file
done

echo "Starting Nginx"
nginx -g 'daemon off;'
exec "$@"
2 changes: 1 addition & 1 deletion app/frontend/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function logIn(callback) {
const authUrl = new URL(json.authorization_url)
// TODO: use an env var for auth redirect instead of hard-coding
// "#" hash routing was not passed from github env secret so had to hard code here.
authUrl.searchParams.set('redirect_uri', `${APP_URL}/#/auth-redirect`)
authUrl.searchParams.set('redirect_uri', `${APP_URL}#/auth-redirect`)
window.open(
authUrl.toString(),
'_blank',
Expand Down
4 changes: 3 additions & 1 deletion app/frontend/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const APP_URL = import.meta.env.VITE_APP_FULL_URL || "VITE_APP_FULL_URL_PLACEHOLDER";
export const APP_BASE = import.meta.env.VITE_APP_BASE || "VITE_APP_BASE_PLACEHOLDER";

let APP_URL_IN = import.meta.env.VITE_APP_FULL_URL || "VITE_APP_FULL_URL_PLACEHOLDER";
export const APP_URL = APP_URL_IN.endsWith("/") ? APP_URL_IN : `${APP_URL_IN}/`

export const API_BASE = import.meta.env.VITE_APP_API_URL || "VITE_APP_API_URL_PLACEHOLDER";
export const ENDPOINTS = {
openapi: `${API_BASE}/openapi.json`,
Expand Down

0 comments on commit 1f69c40

Please sign in to comment.