diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..61b1320 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_TARGO_BACKEND_URL=PREFIX_BACKEND_URL \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9ec98a1..fa43432 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,10 @@ FROM node:22 AS build WORKDIR /app COPY package*.json ./ -# Set environment variables -ARG BACKEND_URL -ENV VITE_TARGO_BACKEND_URL=$BACKEND_URL # Install dependencies RUN npm install -g @quasar/cli COPY . . -RUN npm install +RUN npm ci RUN npm run build # Step 2 - Move Applicatin to Nginx @@ -16,5 +13,12 @@ FROM nginx:alpine COPY --from=build /app/dist/spa /usr/share/nginx/html RUN mkdir /usr/share/nginx/html/src COPY --from=build /app/src /usr/share/nginx/html/src + +COPY env.sh /docker-entrypoint.d/env.sh +RUN dos2unix /docker-entrypoint.d/env.sh +RUN chmod +x /docker-entrypoint.d/env.sh + +ENTRYPOINT ["/docker-entrypoint.sh"] + EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/env.sh b/env.sh new file mode 100644 index 0000000..e7cd7be --- /dev/null +++ b/env.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env sh +# ================================================================================ +# File: env.sh +# Description: Replaces environment variables in asset files. +# Usage: Run this script in your terminal, ensuring APP_PREFIX and ASSET_DIRS are set. +# ================================================================================ + +# Set the exit flag to exit immediately if any command fails +set -e + +# Check if APP_PREFIX is set +: "${APP_PREFIX:?APP_PREFIX must be set (e.g. APP_PREFIX='APP_PREFIX_')}" + +# Check if ASSET_DIRS is set +: "${ASSET_DIR:?Must set ASSET_DIR to one path}" + +# Check if the directory exists +if [ ! -d "$ASSET_DIR" ]; then + # If not, display a warning message and skip to the next iteration + echo "Warning: directory '$ASSET_DIR' not found, skipping." + continue +fi + +# Display the current directory being scanned +echo "Scanning directory: $ASSET_DIR" + +# Iterate through each environment variable that starts with APP_PREFIX +env | grep "^${APP_PREFIX}" | while IFS='=' read -r key value; do + # Display the variable being replaced + echo " • Replacing ${key} → ${value}" + + # Use find and sed to replace the variable in all files within the directory + find "$ASSET_DIR" -type f \ + -exec sed -i "s|${key}|${value}|g" {} + +done