build(frontend): update docker image to use production env
This commit is contained in:
@@ -38,7 +38,7 @@ services:
|
||||
depends_on:
|
||||
- backend
|
||||
ports:
|
||||
- "5173:5173"
|
||||
- "5173:80"
|
||||
restart: unless-stopped
|
||||
|
||||
rtmp:
|
||||
|
||||
@@ -37,7 +37,7 @@ services:
|
||||
depends_on:
|
||||
- backend
|
||||
ports:
|
||||
- "5173:5173"
|
||||
- "5173:80"
|
||||
restart: unless-stopped
|
||||
|
||||
rtmp:
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
FROM node:20-alpine
|
||||
|
||||
# --- Build stage ---
|
||||
FROM node:20-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN --mount=type=cache,target=/root/.npm npm ci
|
||||
|
||||
COPY . .
|
||||
EXPOSE 5173
|
||||
CMD ["npm", "run", "dev"]
|
||||
RUN npm run build
|
||||
|
||||
# --- Production stage ---
|
||||
FROM nginx:1.27-alpine AS prod
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
|
||||
# Inject envs at runtime
|
||||
COPY env.sh /docker-entrypoint.d/40-env.sh
|
||||
RUN chmod +x /docker-entrypoint.d/40-env.sh
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
10
frontend/env.sh
Normal file
10
frontend/env.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
cat <<EOF > /usr/share/nginx/html/env-config.js
|
||||
window._env_ = {
|
||||
VITE_API_URL: "${VITE_API_URL:-}",
|
||||
VITE_FRONTEND_URL: "${VITE_FRONTEND_URL:-}",
|
||||
VITE_GOOGLE_CLIENT_ID: "${VITE_GOOGLE_CLIENT_ID:-}"
|
||||
};
|
||||
EOF
|
||||
@@ -9,6 +9,7 @@
|
||||
<link href="https://fonts.googleapis.com/css2?family=Newsreader:wght@100;200;300;400;500;600;700&family=IBM+Plex+Sans:wght@100;200;300;400;500;600;700&family=IBM+Plex+Mono:wght@100;200;300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<script src="/env-config.js"></script>
|
||||
<title>The VoD System</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
5
frontend/src/config.ts
Normal file
5
frontend/src/config.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const config = {
|
||||
apiUrl: window._env_?.VITE_API_URL ?? import.meta.env.VITE_API_URL ?? '',
|
||||
frontendUrl: window._env_?.VITE_FRONTEND_URL ?? import.meta.env.VITE_FRONTEND_URL ?? '',
|
||||
googleClientId: window._env_?.VITE_GOOGLE_CLIENT_ID ?? import.meta.env.VITE_GOOGLE_CLIENT_ID ?? '',
|
||||
};
|
||||
10
frontend/src/vite-env.d.ts
vendored
10
frontend/src/vite-env.d.ts
vendored
@@ -1 +1,9 @@
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface Window {
|
||||
_env_?: {
|
||||
VITE_API_URL?: string;
|
||||
VITE_FRONTEND_URL?: string;
|
||||
VITE_GOOGLE_CLIENT_ID?: string;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user