CI/CD Pipeline on Forgejo Actions with Docker & Dokploy Deployment #11

Closed
opened 2026-10-14 19:53:26 +00:00 by yuris · 0 comments
Owner

What to build

Establish an automated CI/CD pipeline on Forgejo Actions targeting Dokploy. The pipeline validates code quality on Pull Requests and merges (vp check and pnpm build), builds a multi-stage standalone Docker image, publishes container tags to the Forgejo Container Registry (git.nokopia.com), triggers redeployment on Dokploy via webhook, and prunes stale commit tags to prevent registry bloat.

Technical specifications

  1. Target files:

    • next.config.ts: Enable output: "standalone" for minimal container footprint.
    • Dockerfile: Multi-stage node:22-alpine container configuration.
    • .dockerignore: Docker build context exclusions (.git, node_modules, .next, scratch, docs).
    • .forgejo/workflows/ci.yml: Reusable pull request and push quality verification workflow.
    • .forgejo/workflows/deploy.yml: Production container build, publish, Dokploy redeploy, and prune workflow.
    • .forgejo/scripts/prune-container-tags.mjs: Automated registry cleanup keeping 2 recent commit SHA tags.
  2. Container Image Architecture:

    • Base image: node:22-alpine with corepack enable pnpm.
    • Stage 1 (builder): Install dependencies via pnpm install --frozen-lockfile, compile Next.js standalone output via pnpm build, remove .next/cache.
    • Stage 2 (runner): Unprivileged system user nextjs:nodejs (UID 1001), port 3000, bind 0.0.0.0. Copy standalone server, static assets, and public directory.
  3. CI Workflow (ci.yml):

    • Triggers: pull_request (target main), push (branches: [main]), workflow_dispatch, workflow_call.
    • Concurrency: group: ci-${{ github.workflow }}-${{ github.ref }}, cancel-in-progress: true.
    • Environment: runs-on: ubuntu-latest, Node 22, pnpm, pnpm store cache via actions/cache@v4.
    • Gates: pnpm exec vp check (TypeScript + linter/formatter) and pnpm build.
  4. CD Workflow (deploy.yml):

    • Triggers: push to main, workflow_dispatch.
    • Path filters: Exclude documentation, markdown, and agent rig changes from triggering container builds.
    • Gate: Requires ci.yml completion.
    • Registry Target: git.nokopia.com/${{ github.repository }}:latest and :${{ github.sha }}.
    • Cache: Registry cache git.nokopia.com/${{ github.repository }}:buildcache (mode=max).
    • Dokploy Webhook: Send POST request with X-Gitea-Event: push and payload {"ref":"${{ github.ref }}"} to avoid branch mismatch errors. Gracefully skips if DOKPLOY_DEPLOY_URL secret is not configured.
    • Pruning: Execute prune-container-tags.mjs with KEEP=2 to ensure VPS disk capacity is safeguarded.

Secrets required

  • CONTAINER_REGISTRY_TOKEN: Package read/write token for git.nokopia.com.
  • DOKPLOY_DEPLOY_URL: (Optional initially) Webhook URL generated by Dokploy application.

Acceptance criteria

  • next.config.ts configured with output: "standalone".
  • Multi-stage Dockerfile builds cleanly without warnings and runs as unprivileged user.
  • PR checks run vp check and pnpm build on Forgejo Actions runner.
  • Push to main builds container image and pushes to git.nokopia.com/yuris/titik-gambut-next.
  • Webhook triggers Dokploy deployment without 301/400 errors when URL is provided.
  • Tag pruning script cleans up stale commit tags while preserving :latest and :buildcache.

Blocked by

None - High Priority (Priority 0 gatekeeper for ongoing vertical slices).

