Metadata-Version: 2.4
Name: apx-dokploy
Version: 0.8.0
Summary: Dokploy for Action Platform: the dokploy deploy target (a Docker image the CI publishes, pulled by Dokploy), its overlay, readiness checks, and tools to read projects, applications and deployments.
Author-email: Action Platform <cloud@actionplatform.io>
License-Expression: Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: action-platform>=0.61.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: action-platform[mcp]; extra == "dev"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/actionplatform/action-platform/master/docs/assets/icon.svg" alt="Action Platform" width="120">
</p>

<h1 align="center">apx-dokploy</h1>

<p align="center">
  <strong>Deploy to Dokploy from Action Platform: every deployment is a release tag.</strong>
</p>

<p align="center">
  <a href="https://pypi.org/project/apx-dokploy/"><img alt="PyPI" src="https://img.shields.io/pypi/v/apx-dokploy?style=flat-square&logo=pypi&logoColor=white&color=2ea44f"></a>
  <a href="https://github.com/actionplatform/apx-dokploy/releases/latest"><img alt="Release" src="https://img.shields.io/github/v/release/actionplatform/apx-dokploy?style=flat-square&logo=github&color=2ea44f"></a>
  <a href="https://github.com/actionplatform/apx-dokploy/actions/workflows/code-quality.yml"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/actionplatform/apx-dokploy/code-quality.yml?branch=master&style=flat-square&label=ci"></a>
  <a href="https://github.com/actionplatform/apx-dokploy/blob/master/LICENSE"><img alt="License" src="https://img.shields.io/pypi/l/apx-dokploy?style=flat-square&color=blue"></a>
  <img alt="Python" src="https://img.shields.io/badge/python-%E2%89%A53.11-3776ab?style=flat-square&logo=python&logoColor=white">
</p>

---

