Skip to content

Commit ad5beed

Browse files
authored
Merge pull request #23 from toggle-corp/feat/remove-nginx-serve
Replace nginx-serve with web-app-serve
2 parents a49fbb5 + 9146c6e commit ad5beed

File tree

14 files changed

+472
-321
lines changed

14 files changed

+472
-321
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,16 @@ typings
130130
# dotenv environment variables file
131131
.env
132132
.env*
133+
**/.env
134+
**/.env*
133135

134136
# Sensitive Deploy Files
135137
deploy/eb/
136138

137139
# tox
138140
./.tox
141+
142+
143+
# Backend
144+
backend
145+
!backend/schema.graphql

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

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish web app serve
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- develop
8+
9+
permissions:
10+
packages: write
11+
12+
jobs:
13+
publish_image:
14+
name: Publish Docker Image
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
submodules: true
20+
21+
- name: Publish web-app-serve
22+
uses: toggle-corp/web-app-serve-action@v0.1.1
23+
with:
24+
github_token: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,45 @@ RUN apt-get update -y \
1212
WORKDIR /code
1313

1414
# -------------------------- Nginx - Builder --------------------------------
15-
FROM dev AS nginx-build
15+
FROM dev AS web-app-serve-build
1616

1717
COPY ./package.json ./pnpm-lock.yaml /code/
1818

1919
RUN pnpm install
2020

2121
COPY . /code/
2222

23-
# Dynamic configs. Can be changed with containers. (Placeholder values)
24-
ENV APP_TITLE=APP_TITLE_PLACEHOLDER
25-
ENV APP_ENVIRONMENT=APP_ENVIRONMENT_PLACEHOLDER
26-
ENV APP_GRAPHQL_DOMAIN=APP_GRAPHQL_DOMAIN_PLACEHOLDER
27-
ENV APP_UMAMI_SRC=APP_UMAMI_SRC_PLACEHOLDER
28-
ENV APP_UMAMI_ID=APP_UMAMI_ID_PLACEHOLDER
29-
ENV APP_SENTRY_DSN=APP_SENTRY_DSN_PLACEHOLDER
30-
31-
# Build variables (Requires backend pulled)
23+
# NOTE: Dynamic env variables
24+
# These env variables can be dynamically defined in web-app-serve container runtime.
25+
# These variables are not included in the build files but the values should still be valid.
26+
# See "schema" field in "./env.ts"
27+
ENV APP_TITLE=Timur
28+
ENV APP_ENVIRONMENT=production
29+
ENV APP_GRAPHQL_DOMAIN=https://api.example.com
30+
ENV APP_SENTRY_DSN=https://xyzl@sentry.example.com/123
31+
32+
# NOTE: These are set directly in `vite.config.ts`
33+
# We're using raw web-app-serve placeholder values here to treat them as dynamic values
34+
ENV APP_UMAMI_SRC=WEB_APP_SERVE_PLACEHOLDER__APP_UMAMI_SRC
35+
ENV APP_UMAMI_ID=WEB_APP_SERVE_PLACEHOLDER__APP_UMAMI_ID
36+
37+
# NOTE: Static env variables:
38+
# These env variables are used during build
3239
ENV APP_GRAPHQL_CODEGEN_ENDPOINT=./backend/schema.graphql
3340

34-
RUN pnpm generate:type && pnpm build
41+
# NOTE: WEB_APP_SERVE_ENABLED=true will skip defining the above dynamic env variables
42+
# See "overrideDefine" field in "./env.ts"
43+
RUN pnpm generate:type && WEB_APP_SERVE_ENABLED=true pnpm build
3544

36-
# ---------------------------------------------------------------------------
37-
FROM nginx:1 AS nginx-serve
45+
# ---------------------------------------------------------------------
46+
# Final image using web-app-serve
47+
FROM ghcr.io/toggle-corp/web-app-serve:v0.1.2 AS web-app-serve
3848

39-
LABEL maintainer="Togglecorp Dev"
49+
MAINTAINER navin
4050
LABEL org.opencontainers.image.source="https://github.com/toggle-corp/timur"
51+
LABEL org.opencontainers.image.authors="dev@togglecorp.com"
4152

42-
COPY ./nginx-serve/apply-config.sh /docker-entrypoint.d/
43-
COPY ./nginx-serve/nginx.conf.template /etc/nginx/templates/default.conf.template
44-
COPY --from=nginx-build /code/build /code/build
45-
46-
# NOTE: Used by apply-config.sh
53+
# Env for apply-config script
4754
ENV APPLY_CONFIG__SOURCE_DIRECTORY=/code/build/
48-
ENV APPLY_CONFIG__DESTINATION_DIRECTORY=/usr/share/nginx/html/
49-
ENV APPLY_CONFIG__OVERWRITE_DESTINATION=true
55+
56+
COPY --from=web-app-serve-build /code/build "$APPLY_CONFIG__SOURCE_DIRECTORY"

