From 1cf768183db6e284cfabb837962f406ba218f3fe Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Sun, 9 Aug 2026 21:55:04 +0200 Subject: [PATCH] Add Docker deployment, matching Djupet's setup Multi-stage build (node build -> nginx:alpine serve), docker-compose with a configurable HOST_PORT (default 47174, an unusual port left free for nginx proxy manager to front later), and a Gitea Actions workflow that builds/pushes the image on push to main. Verified: image builds, container serves the app and all art assets on port 47174. --- .dockerignore | 9 ++++++ .env.example | 3 ++ .gitea/workflows/build.yml | 57 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 11 ++++++++ docker-compose.yml | 6 ++++ nginx.conf | 10 +++++++ 6 files changed, 96 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 .gitea/workflows/build.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9fb9c91 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +node_modules +**/node_modules +dist +**/dist +.git +.env +.env.example +*.log +data diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c008f66 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +# Copy to .env to override docker-compose.yml defaults +HOST_PORT=47174 +IMAGE=repo.explewd.com/explewd/vildhjarta:latest diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..3906697 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,57 @@ +name: Docker + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Derive image name and tags + id: meta + shell: bash + run: | + set -euo pipefail + + SERVER_URL="${GITHUB_SERVER_URL:-${GITEA_SERVER_URL:-}}" + REPO="${GITHUB_REPOSITORY:-${GITEA_REPOSITORY:-}}" + SHA="${GITHUB_SHA:-${GITEA_SHA:-}}" + + if [[ -z "${SERVER_URL}" || -z "${REPO}" || -z "${SHA}" ]]; then + echo "Missing SERVER_URL/REPO/SHA env vars." >&2 + echo "SERVER_URL='${SERVER_URL}' REPO='${REPO}' SHA='${SHA}'" >&2 + exit 1 + fi + + HOST=$(echo "${SERVER_URL}" | sed 's|https://||;s|http://||') + IMAGE=$(echo "${HOST}/${REPO}" | tr '[:upper:]' '[:lower:]') + SHORT_SHA=$(echo "${SHA}" | cut -c1-7) + + echo "host=${HOST}" >> "$GITHUB_OUTPUT" + echo "image=${IMAGE}" >> "$GITHUB_OUTPUT" + echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT" + + - name: Log in to Gitea container registry + uses: docker/login-action@v3 + with: + registry: ${{ steps.meta.outputs.host }} + username: ${{ github.actor }} + password: ${{ secrets.TKNTKN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + push: true + tags: | + ${{ steps.meta.outputs.image }}:latest + ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.short_sha }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0331674 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM node:22-alpine AS build +WORKDIR /app +COPY package.json ./ +RUN npm install +COPY . . +RUN npm run build + +FROM nginx:alpine +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f972808 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +services: + app: + image: ${IMAGE:-vildhjarta:local} + restart: unless-stopped + ports: + - "${HOST_PORT:-47174}:80" diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..a676565 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,10 @@ +server { + listen 80; + root /usr/share/nginx/html; + index index.html; + location / { + try_files $uri $uri/ /index.html; + } + gzip on; + gzip_types text/css application/javascript application/json image/svg+xml; +}