### What to build Establish an automated CI/CD pipeline on Forgejo Actions targeting Dokploy. The pipeline validates code quality on Pull Requests and merges (`vp check` and `pnpm build`), builds a multi-stage standalone Docker image, publishes container tags to the Forgejo Container Registry (`git.nokopia.com`), triggers redeployment on Dokploy via webhook, and prunes stale commit tags to prevent registry bloat. ### Technical specifications 1. **Target files**: - `next.config.ts`: Enable `output: "standalone"` for minimal container footprint. - `Dockerfile`: Multi-stage `node:22-alpine` container configuration. - `.dockerignore`: Docker build context exclusions (`.git`, `node_modules`, `.next`, scratch, docs). - `.forgejo/workflows/ci.yml`: Reusable pull request and push quality verification workflow. - `.forgejo/workflows/deploy.yml`: Production container build, publish, Dokploy redeploy, and prune workflow. - `.forgejo/scripts/prune-container-tags.mjs`: Automated registry cleanup keeping 2 recent commit SHA tags. 2. **Container Image Architecture**: - Base image: `node:22-alpine` with `corepack enable pnpm`. - Stage 1 (`builder`): Install dependencies via `pnpm install --frozen-lockfile`, compile Next.js standalone output via `pnpm build`, remove `.next/cache`. - Stage 2 (`runner`): Unprivileged system user `nextjs:nodejs` (UID 1001), port `3000`, bind `0.0.0.0`. Copy standalone server, static assets, and public directory. 3. **CI Workflow (`ci.yml`)**: - Triggers: `pull_request` (target `main`), `push` (branches: `[main]`), `workflow_dispatch`, `workflow_call`. - Concurrency: `group: ci-${{ github.workflow }}-${{ github.ref }}`, `cancel-in-progress: true`. - Environment: `runs-on: ubuntu-latest`, Node 22, pnpm, pnpm store cache via `actions/cache@v4`. - Gates: `pnpm exec vp check` (TypeScript + linter/formatter) and `pnpm build`. 4. **CD Workflow (`deploy.yml`)**: - Triggers: `push` to `main`, `workflow_dispatch`. - Path filters: Exclude documentation, markdown, and agent rig changes from triggering container builds. - Gate: Requires `ci.yml` completion. - Registry Target: `git.nokopia.com/${{ github.repository }}:latest` and `:${{ github.sha }}`. - Cache: Registry cache `git.nokopia.com/${{ github.repository }}:buildcache` (`mode=max`). - Dokploy Webhook: Send POST request with `X-Gitea-Event: push` and payload `{"ref":"${{ github.ref }}"}` to avoid branch mismatch errors. Gracefully skips if `DOKPLOY_DEPLOY_URL` secret is not configured. - Pruning: Execute `prune-container-tags.mjs` with `KEEP=2` to ensure VPS disk capacity is safeguarded. ### Secrets required - `CONTAINER_REGISTRY_TOKEN`: Package read/write token for `git.nokopia.com`. - `DOKPLOY_DEPLOY_URL`: (Optional initially) Webhook URL generated by Dokploy application. ### Acceptance criteria - [x] `next.config.ts` configured with `output: "standalone"`. - [x] Multi-stage `Dockerfile` builds cleanly without warnings and runs as unprivileged user. - [x] PR checks run `vp check` and `pnpm build` on Forgejo Actions runner. - [x] Push to `main` builds container image and pushes to `git.nokopia.com/yuris/titik-gambut-next`. - [x] Webhook triggers Dokploy deployment without 301/400 errors when URL is provided. - [x] Tag pruning script cleans up stale commit tags while preserving `:latest` and `:buildcache`. ### Blocked by None - High Priority (Priority 0 gatekeeper for ongoing vertical slices).
yuris closed this issue 2026-10-14 20:06:15 +00:00
yuris changed title from Issue 10: CI/CD Pipeline on Forgejo Actions with Docker & Dokploy Deployment to CI/CD Pipeline on Forgejo Actions with Docker & Dokploy Deployment 2026-10-14 22:31:30 +00:00
Sign in to join this conversation.
No labels
backend
frontend
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
yuris/titik-gambut-next#11
No description provided.