This commit is contained in:
parent
4a3b80a3b1
commit
cccc264a78
71
Dockerfile
71
Dockerfile
@ -1,56 +1,29 @@
|
||||
# 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
|
||||
# Simple Dockerfile for the GPX viewer application
|
||||
FROM node:18-alpine
|
||||
|
||||
# Set working directory
|
||||
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
|
||||
# Copy all source files
|
||||
COPY . .
|
||||
|
||||
# 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
|
||||
# Build the GPX library first
|
||||
WORKDIR /app/gpx
|
||||
RUN npm install
|
||||
RUN npm run build
|
||||
|
||||
# Expose the port SvelteKit runs on
|
||||
EXPOSE 3000
|
||||
# Then build and run the website
|
||||
WORKDIR /app/website
|
||||
RUN npm install
|
||||
|
||||
# Set environment variable for production
|
||||
ENV NODE_ENV=production
|
||||
ENV PUBLIC_MAPBOX_TOKEN=""
|
||||
# Expose the port for the dev server
|
||||
EXPOSE 5173
|
||||
|
||||
# Command to run the application using our start script
|
||||
CMD ["./start.sh"]
|
||||
# Create a simple startup script that injects the token from env var
|
||||
RUN echo '#!/bin/sh' > /app/start.sh && \
|
||||
echo 'echo "PUBLIC_MAPBOX_TOKEN=$PUBLIC_MAPBOX_TOKEN" > /app/website/.env' >> /app/start.sh && \
|
||||
echo 'cd /app/website && npm run dev -- --host 0.0.0.0' >> /app/start.sh && \
|
||||
chmod +x /app/start.sh
|
||||
|
||||
# Command to start the application
|
||||
CMD ["/app/start.sh"]
|
||||
Loading…
x
Reference in New Issue
Block a user