Skip to content

Commit a981187

Browse files
authored
feat: added dynamic environment configuration (#565)
- feat: added dynamic environment configuration - WIP
1 parent a782bfe commit a981187

37 files changed

+446
-278
lines changed

.vscode/launch.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Open Mailhog",
9+
"request": "launch",
10+
"type": "chrome",
11+
"url": "http://localhost:8025"
12+
},
713
{
814
"name": "Start Server",
915
"request": "launch",
@@ -30,7 +36,8 @@
3036
"configurations": [
3137
"Start Resources",
3238
"Start Prisma Studio",
33-
"Start Server"
39+
"Start Server",
40+
"Open Mailhog"
3441
]
3542
}
3643
]

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ ENTRYPOINT ["/usr/bin/tini", "--"]
9696
# Change runtime working directory
9797
WORKDIR /home/node/app/
9898

99+
# Setup custom runtime
100+
COPY --chown=node:node docker/env.sh ./
101+
RUN chmod +x env.sh
102+
99103
# copy build output required for yarn install for better build efficiency
100-
COPY --from=build_production /home/node/app/package.json ./
101-
COPY --from=build_production /home/node/app/prisma ./prisma
104+
COPY --from=build_production --chown=node:node /home/node/app/package.json ./
105+
COPY --from=build_production --chown=node:node /home/node/app/prisma ./prisma
102106

103107
# install production dependencies
104108
RUN yarn install \
@@ -125,4 +129,4 @@ HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
125129
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
126130

127131
# Run application
128-
CMD ["/bin/bash", "-c", "./node_modules/.bin/prisma migrate deploy && ././node_modules/.bin/next start"]
132+
CMD ["/bin/bash", "-c", "./env.sh && ./node_modules/.bin/prisma migrate deploy && ././node_modules/.bin/next start"]

config/interfaces/Config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { DatabaseConfig } from "./DatabaseConfig";
2+
import { EmailContentConfig } from "./EmailContentConfig";
3+
import { FreeSubConfig } from "./FreeSubConfig";
4+
import { HealthConfig } from "./HealthConfig";
5+
import { NextAuthConfig } from "./NextAuthConfig";
6+
import { RedisConfig } from "./RedisConfig";
7+
import { SentryConfig } from "./SentryConfig";
8+
import { SignupConfig } from "./SignupConfig";
9+
import { SmtpConfig } from "./SmtpConfig";
10+
import { StripeConfig } from "./StripeConfig";
11+
import { UsageReportConfig } from "./UsageReportConfig";
12+
13+
export interface Config {
14+
client: {
15+
sentryConfig: SentryConfig;
16+
};
17+
server: {
18+
database: DatabaseConfig;
19+
emailContent: EmailContentConfig;
20+
freeSub: FreeSubConfig;
21+
health: HealthConfig;
22+
nextAuth: NextAuthConfig;
23+
redisConfig: RedisConfig;
24+
sentryConfig: SentryConfig;
25+
signup: SignupConfig;
26+
smtp: SmtpConfig;
27+
stripeConfig: StripeConfig;
28+
usageReport: UsageReportConfig;
29+
};
30+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface DatabaseConfig {
2+
url: string;
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface EmailContentConfig {
2+
senderName: string;
3+
senderAddress: string;
4+
}

config/interfaces/FreeSubConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface FreeSubConfig {
2+
requestLimit: number;
3+
}

config/interfaces/HealthConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface HealthConfig {
2+
apiKey: string;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface NextAuthConfig {
2+
url: string;
3+
}

config/interfaces/RedisConfig.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export interface RedisConfig {
2+
isEnabled: boolean;
3+
4+
name?: string; // name of the Redis service
5+
host?: string;
6+
password?: string;
7+
port?: number;
8+
db: number | undefined;
9+
10+
cacheMaxAge: number;
11+
12+
isSentinelEnabled: boolean;
13+
sentinels?: { host: string; port: number }[];
14+
sentinelPassword?: string;
15+
}

config/interfaces/SentryConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface SentryConfig {
2+
debug?: boolean;
3+
dsn?: string;
4+
env?: string;
5+
release?: string;
6+
replaysOnErrorSampleRate?: number;
7+
replaysSessionSampleRate?: number;
8+
sampleRate?: number;
9+
tracesSampleRate: number;
10+
}

0 commit comments

Comments
 (0)