@trojeancedric/deployer 0.0.0-stage → 0.1.0

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 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,171 @@
1
- # Temporary Holding Version
1
+ # deployer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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. On the server**, in the directory holding your `docker-compose.yml` and `.env`:
29
+
30
+ ```bash
31
+ echo "$GHCR_TOKEN" | docker login ghcr.io -u <github-user> --password-stdin # token with read:packages
32
+ deployer # interactive UI → Deploy latest / Pick a version / Roll back
33
+ # or scripted:
34
+ deployer versions
35
+ deployer deploy latest --yes
36
+ ```
37
+
38
+ Copy `deployer.json` to the server once with `deployer sync` (see *remote* below), or by hand.
39
+
40
+ Your compose file selects each image's tag through a variable — that is what deployer moves:
41
+
42
+ ```yaml
43
+ services:
44
+ web:
45
+ image: ghcr.io/acme/shop/web:${WEB_VERSION}
46
+ api:
47
+ image: ghcr.io/acme/shop/api:${API_VERSION:-${WEB_VERSION}} # optional fallback
48
+ ```
49
+
50
+ ## The interactive UI
51
+
52
+ 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.
53
+
54
+ | Screen | What it does |
55
+ |---|---|
56
+ | **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. |
57
+ | **Deploy latest** | resolves the newest published version and shows what moves, image by image (`current → new`). |
58
+ | **Pick a version** | every published version, newest first, with push dates, which images it contains, ★ latest and ● running. Enter to deploy. |
59
+ | **Roll back** | puts back what the last deploy replaced. Running it again keeps walking back. |
60
+ | **Status** | the tag each image runs, container states, the last deploy. |
61
+ | **History** | past deploys on that server; Enter re-deploys an exact set of tags. |
62
+ | **Sync to server** | copies `deployer.json` and your compose file(s) to the server. |
63
+
64
+ 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).
65
+
66
+ ## Commands
67
+
68
+ ```
69
+ deployer interactive UI (in a terminal)
70
+ deployer build [image...] --tag T --ref R --platforms P --no-latest --checks --deploy --dry-run --plan
71
+ deployer versions --limit N --json
72
+ deployer deploy [tag|latest] --images a,b --yes
73
+ deployer rollback --yes
74
+ deployer status --json
75
+ deployer history --json
76
+ deployer sync
77
+ deployer init --force
78
+ global: -c/--config <file> (or $DEPLOYER_CONFIG), --help, --version
79
+ ```
80
+
81
+ Exit codes: 0 success, 1 failure, 130 cancelled. Data goes to stdout (`--json`, the built tag), progress to stderr — so `TAG=$(deployer build)` works.
82
+
83
+ ## What a build does
84
+
85
+ 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`).
86
+ 2. Resolves `ref` to a commit and warns about uncommitted or unpushed work.
87
+ 3. Exports **the committed tree** with `git archive` — uncommitted edits and local `node_modules` never reach an image.
88
+ 4. Computes the tag from `version.format` (default `{version}-{sha}`, version read from `version.file` *at that commit*).
89
+ 5. Optionally runs your `checks` against that exported tree (`--checks`).
90
+ 6. `docker buildx build --platform … --push` per image, with OCI labels (`source` links the GHCR package to the repo so it inherits its visibility, plus `revision`, `version`, `created`), tagged `:<tag>` and `:latest`.
91
+
92
+ 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.
93
+
94
+ ## What a deploy does
95
+
96
+ 1. Takes a lock (`.deployer/lock`) so two deploys never overlap.
97
+ 2. **Pulls the new images first** — a missing tag or a refused login stops here, with nothing changed.
98
+ 3. Writes the tag variables into `.env` (atomically, keeping its permissions and every other line).
99
+ 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.
100
+ 4. `docker compose up -d --pull never` (only the images just pulled are used — handy when the server cannot reach Docker Hub).
101
+ 5. Waits for the deployed containers to be running/healthy, runs the HTTP `healthcheck`, then your `postDeploy` hooks.
102
+ 6. If any of that fails, the previous tags are written back and compose is run again (`autoRollback`).
103
+ 7. Records the deploy in `.deployer/history.json` (who, when, every variable before/after).
104
+
105
+ ## deployer.json
106
+
107
+ ```jsonc
108
+ {
109
+ "name": "shop",
110
+ "repo": "acme/shop", // default: parsed from `git remote get-url origin`
111
+ "imagePrefix": "ghcr.io/acme/shop", // default: ghcr.io/<repo>, lower-cased
112
+ "ref": "main", // default: HEAD
113
+ "version": { "file": "package.json", "format": "{version}-{sha}" },
114
+ // placeholders: {version} {sha} {branch} {date} {time}
115
+ "platforms": ["linux/amd64"],
116
+ "pushLatest": true,
117
+ "images": {
118
+ "web": { "context": "frontend", "dockerfile": "frontend/Dockerfile", "tagVar": "WEB_VERSION" },
119
+ "api": {
120
+ "context": "backend",
121
+ "tagVar": "API_VERSION", // default: <KEY>_VERSION
122
+ "tagVarFallback": "WEB_VERSION", // what compose falls back to, if anything
123
+ "buildArgs": { "NODE_ENV": "production" },
124
+ "target": "runtime",
125
+ "extraArgs": ["--secret", "id=npm,src=.npmrc"]
126
+ },
127
+ "migrator": { "context": "backend", "service": false }, // built, but not a compose service
128
+ "tools": { "context": "tools", "default": false, // only built when named
129
+ "versioned": false, "tags": ["v{arg:V}"], "buildArgs": { "V": "3" } }
130
+ },
131
+ "checks": [{ "name": "tests", "cwd": "backend", "run": "npm ci && npm test" }],
132
+ "deploy": {
133
+ "dir": ".", // default: where deployer.json is
134
+ "composeFile": "docker-compose.yml",
135
+ "envFile": ".env",
136
+ "pull": "never", // --pull for `compose up`: never | missing | always
137
+ "up": "all", // recreate all services, or only "deployed" ones
138
+ "healthcheck": { "url": "http://localhost:3000/health", "timeout": 90, "expectStatus": 200 },
139
+ "waitForServices": true,
140
+ "postDeploy": [{ "name": "migrate", "run": "docker compose exec -T api npm run migrate" }],
141
+ "autoRollback": true,
142
+ "keepHistory": 30
143
+ },
144
+ "remote": { // optional: drive the server from the build machine
145
+ "host": "203.0.113.10",
146
+ "user": "deploy",
147
+ "port": 22,
148
+ "identityFile": "~/.ssh/deploy_key", // also sets IdentitiesOnly=yes
149
+ "dir": "~/shop",
150
+ "command": "deployer", // how to run deployer there
151
+ "files": [{ "from": "deploy/docker-compose.prod.yml", "to": "docker-compose.yml" }]
152
+ }
153
+ }
154
+ ```
155
+
156
+ `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`.
157
+
158
+ ## Listing versions
159
+
160
+ 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.
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ npm install
166
+ npm run dev -- --help # run from source (tsx)
167
+ npm run typecheck && npm test && npm run build
168
+ npm publish # prepublishOnly runs typecheck + tests + build
169
+ ```
170
+
171
+ 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.