Public Access
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).
This commit is contained in:
1 parent
d9c3f40c4a
commit
490fa2fa93
3 files changed
+52
No files matched your search
@@ -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
|
||||
+14
@@ -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;"]
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user