56 lines
1.7 KiB
Docker
56 lines
1.7 KiB
Docker
# Multi-stage build for GPX application
|
|
|
|
# Using a specific version of Node
|
|
FROM node:18-alpine as base
|
|
# Install build dependencies
|
|
RUN apk add --no-cache python3 make g++ git
|
|
|
|
# Build stage for gpx library
|
|
FROM base AS gpx-builder
|
|
WORKDIR /app
|
|
# Copy the gpx directory
|
|
COPY gpx/ ./gpx/
|
|
# Install dependencies and build
|
|
WORKDIR /app/gpx
|
|
RUN npm install --legacy-peer-deps
|
|
RUN npm run build
|
|
|
|
# Build stage for website
|
|
FROM base AS website-builder
|
|
WORKDIR /app
|
|
# Copy the website directory
|
|
COPY website/ ./website/
|
|
# Copy the built gpx library
|
|
COPY --from=gpx-builder /app/gpx/dist ./gpx/dist
|
|
# Install dependencies and build
|
|
WORKDIR /app/website
|
|
RUN npm install --legacy-peer-deps
|
|
# Use a dummy token for build time (will be replaced at runtime)
|
|
ENV PUBLIC_MAPBOX_TOKEN="pk.dummy_token_for_build"
|
|
RUN npm run build
|
|
|
|
# Production stage
|
|
FROM node:18-alpine
|
|
WORKDIR /app
|
|
|
|
# Copy the built application
|
|
COPY --from=website-builder /app/website/build ./build
|
|
COPY --from=website-builder /app/website/package.json ./
|
|
COPY --from=website-builder /app/website/node_modules ./node_modules
|
|
|
|
# Create a startup script to replace the Mapbox token at runtime
|
|
COPY --from=website-builder /app/website/build/index.html ./build/index.html.template
|
|
RUN echo '#!/bin/sh' > ./start.sh && \
|
|
echo 'sed "s/pk.dummy_token_for_build/$PUBLIC_MAPBOX_TOKEN/g" ./build/index.html.template > ./build/index.html' >> ./start.sh && \
|
|
echo 'exec node build' >> ./start.sh && \
|
|
chmod +x ./start.sh
|
|
|
|
# Expose the port SvelteKit runs on
|
|
EXPOSE 3000
|
|
|
|
# Set environment variable for production
|
|
ENV NODE_ENV=production
|
|
ENV PUBLIC_MAPBOX_TOKEN=""
|
|
|
|
# Command to run the application using our start script
|
|
CMD ["./start.sh"] |