Deploy Dokploy applications from GitHub and Gitea Actions

A dependency-free node20 action that triggers application.deploy or
compose.deploy, then follows the deployment to a terminal status so a
failed build fails the CI run. Snapshots the deployment list before
triggering, so a concurrent deployment is never mistaken for this one.

Optionally points the application at a freshly built image first, which
is what lets a workflow lint, test, push and deploy the same artifact.
This commit is contained in:
2026-08-09 03:37:35 +03:00
commit c23b44983b
20 changed files with 2778 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
# The same pipeline on Gitea Actions, pushing to Gitea's built-in registry.
#
# The only differences from the GitHub version are the registry host and the
# token: Gitea sets the same GITHUB_* variables, and the action reads them the
# same way. Requires a runner whose label provides Docker.
name: deploy
on:
push:
branches: [main]
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: false
env:
# Your Gitea instance, which is also its container registry.
REGISTRY: gitea.example.com
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci
- run: npm run lint
- run: npm test
build:
needs: check
runs-on: ubuntu-latest
outputs:
image: ${{ steps.meta.outputs.image }}
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
# Automatically provided by Gitea to every workflow run.
password: ${{ secrets.GITEA_TOKEN }}
- id: meta
run: |
image="$REGISTRY/$(echo "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]'):${GITHUB_SHA::7}"
echo "image=$image" >> "$GITHUB_OUTPUT"
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.image }}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: https://github.com/maxvojtkov/dokploy-deploy-action@v1
with:
host: ${{ secrets.DOKPLOY_HOST }}
api-key: ${{ secrets.DOKPLOY_API_KEY }}
project: shop
service: api
docker-image: ${{ needs.build.outputs.image }}
registry-url: ${{ env.REGISTRY }}
registry-username: ${{ secrets.REGISTRY_USERNAME }}
# A Gitea access token with read:package, not the ephemeral
# GITEA_TOKEN: Dokploy needs credentials that outlive this run.
registry-password: ${{ secrets.REGISTRY_TOKEN }}
timeout: 900

View File

@@ -0,0 +1,82 @@
# Lint and test, build and push an image, then deploy that exact tag.
#
# This is the shape the action exists for: Dokploy's own Git webhook fires on
# every push, before anything has been checked. Here the deploy is one more
# job, gated behind the ones that can fail cheaply.
name: deploy
on:
push:
branches: [main]
# One deployment at a time. Do not cancel a run mid-deploy -- the build would
# keep going on the Dokploy side with nobody watching it.
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: false
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test
build:
needs: check
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image: ${{ steps.meta.outputs.image }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# A digest or a commit-pinned tag, never `latest`: the deploy has to be
# able to name the exact artifact the tests passed against.
- id: meta
run: echo "image=ghcr.io/${GITHUB_REPOSITORY,,}:${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.image }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build
runs-on: ubuntu-latest
environment: production
steps:
- uses: maxvojtkov/dokploy-deploy-action@v1
with:
host: ${{ secrets.DOKPLOY_HOST }}
api-key: ${{ secrets.DOKPLOY_API_KEY }}
project: shop
service: api
docker-image: ${{ needs.build.outputs.image }}
registry-url: ghcr.io
registry-username: ${{ github.actor }}
# GITHUB_TOKEN expires with this job. Dokploy stores these credentials
# and reuses them whenever it restarts the container, so use a
# long-lived PAT -- or a Dokploy registry -- for a private image.
registry-password: ${{ secrets.GHCR_PULL_TOKEN }}
timeout: 900

View File

@@ -0,0 +1,43 @@
# Promote an already-built image to an environment on demand, and roll back the
# same way. Nothing is rebuilt: the tag chosen here is one CI has already
# tested and pushed.
name: promote
on:
workflow_dispatch:
inputs:
environment:
description: Dokploy environment to deploy to
type: choice
options: [staging, production]
default: staging
tag:
description: Image tag to promote, e.g. a short commit SHA
required: true
jobs:
promote:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- id: deploy
uses: maxvojtkov/dokploy-deploy-action@v1
with:
host: ${{ secrets.DOKPLOY_HOST }}
api-key: ${{ secrets.DOKPLOY_API_KEY }}
project: shop
service: api
environment: ${{ inputs.environment }}
docker-image: ghcr.io/acme/api:${{ inputs.tag }}
title: Promote ${{ inputs.tag }} to ${{ inputs.environment }}
# Print the build log either way, since a human is watching.
logs: always
timeout: 900
- name: Announce
if: always()
run: |
echo "deployment ${{ steps.deploy.outputs.deployment-id }}" \
"finished with status ${{ steps.deploy.outputs.status }}" \
"in ${{ steps.deploy.outputs.duration }}s"