From 490fa2fa93950650ebce6f1107f0642bfd86342b Mon Sep 17 00:00:00 2001 From: Lobo Date: Sat, 28 Mar 2026 10:10:09 +0100 Subject: [PATCH] Add Dockerfile, nginx config and publish CI Add a multi-stage Dockerfile to build the React app (node:24-alpine, npm ci, npm run build) and serve the compiled /app/dist via nginx:alpine. Include nginx.conf that routes unknown paths to /index.html so React Router works in a SPA. Add a CI workflow (.forgejo/workflows/docker-publish.yml) to build and push the Docker image to Codeberg Container Registry on pushes to main (requires CODEBERG_TOKEN repository secret and tags the image as codeberg.org/${{ github.repository }}:latest). --- .forgejo/workflows/docker-publish.yml | 28 +++++++++++++++++++++++++++ Dockerfile | 14 ++++++++++++++ nginx.conf | 10 ++++++++++ 3 files changed, 52 insertions(+) create mode 100644 .forgejo/workflows/docker-publish.yml create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.forgejo/workflows/docker-publish.yml b/.forgejo/workflows/docker-publish.yml new file mode 100644 index 0000000..dce3621 --- /dev/null +++ b/.forgejo/workflows/docker-publish.yml @@ -0,0 +1,28 @@ +name: Build and Publish Docker Image + +on: + push: + branches: + - main + +jobs: + build-and-push: + runs-on: docker + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Codeberg Container Registry + uses: docker/login-action@v3 + with: + registry: codeberg.org + username: ${{ github.repository_owner }} + # Requires a generated Application Token from your Codeberg settings saved as a repository secret + password: ${{ secrets.CODEBERG_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: codeberg.org/${{ github.repository }}:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..61da87a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Compile the React application into static files +FROM node:24-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +# Serve the static files using a lightweight web server +FROM nginx:alpine +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..52a60e7 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,10 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + # Redirect all unknown paths to index.html to allow React Router to handle the routing + try_files $uri $uri/ /index.html; + } +} \ No newline at end of file