dockerfile and setenv updates

master
Tudor Stanciu 2023-05-06 14:29:59 +03:00
parent a38603be2c
commit 72a349c779
2 changed files with 11 additions and 13 deletions

View File

@ -1,9 +1,8 @@
# build environment
# BUILD ENVIRONMENT
FROM node:14-slim as builder
WORKDIR /app
# global args
ARG APP_SUBFOLDER=
ARG APP_SUBFOLDER=""
COPY .npmrc .npmrc
COPY package*.json ./
@ -12,18 +11,15 @@ RUN rm -f .npmrc
COPY . ./
# set the PUBLIC_URL environment variable
ENV PUBLIC_URL /${APP_SUBFOLDER}/
# build the react app
# RUN npm run build
RUN if [ -z "$APP_SUBFOLDER" ]; then npm run build; else PUBLIC_URL=$PUBLIC_URL npm run build; fi
RUN if [ -z "$APP_SUBFOLDER" ]; then npm run build; else PUBLIC_URL=/${APP_SUBFOLDER}/ npm run build; fi
# production environment
# PRODUCTION ENVIRONMENT
FROM node:14-slim
RUN printf '\n\n- Copy application files\n'
ARG APP_SUBFOLDER=""
RUN printf '\n\n- Copy application files\n'
COPY --from=builder /app/build ./application/${APP_SUBFOLDER}
COPY --from=builder /app/build/index.html ./application/
COPY --from=builder /app/setenv.js ./application/setenv.js
@ -33,6 +29,7 @@ RUN npm install -g serve
# environment variables
ENV AUTHOR="Tudor Stanciu"
ENV PUBLIC_URL=/${APP_SUBFOLDER}/
ARG APP_VERSION=0.0.0
ENV APP_VERSION=${APP_VERSION}
@ -44,4 +41,4 @@ WORKDIR /
EXPOSE 80
CMD ["sh", "-c", "node setenv.js && serve -s application -p 80"]
CMD ["sh", "-c", "node application/setenv.js && serve -s application -p 80"]

View File

@ -3,7 +3,8 @@ const fs = require("fs");
const path = require("path");
const prefix = "REACT_APP_";
const scriptPath = path.join("./application", process.env.PUBLIC_URL, "env.js");
const publicUrl = process.env.PUBLIC_URL || "";
const scriptPath = path.join("./application", publicUrl, "env.js");
function generateScriptContent() {
const prefixRegex = new RegExp(`^${prefix}`);