env.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1-
import { defineConfig, Schema } from '@julr/vite-plugin-validate-env';
1+
import {
2+
defineConfig,
3+
overrideDefineForWebAppServe,
4+
Schema,
5+
} from '@julr/vite-plugin-validate-env';
6+
7+
const webAppServeEnabled = process.env.WEB_APP_SERVE_ENABLED?.toLowerCase() === 'true';
8+
if (webAppServeEnabled) {
9+
// eslint-disable-next-line no-console
10+
console.warn('Building application for web-app-serve');
11+
}
12+
const overrideDefine = webAppServeEnabled
13+
? overrideDefineForWebAppServe
14+
: undefined;
215

316
export default defineConfig({
4-
APP_TITLE: Schema.string(),
5-
APP_ENVIRONMENT: (key, value) => {
6-
// NOTE: APP_ENVIRONMENT_PLACEHOLDER is meant to be used with image builds
7-
// The value will be later replaced with the actual value
8-
const regex = /^production|staging|testing|alpha-\d+|development|APP_ENVIRONMENT_PLACEHOLDER$/;
9-
const valid = !!value && (value.match(regex) !== null);
10-
if (!valid) {
11-
throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`);
12-
}
13-
if (value === 'APP_ENVIRONMENT_PLACEHOLDER') {
14-
console.warn(`Using ${value} for app environment. Make sure to not use this for builds without nginx-serve`)
15-
}
16-
return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development' | 'APP_ENVIRONMENT_PLACEHOLDER');
17+
overrideDefine,
18+
validator: 'builtin',
19+
schema: {
20+
APP_TITLE: Schema.string(),
21+
APP_ENVIRONMENT: (key: string, value: string) => {
22+
// NOTE: APP_ENVIRONMENT_PLACEHOLDER is meant to be used with image builds
23+
// The value will be later replaced with the actual value
24+
const regex = /^production|staging|testing|alpha-\d+|development|APP_ENVIRONMENT_PLACEHOLDER$/;
25+
const valid = !!value && (value.match(regex) !== null);
26+
if (!valid) {
27+
throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`);
28+
}
29+
if (value === 'APP_ENVIRONMENT_PLACEHOLDER') {
30+
// eslint-disable-next-line no-console
31+
console.warn(`Using ${value} for app environment. Make sure to not use this for builds without nginx-serve`);
32+
}
33+
return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development' | 'APP_ENVIRONMENT_PLACEHOLDER');
34+
},
35+
APP_GRAPHQL_CODEGEN_ENDPOINT: Schema.string(),
36+
APP_GRAPHQL_DOMAIN: Schema.string(),
37+
APP_UMAMI_SRC: Schema.string.optional(),
38+
APP_UMAMI_ID: Schema.string.optional(),
39+
APP_SENTRY_DSN: Schema.string.optional(),
1740
},
18-
APP_GRAPHQL_CODEGEN_ENDPOINT: Schema.string(),
19-
APP_GRAPHQL_DOMAIN: Schema.string(),
20-
APP_UMAMI_SRC: Schema.string.optional(),
21-
APP_UMAMI_ID: Schema.string.optional(),
22-
APP_SENTRY_DSN: Schema.string.optional(),
2341
});

knip.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
{
22
"$schema": "https://unpkg.com/knip@5/schema.json",
33
"ignoreDependencies": [
4-
"virtual:pwa-info",
5-
"virtual:pwa-register",
4+
"dotenv",
65
"sharp"
76
],
87
"entry": [
9-
"src/**/*.test.ts",
10-
"src/**/*.test.tsx",
118
"generated/**/*.ts",
129
"src/index.tsx!"
1310
],
1411
"project": [
1512
"src/**/*.d.ts",
16-
"src/**/*.test.ts",
17-
"src/**/*.test.tsx",
1813
"src/**/*.tsx!",
1914
"src/**/*.ts!"
2015
]

nginx-serve/apply-config.sh

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

nginx-serve/nginx.conf.template

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@graphql-codegen/cli": "^5.0.2",
4444
"@graphql-codegen/client-preset": "^4.3.3",
4545
"@graphql-typed-document-node/core": "^3.2.0",
46-
"@julr/vite-plugin-validate-env": "^1.0.1",
46+
"@julr/vite-plugin-validate-env": "git+https://github.com/toggle-corp/vite-plugin-validate-env#v2.2.0-tc.1",
4747
"@types/node": "^20.11.6",
4848
"@types/react": "^18.0.28",
4949
"@types/react-dom": "^18.0.11",
@@ -67,7 +67,7 @@
6767
"eslint-plugin-simple-import-sort": "^10.0.0",
6868
"graphql": "^16.9.0",
6969
"happy-dom": "^15.7.3",
70-
"knip": "^5.29.2",
70+
"knip": "^5.61.3",
7171
"patch-package": "^7.0.0",
7272
"postcss": "^8.3.0",
7373
"postcss-nested": "^6.0.1",

0 commit comments

Comments
 (0)