-
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.
feat: support for setting env variable when running container
- Loading branch information
1 parent
eb4f3cc
commit 9bfc503
Showing
4 changed files
with
50 additions
and
27 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 |
---|---|---|
@@ -1,32 +1,22 @@ | ||
FROM node:21-alpine AS base | ||
|
||
# Install dependencies only when needed | ||
FROM base AS deps | ||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
# RUN apk add --no-cache libc6-compat g++ cmake tar make | ||
FROM nginx:1.19.0 | ||
ARG PORT=8080 | ||
ARG MANAGER_URL | ||
EXPOSE $PORT | ||
EXPOSE $MANAGER_URL | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y curl | ||
RUN curl -fsSL https://deb.nodesource.com/setup_21.x | bash - | ||
RUN apt-get install -y nodejs | ||
RUN npm install -g yarn | ||
RUN mkdir /app | ||
WORKDIR /app | ||
|
||
# Install dependencies based on the preferred package manager | ||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ | ||
RUN yarn --immutable | ||
|
||
# Rebuild the source code only when needed | ||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
|
||
# Set backed url to empty string to use window.location.origin fallback | ||
RUN VITE_BACKEND_URL="" yarn build | ||
|
||
# Production image, copy all the files and run next | ||
FROM nginx:1.19.0 AS runner | ||
WORKDIR /usr/share/nginx/html/app | ||
RUN rm -rf ./* | ||
|
||
ENV NODE_ENV production | ||
RUN yarn --immutable | ||
|
||
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf | ||
COPY --from=builder /app/dist . | ||
RUN chmod +x /app/scripts/entrypoint.sh | ||
|
||
ENTRYPOINT [ "nginx", "-g", "daemon off;" ] | ||
ENV NODE_ENV production | ||
ENTRYPOINT [ "/app/scripts/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
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,7 @@ | ||
#!/bin/bash | ||
|
||
sed -i "s/listen\s*8080;/listen $PORT;/" /etc/nginx/conf.d/default.conf | ||
|
||
VITE_BACKEND_URL=$MANAGER_URL yarn build && \ | ||
cp -r /app/dist/* /usr/share/nginx/html/ && \ | ||
nginx -g 'daemon off;' |