feat: build and publish docker image action workflow #1
56
Dockerfile
56
Dockerfile
@ -1,36 +1,56 @@
|
|||||||
|
# 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
|
# Build stage for gpx library
|
||||||
FROM node:20-alpine AS gpx-builder
|
FROM base AS gpx-builder
|
||||||
|
WORKDIR /app
|
||||||
|
# Copy the gpx directory
|
||||||
|
COPY gpx/ ./gpx/
|
||||||
|
# Install dependencies and build
|
||||||
WORKDIR /app/gpx
|
WORKDIR /app/gpx
|
||||||
COPY gpx/package*.json ./
|
RUN npm install --legacy-peer-deps
|
||||||
RUN npm install
|
|
||||||
COPY gpx/ ./
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Build stage for website
|
# Build stage for website
|
||||||
FROM node:20-alpine AS website-builder
|
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
|
WORKDIR /app/website
|
||||||
COPY website/package*.json ./
|
RUN npm install --legacy-peer-deps
|
||||||
RUN npm install
|
# Use a dummy token for build time (will be replaced at runtime)
|
||||||
COPY website/ ./
|
ENV PUBLIC_MAPBOX_TOKEN="pk.dummy_token_for_build"
|
||||||
COPY --from=gpx-builder /app/gpx/dist /app/gpx/dist
|
|
||||||
# RUN npm link /app/gpx
|
|
||||||
|
|
||||||
ENV PUBLIC_MAPBOX_TOKEN="pk"
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM node:20-alpine
|
# Production stage
|
||||||
|
FROM node:18-alpine
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=website-builder /app/website/package*.json ./
|
|
||||||
COPY --from=website-builder /app/website/build ./build
|
|
||||||
COPY --from=website-builder /app/website/node_modules ./node_modules
|
|
||||||
COPY --from=website-builder /app/website/build/index.html ./build/index.html.template
|
|
||||||
|
|
||||||
RUN echo '#!/bin/sh\ncat ./build/index.html.template | sed "s/pk.dummy_token_for_build/$PUBLIC_MAPBOX_TOKEN/g" > ./build/index.html\nexec node build' > ./start.sh && \
|
# 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
|
chmod +x ./start.sh
|
||||||
|
|
||||||
|
# Expose the port SvelteKit runs on
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Set environment variable for production
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV PUBLIC_MAPBOX_TOKEN=""
|
ENV PUBLIC_MAPBOX_TOKEN=""
|
||||||
|
|
||||||
|
# Command to run the application using our start script
|
||||||
CMD ["./start.sh"]
|
CMD ["./start.sh"]
|
||||||
Loading…
x
Reference in New Issue
Block a user