@trojeancedric/deployer 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +197 -2
- package/dist/deployer.js +5616 -0
- package/examples/sentinel.deployer.json +46 -0
- package/package.json +54 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 trojeancedric
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,198 @@
|
|
|
1
|
-
#
|
|
1
|
+
# deployer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build Docker images from a commit, push them to GitHub Container Registry (or any registry), then — on the server — pick a version and deploy it with docker compose. One CLI for both halves, with an interactive full-screen UI (keyboard **and mouse**) and plain scriptable commands.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
your machine your server (Ubuntu + Docker)
|
|
7
|
+
──────────── ─────────────────────────────
|
|
8
|
+
deployer build ──▶ ghcr.io/<owner>/<repo>/* ──▶ deployer deploy (or: pick a version in the UI)
|
|
9
|
+
:1.4.0-0b923205 pull → .env tag vars → compose up → checks
|
|
10
|
+
:latest rolls back automatically if checks fail
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g @trojeancedric/deployer # on the build machine AND on the server (Node ≥ 18.17)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
**1. In your repository** (build machine):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
deployer init # finds your Dockerfiles, reads the git remote, writes deployer.json
|
|
23
|
+
deployer # interactive UI → Build & push
|
|
24
|
+
# or scripted:
|
|
25
|
+
deployer build # builds every default image, tags <version>-<sha8> + latest, pushes
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**2. Connect the server** — from the same repository:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
deployer setup # guided: repo, server, ssh, deployer + docker there, a read-only registry token
|
|
32
|
+
deployer build --deploy
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Or by hand, on the server**, in the directory holding your `docker-compose.yml` and `.env`:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
echo "$GHCR_TOKEN" | docker login ghcr.io -u <github-user> --password-stdin # token with read:packages
|
|
39
|
+
deployer # interactive UI → Deploy latest / Pick a version / Roll back
|
|
40
|
+
# or scripted:
|
|
41
|
+
deployer versions
|
|
42
|
+
deployer deploy latest --yes
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Copy `deployer.json` to the server once with `deployer sync` (see *remote* below), or by hand.
|
|
46
|
+
|
|
47
|
+
## Setting up a server: `deployer setup`
|
|
48
|
+
|
|
49
|
+
An interactive walk-through, run on your build machine. Run it again whenever something changes — the current values are the defaults.
|
|
50
|
+
|
|
51
|
+
1. **Project** — finds `deployer.json` (or creates it like `deployer init`) and asks for the GitHub repository (`owner/name`, default: the `origin` remote).
|
|
52
|
+
2. **Server** — host, ssh port and user, and how you log in: your usual ssh login, a key file, or a **password**. With a password, deployer creates a dedicated key (`~/.ssh/deployer_<project>`) and installs it with `ssh-copy-id`, which asks for the password once — deploys run ssh without prompts, so they need a key. It then connects (offering to trust a new host's key; a *changed* host key stops the setup).
|
|
53
|
+
3. **Server software** — creates the deploy directory (default `/opt/<project>` for root, `~/<project>` otherwise) and checks docker, docker compose, Node ≥ 18.17 and deployer, including installs made with nvm. It offers to install deployer when Node is there.
|
|
54
|
+
4. **Registry access** — prints a link that creates the right token, e.g.
|
|
55
|
+
`https://github.com/settings/tokens/new?scopes=read:packages&description=<project>-vps-ghcr-pull`,
|
|
56
|
+
and asks you to paste it (hidden). The token is checked with GitHub (classic, `read:packages`, warns about broader scopes) and against each image on ghcr.io, then `docker login` runs **on the server** into the project's own docker config (`remote.dockerConfig`, `.docker` in the deploy directory). The token travels over ssh's stdin, never on a command line, and the server's other docker logins are left alone.
|
|
57
|
+
5. **Save and verify** — writes `deployer.json`, then pulls the newest image on the server, printing the command so you can run the same check yourself:
|
|
58
|
+
`ssh root@203.0.113.10 'docker --config /opt/shop/.docker pull ghcr.io/acme/shop/web:latest'`.
|
|
59
|
+
Offers `deployer sync`, and points at a `.env.example` if the server has no `.env` yet.
|
|
60
|
+
6. **This machine** — checks that builds can push (`GHCR_TOKEN`, your `gh` login with `write:packages`, or a `docker login`).
|
|
61
|
+
|
|
62
|
+
`deployer setup --check` runs every check without asking anything and exits 1 when the server is not ready — handy after a server rebuild or a token expiry. **Set up server** in the interactive UI starts the wizard.
|
|
63
|
+
|
|
64
|
+
Your compose file selects each image's tag through a variable — that is what deployer moves:
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
services:
|
|
68
|
+
web:
|
|
69
|
+
image: ghcr.io/acme/shop/web:${WEB_VERSION}
|
|
70
|
+
api:
|
|
71
|
+
image: ghcr.io/acme/shop/api:${API_VERSION:-${WEB_VERSION}} # optional fallback
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## The interactive UI
|
|
75
|
+
|
|
76
|
+
Run `deployer` with no command. Arrows / `j` `k` move, Enter or a **click** selects, the underlined letter is a shortcut, `esc` goes back, `q` quits, `/` filters lists, the wheel scrolls.
|
|
77
|
+
|
|
78
|
+
| Screen | What it does |
|
|
79
|
+
|---|---|
|
|
80
|
+
| **Build & push** | toggle images, set tag / git ref / `:latest` / checks / dry run, see exactly which tags will be pushed, then build with a live step list and log. Optionally deploy right after. |
|
|
81
|
+
| **Deploy latest** | resolves the newest published version and shows what moves, image by image (`current → new`). |
|
|
82
|
+
| **Pick a version** | every published version, newest first, with push dates, which images it contains, ★ latest and ● running. Enter to deploy. |
|
|
83
|
+
| **Roll back** | puts back what the last deploy replaced. Running it again keeps walking back. |
|
|
84
|
+
| **Status** | the tag each image runs, container states, the last deploy. |
|
|
85
|
+
| **History** | past deploys on that server; Enter re-deploys an exact set of tags. |
|
|
86
|
+
| **Sync to server** | copies `deployer.json` and your compose file(s) to the server. |
|
|
87
|
+
| **Set up server** | leaves the UI and runs `deployer setup`. |
|
|
88
|
+
|
|
89
|
+
On the server the UI acts directly. On your build machine, if `deployer.json` has a `remote` section, the deploy screens drive the server over ssh (`deployer` must be installed there too).
|
|
90
|
+
|
|
91
|
+
## Commands
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
deployer interactive UI (in a terminal)
|
|
95
|
+
deployer build [image...] --tag T --ref R --platforms P --no-latest --checks --deploy --dry-run --plan
|
|
96
|
+
deployer versions --limit N --json
|
|
97
|
+
deployer deploy [tag|latest] --images a,b --yes
|
|
98
|
+
deployer rollback --yes
|
|
99
|
+
deployer status --json
|
|
100
|
+
deployer history --json
|
|
101
|
+
deployer sync
|
|
102
|
+
deployer setup --check
|
|
103
|
+
deployer init --force
|
|
104
|
+
global: -c/--config <file> (or $DEPLOYER_CONFIG), --help, --version
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Exit codes: 0 success, 1 failure, 130 cancelled. Data goes to stdout (`--json`, the built tag), progress to stderr — so `TAG=$(deployer build)` works.
|
|
108
|
+
|
|
109
|
+
## What a build does
|
|
110
|
+
|
|
111
|
+
1. Checks docker + buildx, and logs in to the registry: `GHCR_TOKEN` (or `DEPLOYER_TOKEN`/`GITHUB_TOKEN`) if set, else an existing `docker login`, else your `gh` CLI token (needs `write:packages`: `gh auth refresh -s write:packages`).
|
|
112
|
+
2. Resolves `ref` to a commit and warns about uncommitted or unpushed work.
|
|
113
|
+
3. Exports **the committed tree** with `git archive` — uncommitted edits and local `node_modules` never reach an image.
|
|
114
|
+
4. Computes the tag from `version.format` (default `{version}-{sha}`, version read from `version.file` *at that commit*).
|
|
115
|
+
5. Optionally runs your `checks` against that exported tree (`--checks`).
|
|
116
|
+
6. `docker buildx build --platform … --push` per image, with OCI labels (`revision`, `version`, `created`), tagged `:<tag>` and `:latest`. The `source` label **and** index annotation link the GHCR package to the repository, so it is listed under the repo's *Packages* and inherits its visibility and access. (buildx pushes an image index whenever it attaches provenance or builds several platforms, and GHCR reads the link from the index; a builder that pushes a single manifest gets a retry with the source on the manifest only.)
|
|
117
|
+
|
|
118
|
+
Building on an Apple Silicon Mac for an x86 server: keep `"platforms": ["linux/amd64"]` and enable *Use Rosetta for x86_64/amd64 emulation* in Docker Desktop — it is many times faster than QEMU.
|
|
119
|
+
|
|
120
|
+
## What a deploy does
|
|
121
|
+
|
|
122
|
+
1. Takes a lock (`.deployer/lock`) so two deploys never overlap.
|
|
123
|
+
2. **Pulls the new images first** — a missing tag or a refused login stops here, with nothing changed.
|
|
124
|
+
3. Writes the tag variables into `.env` (atomically, keeping its permissions and every other line).
|
|
125
|
+
If an image you are *not* deploying follows a variable you are moving (`${API_VERSION:-${WEB_VERSION}}`) and has no variable of its own, it is first pinned to the tag it runs today — so a web-only release never drags api to a tag that does not exist.
|
|
126
|
+
4. `docker compose up -d --pull never` (only the images just pulled are used — handy when the server cannot reach Docker Hub).
|
|
127
|
+
5. Waits for the deployed containers to be running/healthy, runs the HTTP `healthcheck`, then your `postDeploy` hooks.
|
|
128
|
+
6. If any of that fails, the previous tags are written back and compose is run again (`autoRollback`).
|
|
129
|
+
7. Records the deploy in `.deployer/history.json` (who, when, every variable before/after).
|
|
130
|
+
|
|
131
|
+
## deployer.json
|
|
132
|
+
|
|
133
|
+
```jsonc
|
|
134
|
+
{
|
|
135
|
+
"name": "shop",
|
|
136
|
+
"repo": "acme/shop", // default: parsed from `git remote get-url origin`
|
|
137
|
+
"imagePrefix": "ghcr.io/acme/shop", // default: ghcr.io/<repo>, lower-cased
|
|
138
|
+
"ref": "main", // default: HEAD
|
|
139
|
+
"version": { "file": "package.json", "format": "{version}-{sha}" },
|
|
140
|
+
// placeholders: {version} {sha} {branch} {date} {time}
|
|
141
|
+
"platforms": ["linux/amd64"],
|
|
142
|
+
"pushLatest": true,
|
|
143
|
+
"images": {
|
|
144
|
+
"web": { "context": "frontend", "dockerfile": "frontend/Dockerfile", "tagVar": "WEB_VERSION" },
|
|
145
|
+
"api": {
|
|
146
|
+
"context": "backend",
|
|
147
|
+
"tagVar": "API_VERSION", // default: <KEY>_VERSION
|
|
148
|
+
"tagVarFallback": "WEB_VERSION", // what compose falls back to, if anything
|
|
149
|
+
"buildArgs": { "NODE_ENV": "production" },
|
|
150
|
+
"target": "runtime",
|
|
151
|
+
"extraArgs": ["--secret", "id=npm,src=.npmrc"]
|
|
152
|
+
},
|
|
153
|
+
"migrator": { "context": "backend", "service": false }, // built, but not a compose service
|
|
154
|
+
"tools": { "context": "tools", "default": false, // only built when named
|
|
155
|
+
"versioned": false, "tags": ["v{arg:V}"], "buildArgs": { "V": "3" } }
|
|
156
|
+
},
|
|
157
|
+
"checks": [{ "name": "tests", "cwd": "backend", "run": "npm ci && npm test" }],
|
|
158
|
+
"deploy": {
|
|
159
|
+
"dir": ".", // default: where deployer.json is
|
|
160
|
+
"composeFile": "docker-compose.yml",
|
|
161
|
+
"envFile": ".env",
|
|
162
|
+
"pull": "never", // --pull for `compose up`: never | missing | always
|
|
163
|
+
"up": "all", // recreate all services, or only "deployed" ones
|
|
164
|
+
"healthcheck": { "url": "http://localhost:3000/health", "timeout": 90, "expectStatus": 200 },
|
|
165
|
+
"waitForServices": true,
|
|
166
|
+
"postDeploy": [{ "name": "migrate", "run": "docker compose exec -T api npm run migrate" }],
|
|
167
|
+
"autoRollback": true,
|
|
168
|
+
"keepHistory": 30
|
|
169
|
+
},
|
|
170
|
+
"remote": { // optional: drive the server from the build machine
|
|
171
|
+
"host": "203.0.113.10",
|
|
172
|
+
"user": "deploy",
|
|
173
|
+
"port": 22,
|
|
174
|
+
"identityFile": "~/.ssh/deploy_key", // also sets IdentitiesOnly=yes
|
|
175
|
+
"dir": "~/shop",
|
|
176
|
+
"command": "deployer", // how to run deployer there (setup writes the nvm form when needed)
|
|
177
|
+
"dockerConfig": ".docker", // DOCKER_CONFIG for this project, inside "dir": its own registry login
|
|
178
|
+
"files": [{ "from": "deploy/docker-compose.prod.yml", "to": "docker-compose.yml" }]
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`examples/sentinel.deployer.json` is a complete real-world config (five images, an opt-in emulator image tagged `api-34`, fallback variables, CI-style checks, a post-deploy smoke test) that produces exactly the same images and tags as a hand-written `build-images.sh`.
|
|
184
|
+
|
|
185
|
+
## Listing versions
|
|
186
|
+
|
|
187
|
+
For `ghcr.io`, versions come from the GitHub Packages API (it knows when each was pushed). The token is taken from `DEPLOYER_TOKEN`/`GHCR_TOKEN`/`GITHUB_TOKEN`, else the server's `docker login ghcr.io` credentials, else `gh auth token` — it needs **read:packages** (a classic PAT; fine-grained tokens fall back to the registry API). Any other registry uses the Docker Registry v2 API, reading dates from the images' `created` label.
|
|
188
|
+
|
|
189
|
+
## Development
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
npm install
|
|
193
|
+
npm run dev -- --help # run from source (tsx)
|
|
194
|
+
npm run typecheck && npm test && npm run build
|
|
195
|
+
npm publish # prepublishOnly runs typecheck + tests + build
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The UI is dependency-free on purpose (ANSI, raw-mode keys and SGR mouse are hand-rolled in `src/tui/`), and so is the CLI: no runtime dependencies at all.
|