Self-hosting on [Dokploy](https://dokploy.com) usually ends in a build running on the server, or a "latest" image nobody can trace to a release. **apx-dokploy** is the [Action Platform](https://github.com/actionplatform/action-platform) plugin that keeps the build out of it: the overlay's workflow publishes `ghcr.io/<owner>/<repo>:<version>` on every published release, and the `dokploy` deploy target tells Dokploy which tag to run and waits for the deployment to end. `apx-` is the prefix every Action Platform extension carries.

## What you get

- **The `dokploy` deploy target.** `deploy`, `rollback`, `diagnose` and `delete`; the build never runs on the platform or on Dokploy, every deployment references a release, and rolling back is pointing at the previous tag.
- **One overlay for every language** of the official `web/*` templates: `Dockerfile`, `.dockerignore`, `docker-compose.yml`, the image workflow and `DEPLOY.md`.
- **Provisioning.** Dokploy project, environment and application are created on the first deploy, the domain included when `[deploy.domains]` names one.
- **Readiness before the deploy.** Settings, image published at the registry, API key and application state, run by the platform after every release.
- **Access management.** Members, roles and project access of the instance's organization through the platform's service access.
- **Read tools.** `dokploy_projects`, `dokploy_applications` and `dokploy_deployments` for MCP, and `action-platform dokploy projects|applications|deployments` for the terminal.

## Install

```bash
action-platform plugin install dokploy
export DOKPLOY_URL=… DOKPLOY_API_KEY=…      # or Plugins → Dokploy → Configure on the platform
action-platform cloud set dokploy               # Dockerfile, compose file, image workflow
action-platform deploy --dry-run                # readiness: settings, image, key, application
action-platform deploy                          # point Dokploy at <image>:<version>, follow to done
action-platform diagnose
```

The variables are for a machine. On the hosted platform the plugin reads the organization's options only — never the worker's variables nor an options file.

## How it works

The build never runs on the platform or on Dokploy. The overlay's workflow publishes `ghcr.io/<owner>/<repo>:<version>` on every published release; the target tells Dokploy which tag to run and waits for the deployment to end. Every deployment therefore references a release, and rolling back is pointing at the previous tag.

| | |
|---|---|
| Overlay | `Dockerfile` (two stages on the [images-base](https://github.com/actionplatform/images-base) build and runtime images, `ap-build package`, port 8000), `.dockerignore`, `docker-compose.yml` for a machine, `.github/workflows/docker-publish.yml` (GitHub CI only), `DEPLOY.md`. One overlay for every language of the official `web/*` templates |
| Mapping | Dokploy project = `[project] name`; environment = the scope (`dev`, `prod`); application = `<name>-<scope>`. `create` and the first `deploy` provision what is missing, the domain included when `[deploy.domains]` names one |
| Readiness | `dokploy.settings` (url, key, image known), `image.published` (a manifest HEAD at the registry, following the bearer challenge), `dokploy.credentials` (the key opens `project.all`), `dokploy.application` (exists, not mid-deployment). The platform runs it after every release and refuses a blocked deploy |
| Deploy | `application.saveDockerProvider` with `<image>:<version>`, `application.deploy` titled `v<version>`, then `application.one` until `done` or `error` (15 minutes at most). Every step reaches the platform's run log |
| Rollback | the previous `done` deployment titled `v<version>` in the history, or the version asked for, deployed again |
| Diagnose | status, image, version and url of the scope's application |
| Delete | `application.delete` of the scope's application |
| Tools | `dokploy_projects`, `dokploy_applications`, `dokploy_deployments` |
| Commands | `action-platform dokploy projects\|applications\|deployments` |
| Access | members, roles and project access of the instance's organization, managed through the platform's [service access](https://github.com/actionplatform/action-platform/blob/master/docs/concept_service_access.md) (see [Access](#access)) |

## Configuration

`platform.toml`:

```toml
[deploy]
target = "dokploy"
# url = "https://dokploy.example.com"    # overrides the plugin option
# image = "ghcr.io/acme/shop"            # default: ghcr.io/<[source_host] repo>
# project = "shop"                       # default: [project] name
# application = "shop"                   # default: [project] name
# port = 8000
# health = "/health"                    # checked after the deploy; "" skips it

[deploy.domains]
prod = "shop.example.com"
dev = "shop-dev.example.com"

[deploy.env]                             # set on the application before each deploy,
LOG_LEVEL = "info"                       # over what it already has
```

Plugin options (Plugins → Dokploy → Configure on the platform; on a machine, the environment or `~/.action-platform/plugins/dokploy.json`):

| Option | Environment | |
|---|---|---|
| `url` | `DOKPLOY_URL` | where the dashboard answers. Order on a machine: `[deploy]`, `AP_DOKPLOY_URL`, `DOKPLOY_URL`, the options file |
| `api_key` | `DOKPLOY_API_KEY` | Settings → API Keys in Dokploy. Never in `platform.toml` |
| `registry_username`, `registry_password` | `AP_DOKPLOY_REGISTRY_*` | only for a private image; a GitHub token with `read:packages` for ghcr.io |

A deploy job carries the options as `AP_DOKPLOY_<KEY>`.

## Access

The plugin brings the `dokploy` service to the platform's service access: who belongs to the instance's organization, with which role, and which projects a member may open. It reads the plugin's `url` and `api_key` options only, and needs an API key created by an **owner** of the organization.

| Resource | Levels | Meaning |
|---|---|---|
| `org` | `member`, `admin`, `owner` | membership of the organization. The platform grants `member` and `admin`; the owner is read and never changed |
| `project/<name>` | `access` | the member may open that project and its environments. Owners and admins already see every project, so project grants for them are not kept |

- Accounts are user emails.
- Granting `org` sends an invitation. The invitation counts as access while it is pending and unexpired; project access can be granted once it is accepted.
- A role change updates the member's role.
- Revoking `org` from a pending invitation cancels it. Revoking it from an accepted member calls Dokploy's `user.remove`, which on a self-hosted instance **deletes the user** from the instance, not only from the organization.
- Granting or revoking `project/<name>` keeps the member's other permissions as they are.

## Requirements

- Action Platform 0.33 or newer.
- Dokploy 0.20 or newer (projects with environments; `application.saveDockerProvider`).
- An API key **without a rate limit** (Settings > API Keys): a deploy makes more calls than a limited key allows and gets 401 half-way.
- The image published before the deploy: on GitHub, the overlay's workflow does it on every release. Another CI publishes `<image>:<version>` itself; the `image.published` check waits for it.
- The container listens on `$PORT` (8000 in the overlay's Dockerfile).

## Development

```bash
pip install -e ".[dev]"
ruff check . && ruff format --check . && pytest
```

Tests never reach the network: `tests/fake.py` is a Dokploy in memory.

| Module | Responsibility (ABC in `abc.py`) |
|---|---|
| `target.py` | `DokployTarget`: the core's `DeployTarget` contract, composing the parts below |
| `spec.py` | `Spec`: options, `platform.toml` and settings resolved once per call |
| `client.py` | `Api`: the Dokploy REST API |
| `access.py` | `DokployAccess`: the access provider (members, roles, project access) |
| `registry.py` | `Registry`: whether an image tag was published |
| `provision.py` | `Provisioner`: project → environment (scope) → application |
| `domains.py` | `Domains`: the scope's domain, or one Dokploy generates |
| `deployments.py` | `Deployments`: point at the tag, deploy, wait, previous version |
| `health.py` | `Health`: the app answers its health route after the deploy |
| `checks.py` | `Readiness`: settings, image, API key, application state |
| `settings.py` | where a value comes from: argument, job env, process env, options file |
| `tools.py`, `cli.py` | read-only views for MCP and the terminal |

## How it fits in Action Platform

[Action Platform](https://github.com/actionplatform/action-platform) turns scaffold, CI, versioning and deploy into one set of verbs — `init`, `release`, `readiness`, `deploy`, `rollback`, `diagnose` — on a CLI, a web app and an MCP server. Everything cloud-specific is a plugin: this one is the `dokploy` deploy target behind the core's verbs, and its readiness checks run after every release. It is listed in [plugins-index](https://github.com/actionplatform/plugins-index); [apx-example](https://github.com/actionplatform/apx-example) is the template for writing another one.

## Contributing

Git-flow branches (`<kind>/<issue>-slug`), Conventional Commits and one pull request per change, as in the [main repository's guide](https://github.com/actionplatform/action-platform/blob/master/CONTRIBUTING.md). Rules for contributors and agents are in [`AGENTS.md`](AGENTS.md); see [Development](#development) for the test setup.

## License

Apache 2.0 — see [LICENSE](LICENSE).
