From d940aa2169d13c396791535f40ddb5b965b16e8e Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Thu, 17 Apr 2025 21:22:50 +0200 Subject: [PATCH 1/4] feat: Added actions to build and upload docker image --- .gitea/workflows/docker-build.yml | 28 ++++++++++++++++++++++++ Dockerfile | 36 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .gitea/workflows/docker-build.yml create mode 100644 Dockerfile diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml new file mode 100644 index 0000000..1923849 --- /dev/null +++ b/.gitea/workflows/docker-build.yml @@ -0,0 +1,28 @@ +name: Docker Build + +on: push + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Container Registry + run: | + docker login git.ambeles.nl \ + -u ${{ secrets.REGISTRY_USERNAME }} \ + -p ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build Docker Image + run: | + docker build \ + -t git.ambeles.nl/bedroomghost/gpx-viewer:${{ github.sha }} . + + - name: Push Docker Image + run: | + docker tag git.ambeles.nl/bedroomghost/gpx-viewer:${{ github.sha }} git.ambeles.nl/bedroomghost/gpx-viewer:latest + docker push git.ambeles.nl/bedroomghost/gpx-viewer:${{ github.sha }} + docker push git.ambeles.nl/bedroomghost/gpx-viewer:latest + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dc973ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Build stage for gpx library +FROM node:20-alpine AS gpx-builder +WORKDIR /app/gpx +COPY gpx/package*.json ./ +RUN npm install +COPY gpx/ ./ +RUN npm run build + +# Build stage for website +FROM node:20-alpine AS website-builder +WORKDIR /app/website +COPY website/package*.json ./ +RUN npm install +COPY website/ ./ +COPY --from=gpx-builder /app/gpx/dist /app/gpx/dist +# RUN npm link /app/gpx + +ENV PUBLIC_MAPBOX_TOKEN="pk" +RUN npm run build + +FROM node:20-alpine +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 && \ + chmod +x ./start.sh + +EXPOSE 3000 + +ENV NODE_ENV=production +ENV PUBLIC_MAPBOX_TOKEN="" + +CMD ["./start.sh"] -- 2.47.2 From 4a3b80a3b1c4fba890b409fbfe43ba4f937121ec Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Thu, 17 Apr 2025 21:25:42 +0200 Subject: [PATCH 2/4] Docker file test --- Dockerfile | 58 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index dc973ea..ddf85e9 100644 --- a/Dockerfile +++ b/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 -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 -COPY gpx/package*.json ./ -RUN npm install -COPY gpx/ ./ +RUN npm install --legacy-peer-deps RUN npm run build # 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 -COPY website/package*.json ./ -RUN npm install -COPY website/ ./ -COPY --from=gpx-builder /app/gpx/dist /app/gpx/dist -# RUN npm link /app/gpx - -ENV PUBLIC_MAPBOX_TOKEN="pk" +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 -FROM node:20-alpine +# Production stage +FROM node:18-alpine 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 +# Expose the port SvelteKit runs on EXPOSE 3000 +# Set environment variable for production ENV NODE_ENV=production ENV PUBLIC_MAPBOX_TOKEN="" -CMD ["./start.sh"] +# Command to run the application using our start script +CMD ["./start.sh"] \ No newline at end of file -- 2.47.2 From cccc264a78758808da3323dfd0c6b207104e0f91 Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Thu, 17 Apr 2025 21:33:36 +0200 Subject: [PATCH 3/4] Dockerfile test --- Dockerfile | 71 +++++++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/Dockerfile b/Dockerfile index ddf85e9..a6e5f43 100644 --- a/Dockerfile +++ b/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"] \ No newline at end of file +# 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"] \ No newline at end of file -- 2.47.2 From 51eb8cb4a2004aef884eab131ce9a1bc9171903e Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Fri, 18 Apr 2025 10:27:03 +0200 Subject: [PATCH 4/4] Dockerfile test --- .gitea/workflows/docker-build.yml | 9 ++++----- Dockerfile | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index 1923849..5c11f25 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -17,12 +17,11 @@ jobs: - name: Build Docker Image run: | - docker build \ - -t git.ambeles.nl/bedroomghost/gpx-viewer:${{ github.sha }} . + docker build -t git.ambeles.nl/bedroomghost/gpx-studio:${{ github.sha }} . - name: Push Docker Image run: | - docker tag git.ambeles.nl/bedroomghost/gpx-viewer:${{ github.sha }} git.ambeles.nl/bedroomghost/gpx-viewer:latest - docker push git.ambeles.nl/bedroomghost/gpx-viewer:${{ github.sha }} - docker push git.ambeles.nl/bedroomghost/gpx-viewer:latest + docker tag git.ambeles.nl/bedroomghost/gpx-studio:${{ github.sha }} git.ambeles.nl/bedroomghost/gpx-studio:latest + docker push git.ambeles.nl/bedroomghost/gpx-studio:${{ github.sha }} + docker push git.ambeles.nl/bedroomghost/gpx-studio:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a6e5f43..4c98d4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,7 @@ EXPOSE 5173 # 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 'find /app/website -type f -name "*.js" -o -name "*.ts" -o -name "*.svelte" | xargs sed -i "s|https://brouter.gpx.studio|https://brouter.ambeles.nl|g"' >> /app/start.sh && \ echo 'cd /app/website && npm run dev -- --host 0.0.0.0' >> /app/start.sh && \ chmod +x /app/start.sh -- 2.47.2