Fix a docker rebuild issue #88
+1
-2
@@ -7,7 +7,6 @@ build
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Env files (use build args instead; .env.template is copied for defaults)
|
||||
.env
|
||||
# Env files (keep .env for build; exclude local overrides)
|
||||
.env.local
|
||||
.env.*.local
|
||||
+13
-12
@@ -1,30 +1,31 @@
|
||||
# Pass the build hash as an argument:
|
||||
# docker build --build-arg VITE_BUILD_HASH=$(git rev-parse --short HEAD) -t flotilla .
|
||||
# Stage 1: Build
|
||||
|
|
||||
# Uses .env from build context for config (logo, branding, etc.)
|
||||
# Optional: docker build --build-arg VITE_BUILD_HASH=$(git rev-parse --short HEAD) -t flotilla .
|
||||
|
||||
FROM node:20-slim
|
||||
FROM node:20-slim AS builder
|
||||
|
||||
# Install pnpm
|
||||
RUN npm install -g pnpm@latest
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# Install dependencies
|
||||
RUN pnpm i
|
||||
|
||||
# Copy the rest of the application
|
||||
# Copy everything (including .env when present) - build.sh will source it
|
||||
COPY . .
|
||||
|
||||
ARG VITE_BUILD_HASH
|
||||
ENV VITE_BUILD_HASH=${VITE_BUILD_HASH}
|
||||
|
||||
# Build the application
|
||||
ENV NODE_OPTIONS=--max_old_space_size=16384
|
||||
RUN pnpm run build
|
||||
|
||||
# Default to serving the build directory
|
||||
CMD ["npx", "serve", "build"]
|
||||
# Stage 2: Runtime
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only the built output - no source, no .env, no dev deps
|
||||
COPY --from=builder /app/build ./build
|
||||
|
||||
CMD ["npx", "serve", "build"]
|
||||
|
||||
@@ -5,6 +5,9 @@ temp_env=$(declare -p -x)
|
||||
if [ -f .env.template ]; then
|
||||
source .env.template
|
||||
fi
|
||||
if [ -f .env ]; then
|
||||
source .env
|
||||
fi
|
||||
|
mplorentz
commented
This fixes an issue I had with setting the logo. You could configure the other vars in This fixes an issue I had with setting the logo. You could configure the other vars in `.env` because npx reads that automatically but the logo was being read here and wasn't respecting .env.
|
||||
|
||||
# Avoid overwriting env vars provided directly
|
||||
# https://stackoverflow.com/a/69127685/1467342
|
||||
|
||||
Reference in New Issue
Block a user
I changed this to a two-stage docker build mostly because include .env in an image seems dangerous even if none of the env values are secrets at this time.