Fix a docker rebuild issue #88

Merged
hodlbod merged 6 commits from bugfix/docker-rebuild into dev 2026-03-03 19:52:23 +00:00
5 changed files with 477 additions and 379 deletions
+8
View File
@@ -2,3 +2,11 @@ node_modules
android
ios
build
# Git
.git
.gitignore
# Env files (keep .env for build; exclude local overrides)
.env.local
.env.*.local
+17 -10
View File
@@ -1,24 +1,31 @@
FROM node:20-slim
# Stage 1: Build
Review

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.

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.
# 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-bookworm 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 . .
# Build the application
ARG VITE_BUILD_HASH
ENV VITE_BUILD_HASH=${VITE_BUILD_HASH}
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"]
+1 -1
View File
@@ -11,7 +11,7 @@ You can also optionally create an `.env` file and populate it with the following
- `VITE_DEFAULT_PUBKEYS` - A comma-separated list of hex pubkeys for bootstrapping web of trust
- `VITE_PLATFORM_URL` - The url where the app will be hosted
- `VITE_PLATFORM_NAME` - The name of the app
- `VITE_PLATFORM_LOGO` - A logo url for the app
- `VITE_PLATFORM_LOGO` - A logo url for the app. Can be a local path or https link. Must be a PNG file.
- `VITE_PLATFORM_RELAYS` - A list of comma-separated relay urls that will make flotilla operate in "platform mode". Disables all space browse/add/select functionality and makes the first platform relay the home page.
- `VITE_PLATFORM_ACCENT` - A hex color for the app's accent color
- `VITE_PLATFORM_DESCRIPTION` - A description of the app
+7 -3
View File
@@ -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
Review

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.

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
@@ -14,12 +17,13 @@ if [[ -z $VITE_BUILD_HASH ]]; then
export VITE_BUILD_HASH=$(git rev-parse --short HEAD)
fi
if [[ $VITE_PLATFORM_LOGO =~ ^https://* ]]; then
curl $VITE_PLATFORM_LOGO > static/logo.png
if [[ $VITE_PLATFORM_LOGO =~ ^https:// ]]; then
curl -fSL "$VITE_PLATFORM_LOGO" -o static/logo.png
Review

The old curl command was failing silently for me so this one will fail the build if the logo URL exists but the logo cannot be fetched.

The old curl command was failing silently for me so this one will fail the build if the logo URL exists but the logo cannot be fetched.
export VITE_PLATFORM_LOGO=static/logo.png
fi
npx pwa-assets-generator
# Ensure generator uses local path (dotenv may have loaded URL from .env)
VITE_PLATFORM_LOGO="${VITE_PLATFORM_LOGO}" npx pwa-assets-generator
npx vite build
# Replace index.html variables with stuff from our env
+444 -365
View File
File diff suppressed because it is too large Load Diff