python-ship 0.1.0__py3-none-any.whl
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.
- python_ship/__init__.py +3 -0
- python_ship/__main__.py +3 -0
- python_ship/adapters.py +270 -0
- python_ship/cli.py +588 -0
- python_ship/compose.py +439 -0
- python_ship/config.py +368 -0
- python_ship/contracts.py +234 -0
- python_ship/init.py +369 -0
- python_ship/mutagen.py +89 -0
- python_ship/plugins.py +149 -0
- python_ship/production.py +69 -0
- python_ship/py.typed +0 -0
- python_ship/release.py +175 -0
- python_ship/runtime.py +83 -0
- python_ship/security.py +69 -0
- python_ship/servers.py +72 -0
- python_ship/services.py +353 -0
- python_ship/storage.py +151 -0
- python_ship/stubs.py +149 -0
- python_ship/templates/Dockerfile +52 -0
- python_ship/templates/check-python-security-floor.py +49 -0
- python_ship/templates/garage/Dockerfile +7 -0
- python_ship/templates/garage/garage.toml +15 -0
- python_ship/uv.py +76 -0
- python_ship-0.1.0.dist-info/METADATA +936 -0
- python_ship-0.1.0.dist-info/RECORD +30 -0
- python_ship-0.1.0.dist-info/WHEEL +5 -0
- python_ship-0.1.0.dist-info/entry_points.txt +2 -0
- python_ship-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- python_ship-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,936 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-ship
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Framework-agnostic, cross-platform Docker development environment and portable releases for Python web apps.
|
|
5
|
+
Author: python-ship
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ship-ecosystem/python-ship
|
|
8
|
+
Project-URL: Documentation, https://github.com/ship-ecosystem/python-ship#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/ship-ecosystem/python-ship
|
|
10
|
+
Project-URL: Issues, https://github.com/ship-ecosystem/python-ship/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/ship-ecosystem/python-ship/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: docker,docker-compose,development-environment,asgi,django,fastapi,uv,devops
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Framework :: FastAPI
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
26
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
27
|
+
Classifier: Topic :: System :: Software Distribution
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.11
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE.md
|
|
32
|
+
Requires-Dist: typer<1,>=0.27
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# python-ship
|
|
36
|
+
|
|
37
|
+
[](https://github.com/ship-ecosystem/python-ship/actions/workflows/quality.yml)
|
|
38
|
+
[](https://github.com/ship-ecosystem/python-ship/actions/workflows/docker-integration.yml)
|
|
39
|
+
[](https://pypi.org/project/python-ship/)
|
|
40
|
+
[](https://pypi.org/project/python-ship/)
|
|
41
|
+
[](https://pypistats.org/packages/python-ship)
|
|
42
|
+
[](https://github.com/ship-ecosystem/python-ship/blob/main/LICENSE.md)
|
|
43
|
+
|
|
44
|
+
A framework-agnostic, cross-platform Docker development environment for
|
|
45
|
+
Python web apps, with portable production releases. It is the Python member
|
|
46
|
+
of the Ship ecosystem, alongside [PHP Ship](https://github.com/php-ship/ship):
|
|
47
|
+
the same commands, the same `ship.json` vocabulary and the same release
|
|
48
|
+
artifact, for any ASGI or WSGI app — a plain callable, Django, FastAPI or
|
|
49
|
+
Flask built in, anything else through a community adapter.
|
|
50
|
+
|
|
51
|
+
**Status: beta, first public release.** `init`/`up`/`down`/`exec`/`shell`/
|
|
52
|
+
`logs`/`db`/`config:test`/`build`/`release`/`npm`/`uv`/`manage` all work
|
|
53
|
+
end-to-end against a real Docker daemon, for a framework-free app, a Django,
|
|
54
|
+
a FastAPI and a Flask app alike, on Uvicorn, Hypercorn, Gunicorn or Granian: development stacks with a real database and
|
|
55
|
+
cache, production images, and releases booted on a machine with nothing but
|
|
56
|
+
Docker. CI runs the unit suite on Linux, macOS and Windows with Python
|
|
57
|
+
3.11–3.15, and the Docker suites on every push to `main`. See
|
|
58
|
+
[`docs/roadmap.md`](https://github.com/ship-ecosystem/python-ship/blob/main/docs/roadmap.md)
|
|
59
|
+
for what's built and what's next.
|
|
60
|
+
|
|
61
|
+
## Contents
|
|
62
|
+
|
|
63
|
+
- [Why not just write a Compose file?](#why-not-just-write-a-compose-file)
|
|
64
|
+
- [Requirements](#requirements)
|
|
65
|
+
- [Quick start](#quick-start)
|
|
66
|
+
- [Commands](#commands)
|
|
67
|
+
- [Services](#services)
|
|
68
|
+
- [Silo on older CPUs](#silo-on-older-cpus)
|
|
69
|
+
- [Configuration (`ship.json`)](#configuration-shipjson)
|
|
70
|
+
- [Adding a service later](#adding-a-service-later)
|
|
71
|
+
- [Multiple instances of a service](#multiple-instances-of-a-service)
|
|
72
|
+
- [Custom service names and an external network](#custom-service-names-and-an-external-network)
|
|
73
|
+
- [Dependencies and `ship uv`](#dependencies-and-ship-uv)
|
|
74
|
+
- [Web servers: ASGI and WSGI](#web-servers-asgi-and-wsgi)
|
|
75
|
+
- [Background tasks (Celery)](#background-tasks-celery)
|
|
76
|
+
- [Production releases](#production-releases)
|
|
77
|
+
- [Python security floor](#python-security-floor)
|
|
78
|
+
- [HTTPS / TLS](#https--tls)
|
|
79
|
+
- [Backing up data volumes](#backing-up-data-volumes)
|
|
80
|
+
- [Frontend dev server (Vite HMR)](#frontend-dev-server-vite-hmr)
|
|
81
|
+
- [File ownership in dev](#file-ownership-in-dev)
|
|
82
|
+
- [Debugging (debugpy)](#debugging-debugpy)
|
|
83
|
+
- [Faster file sync on Windows/macOS (Mutagen)](#faster-file-sync-on-windowsmacos-mutagen)
|
|
84
|
+
- [Running more than one project at once](#running-more-than-one-project-at-once)
|
|
85
|
+
- [Customizing the stack](#customizing-the-stack)
|
|
86
|
+
- [Extending ship](#extending-ship)
|
|
87
|
+
- [Architecture](#architecture)
|
|
88
|
+
- [Contributing](#contributing)
|
|
89
|
+
- [License](#license)
|
|
90
|
+
|
|
91
|
+
## Why not just write a Compose file?
|
|
92
|
+
|
|
93
|
+
You can, and every project that uses Ship ends up with one — Ship generates
|
|
94
|
+
it. What Ship adds is everything around that file that each project would
|
|
95
|
+
otherwise rebuild by hand:
|
|
96
|
+
|
|
97
|
+
- **One cross-platform CLI.** `ship` is a Python executable, so `ship up`,
|
|
98
|
+
`ship exec` and `ship db` run natively on Windows, macOS and Linux, with no
|
|
99
|
+
shell scripts and no requirement to keep the project inside WSL.
|
|
100
|
+
- **A portable release artifact, not just a dev tool.** `ship release --tag`
|
|
101
|
+
builds real production images (no bind mount, no uv or pip, a non-root
|
|
102
|
+
user) from the same `ship.json` and packages them with a final Compose
|
|
103
|
+
file, `.env.production`, and a deploy script into `dist/ship/<tag>/`. The
|
|
104
|
+
server needs nothing but Docker — see
|
|
105
|
+
[Production releases](#production-releases).
|
|
106
|
+
- **A real database shell without a published port.** `ship db` opens
|
|
107
|
+
`psql`/`mysql` inside the database container, reading its credentials from
|
|
108
|
+
that container's own environment.
|
|
109
|
+
- **Not tied to a framework.** The core knows nothing about Django or
|
|
110
|
+
FastAPI; both are [`FrameworkAdapter`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/contracts.py)
|
|
111
|
+
implementations on the same public extension point a third party uses —
|
|
112
|
+
the [Starlette example](https://github.com/ship-ecosystem/python-ship/tree/main/examples/community-adapter)
|
|
113
|
+
is one. A plain ASGI callable needs no framework, `requirements.txt` or
|
|
114
|
+
`pyproject.toml` at all.
|
|
115
|
+
- **Postgres and MySQL, Redis, RabbitMQ and Celery, four S3-compatible
|
|
116
|
+
stores, Meilisearch, Mailpit, Selenium and Playwright, Node; Uvicorn,
|
|
117
|
+
Hypercorn, Gunicorn and Granian** — `ship init` picks one option per group;
|
|
118
|
+
nothing is hardcoded to one choice.
|
|
119
|
+
|
|
120
|
+
## Requirements
|
|
121
|
+
|
|
122
|
+
- Python 3.11+ to run the `ship` CLI itself — or just
|
|
123
|
+
[uv](https://docs.astral.sh/uv/getting-started/installation/), which
|
|
124
|
+
installs `ship` with a Python it manages.
|
|
125
|
+
- Docker Desktop (or Docker Engine with Compose v2). This is what actually
|
|
126
|
+
runs your project; `ship` drives `docker compose`.
|
|
127
|
+
- [uv](https://docs.astral.sh/uv/) on the host. `ship init` offers to install
|
|
128
|
+
it with Astral's official installer if it's missing, and makes no changes to
|
|
129
|
+
the project if you decline.
|
|
130
|
+
- An ASGI app. Nothing else: no framework, no dependency manifest, no local
|
|
131
|
+
database, no Node install.
|
|
132
|
+
|
|
133
|
+
## Quick start
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
uv tool install python-ship # or: pipx install python-ship
|
|
137
|
+
cd your-project
|
|
138
|
+
ship init # pick your services interactively
|
|
139
|
+
ship up # build and start
|
|
140
|
+
ship manage migrate # Django only: registered when manage.py is detected
|
|
141
|
+
ship uv add httpx # add a dependency; `ship up` rebuilds the image
|
|
142
|
+
ship shell # drop into the app container
|
|
143
|
+
ship down
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`ship init` detects Django (`manage.py`) and FastAPI (a `FastAPI()` app) and
|
|
147
|
+
suggests the ASGI target to serve. A framework-free app works too — save this
|
|
148
|
+
as `main.py` and run `ship init`:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
async def app(scope, receive, send):
|
|
152
|
+
if scope["type"] != "http":
|
|
153
|
+
return
|
|
154
|
+
await send({"type": "http.response.start", "status": 200, "headers": []})
|
|
155
|
+
await send({"type": "http.response.body", "body": b"Hello from Ship"})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`ship init` writes `ship.json` and publishes a `ship/` directory (the
|
|
159
|
+
Dockerfile and its security check) into your project root — both are meant to
|
|
160
|
+
be committed. In scripts and CI, pass everything as options and add
|
|
161
|
+
`--no-interaction`:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
ship init -n --framework django --app project.asgi:application --database postgres --cache redis
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Production is a separate pair of commands, not a flag on `ship up` — see
|
|
168
|
+
[Production releases](#production-releases) for `ship build`/`ship release`.
|
|
169
|
+
|
|
170
|
+
## Commands
|
|
171
|
+
|
|
172
|
+
| Command | What it does |
|
|
173
|
+
|---|---|
|
|
174
|
+
| `ship init` | Interactive picker for the framework, ASGI target, server and services (database, cache, storage, ...); writes `ship.json` and publishes `ship/`. Every option has a flag for non-interactive use (`ship init --help`). Re-run it to change selections — see [Adding a service later](#adding-a-service-later). |
|
|
175
|
+
| `ship up` | Regenerates `ship/docker-compose.generated.yml` from `ship.json`, runs `docker compose up --build`, then waits until every container is running, every healthcheck passes and the app answers HTTP. Development only. |
|
|
176
|
+
| `ship build` | Builds every project-owned production image, tagged locally. Needs `.env.production` as soon as a selected service has a required credential. See [Production releases](#production-releases). |
|
|
177
|
+
| `ship release --tag <tag>` | Builds the same images (re-tagged) and assembles the portable release under `dist/ship/<tag>/`. |
|
|
178
|
+
| `ship down [--volumes]` | `docker compose down`. `--volumes` also deletes named volumes (database and storage data — use with care). |
|
|
179
|
+
| `ship exec <service> <cmd...>` | Runs a command inside a running service. The generic escape hatch every shortcut below wraps. |
|
|
180
|
+
| `ship shell [service]` | Opens a shell (`sh`) in a service; defaults to the app. |
|
|
181
|
+
| `ship logs [service] [-f]` | Shows logs for one service, or all of them. `-f`/`--follow` streams. |
|
|
182
|
+
| `ship db [instance]` | Opens the database's client (`psql`/`mysql`) with credentials from its own container. Name one of `additionalServices`' databases to open that instance instead. |
|
|
183
|
+
| `ship config:test` | Validates `ship.json`, `ship/`, both Compose models, and production credentials in `.env.production` — without Docker. Reports every problem it finds in one pass. |
|
|
184
|
+
| `ship doctor` | Shows the installed and published versions and the state and health of every container, with a recovery hint for anything that crashed. |
|
|
185
|
+
| `ship uv <args...>` | Runs uv dependency commands (`add`, `remove`, `lock`, `tree`, ...) in a temporary container with the project's Python. See [Dependencies](#dependencies-and-ship-uv). |
|
|
186
|
+
| `ship npm <args...>` | Runs `npm` in the Node frontend service (e.g. `ship npm install`, `ship npm run dev`). |
|
|
187
|
+
| `ship manage <args...>` | Runs `python manage.py` in the app — only registered for Django projects. |
|
|
188
|
+
| `ship flask <args...>` | Runs the `flask` CLI in the app (`FLASK_APP` is set) — only registered for Flask projects. A community adapter registers its own commands the same way. |
|
|
189
|
+
| `ship --version` | Shows the installed python-ship version. |
|
|
190
|
+
|
|
191
|
+
Every proxied command forwards its arguments exactly as typed (including
|
|
192
|
+
flags such as `ship manage migrate --database=other`), and returns the inner
|
|
193
|
+
command's exit code. `--project-directory PATH` before any command runs it
|
|
194
|
+
against another project. Without a terminal (CI, piped input), `exec`-style
|
|
195
|
+
commands pass `-T` to Compose, so `ship db < dump.sql` works.
|
|
196
|
+
|
|
197
|
+
## Services
|
|
198
|
+
|
|
199
|
+
`ship init` groups services (database, cache, storage, search, mail, testing,
|
|
200
|
+
frontend) and lets you pick one per group. "Wired" means the container runs,
|
|
201
|
+
is healthchecked where it can be, and the right variables are injected into
|
|
202
|
+
the app; it does not install the Python client library your app uses to
|
|
203
|
+
read them — that stays your app's decision.
|
|
204
|
+
|
|
205
|
+
| Service | Wired automatically | Still needed in the app |
|
|
206
|
+
|---|---|---|
|
|
207
|
+
| PostgreSQL (`postgres`, or `pgsql`) | `DB_HOST`/`DB_PORT`/`DB_NAME`/`DB_USER`/`DB_PASSWORD`, `ship db` | A driver such as `psycopg[binary]`, and settings that read `DB_*` |
|
|
208
|
+
| MySQL (`mysql`) | The same `DB_*` variables, a separate `DB_ROOT_PASSWORD` the app never receives, `ship db` | A driver such as `mysqlclient` or `PyMySQL` |
|
|
209
|
+
| Redis (`redis`) | `REDIS_URL`; RDB snapshots plus an append-only log | `redis` |
|
|
210
|
+
| RabbitMQ (`rabbitmq`, broker group) | `AMQP_URL`; management UI on `127.0.0.1:${RABBITMQ_MANAGEMENT_PORT:-15672}` in development | A client such as `kombu` or `pika`, or just Celery |
|
|
211
|
+
| Celery (`celery`, tasks group) | A worker and a beat container from the app's image; `CELERY_BROKER_URL`, `CELERY_RESULT_BACKEND`, `CELERY_APP` | `celery` in your dependencies — see [Background tasks](#background-tasks-celery) |
|
|
212
|
+
| Mailpit (`mailpit`) | `MAIL_HOST`/`MAIL_PORT` (SMTP), web UI on `127.0.0.1:${MAILPIT_WEB_PORT:-8025}`. Development only | Nothing for `smtplib`; point your framework's mail settings at the variables |
|
|
213
|
+
| Meilisearch (`meilisearch`) | `MEILISEARCH_URL`/`MEILISEARCH_KEY` | `meilisearch` (or plain HTTP) |
|
|
214
|
+
| Garage / SeaweedFS / RustFS / Silo | `AWS_ENDPOINT`/`AWS_USE_PATH_STYLE_ENDPOINT`/`AWS_DEFAULT_REGION`/`AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY`/`AWS_BUCKET` | `boto3` with path-style addressing. Garage creates its bucket; with the others, create `AWS_BUCKET` once. Silo has two image variants — see [Silo on older CPUs](#silo-on-older-cpus) |
|
|
215
|
+
| Selenium (`selenium`) | A Chrome grid, `SELENIUM_REMOTE_URL`, `APP_URL`. Development only | `selenium` in your test dependencies |
|
|
216
|
+
| Playwright (`playwright`) | A browser server, `PLAYWRIGHT_WS_URL`, `APP_URL`. Development only | `playwright==1.64.1` — the client must match the server version |
|
|
217
|
+
| Node.js (`node`) | A Node container for `ship npm`, Vite's port published. Development only | See [Frontend dev server](#frontend-dev-server-vite-hmr) |
|
|
218
|
+
|
|
219
|
+
Connecting a Django app to the injected variables:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
import os
|
|
223
|
+
|
|
224
|
+
DATABASES = {"default": {
|
|
225
|
+
"ENGINE": "django.db.backends.postgresql",
|
|
226
|
+
"HOST": os.environ["DB_HOST"], "PORT": os.environ["DB_PORT"],
|
|
227
|
+
"NAME": os.environ["DB_NAME"], "USER": os.environ["DB_USER"],
|
|
228
|
+
"PASSWORD": os.environ["DB_PASSWORD"],
|
|
229
|
+
}}
|
|
230
|
+
CACHES = {"default": {"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
|
231
|
+
"LOCATION": os.environ["REDIS_URL"]}}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
A FastAPI or framework-free app passes the same values to its own clients:
|
|
235
|
+
`psycopg.connect(host=os.environ["DB_HOST"], ...)`,
|
|
236
|
+
`redis.from_url(os.environ["REDIS_URL"])`, or
|
|
237
|
+
`boto3.client("s3", endpoint_url=os.environ["AWS_ENDPOINT"], ...,
|
|
238
|
+
config=Config(s3={"addressing_style": "path"}))`. The
|
|
239
|
+
[Django](https://github.com/ship-ecosystem/python-ship/tree/main/tests/fixtures/django_app) and
|
|
240
|
+
[FastAPI](https://github.com/ship-ecosystem/python-ship/tree/main/tests/fixtures/fastapi_app)
|
|
241
|
+
fixtures the test suite runs are complete working examples.
|
|
242
|
+
|
|
243
|
+
Browser tests reach the app at `APP_URL` (`http://ship-app.test:8000`):
|
|
244
|
+
browsers force a single-label host such as `app` to HTTPS, so the app gets a
|
|
245
|
+
dotted alias whenever a testing service is selected.
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
import os
|
|
249
|
+
from playwright.sync_api import sync_playwright
|
|
250
|
+
|
|
251
|
+
with sync_playwright() as playwright:
|
|
252
|
+
browser = playwright.chromium.connect(os.environ["PLAYWRIGHT_WS_URL"])
|
|
253
|
+
page = browser.new_page()
|
|
254
|
+
page.goto(os.environ["APP_URL"])
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Every image carries an exact version tag, reviewed through Renovate:
|
|
258
|
+
|
|
259
|
+
| Service | Image |
|
|
260
|
+
|---|---|
|
|
261
|
+
| PostgreSQL | `postgres:17.12-alpine3.24` |
|
|
262
|
+
| MySQL | `mysql:9.7.4` |
|
|
263
|
+
| Redis | `redis:8.10.3-alpine3.23` |
|
|
264
|
+
| Mailpit | `axllent/mailpit:v1.31.1` |
|
|
265
|
+
| Meilisearch | `getmeili/meilisearch:v1.56.2` |
|
|
266
|
+
| Garage | `dxflrs/garage:v2.5.0` (built from `ship/garage/`) |
|
|
267
|
+
| SeaweedFS | `chrislusf/seaweedfs:4.46` |
|
|
268
|
+
| RustFS | `rustfs/rustfs:1.0.0` |
|
|
269
|
+
| Silo | `pgsty/silo:RELEASE.2026-09-16T00-00-00Z` |
|
|
270
|
+
| Selenium | `selenium/standalone-chrome:4.52.0-20261101` |
|
|
271
|
+
| Playwright | `mcr.microsoft.com/playwright:v1.64.1-noble` |
|
|
272
|
+
| Node.js | `node:24.18.0-alpine3.24` |
|
|
273
|
+
|
|
274
|
+
### Silo on older CPUs
|
|
275
|
+
|
|
276
|
+
Silo publishes two images of every release, and they don't run on the same
|
|
277
|
+
set of machines:
|
|
278
|
+
|
|
279
|
+
| `siloImage` | Image | What's in it |
|
|
280
|
+
|---|---|---|
|
|
281
|
+
| `standard` (default) | `pgsty/silo:<release>` | The server on a RHEL 9 base, with a shell and the usual tools. |
|
|
282
|
+
| `distroless` | `pgsty/silo:<release>-distroless` | The server binary only. No shell, so `ship shell silo` can't open one. |
|
|
283
|
+
|
|
284
|
+
RHEL 9 requires a CPU with the x86-64-v2 instruction set. On an older CPU —
|
|
285
|
+
or a virtual machine configured with a generic CPU model — the standard
|
|
286
|
+
image's container fails to start. `ship init` explains this and asks which
|
|
287
|
+
image to use whenever Silo is selected (`--silo-image` sets it
|
|
288
|
+
non-interactively), and records the answer in `ship.json`:
|
|
289
|
+
|
|
290
|
+
```json
|
|
291
|
+
"siloImage": "distroless"
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Pick `distroless` if *any* machine that will run the stack might be affected.
|
|
295
|
+
To check a Linux machine, run
|
|
296
|
+
`/lib64/ld-linux-x86-64.so.2 --help | grep x86-64-v2`; `x86-64-v2 (supported,
|
|
297
|
+
searched)` means the standard image runs there. Both images are the same Silo
|
|
298
|
+
release on the same data volume, so you can switch later.
|
|
299
|
+
|
|
300
|
+
## Configuration (`ship.json`)
|
|
301
|
+
|
|
302
|
+
`ship init` writes this file; you rarely need to edit it by hand. Its field
|
|
303
|
+
names match PHP Ship's `ship.json`, so a team using both reads one format:
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"framework": "django",
|
|
308
|
+
"app": "project.asgi:application",
|
|
309
|
+
"python": "3.13",
|
|
310
|
+
"services": {
|
|
311
|
+
"database": "postgres",
|
|
312
|
+
"cache": "redis"
|
|
313
|
+
},
|
|
314
|
+
"additionalServices": [
|
|
315
|
+
{"group": "database", "service": "mysql", "name": "analytics"}
|
|
316
|
+
],
|
|
317
|
+
"extensions": []
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
- `$schema` — the shared [ship.json schema](https://github.com/ship-ecosystem/python-ship/blob/main/schema/ship.schema.json),
|
|
322
|
+
written by `ship init` so editors validate and complete the file. PHP Ship
|
|
323
|
+
uses the same schema.
|
|
324
|
+
- `framework` — the adapter: `generic` (any ASGI or WSGI callable), `django`,
|
|
325
|
+
`fastapi`, `flask`, or a community adapter's key.
|
|
326
|
+
- `app` — the ASGI or WSGI target to serve, `module:callable`. A module
|
|
327
|
+
under `src/` works too.
|
|
328
|
+
- `python` — the Python branch built into the image (`ARG PYTHON_VERSION`).
|
|
329
|
+
Keep it a bare branch (`"3.13"`) so every build gets that branch's latest
|
|
330
|
+
patch release. See [Python security floor](#python-security-floor).
|
|
331
|
+
- `server` — the web server: `uvicorn`, `hypercorn` or `granian` for an ASGI
|
|
332
|
+
app; `gunicorn` or `granian` for a WSGI app; or a community server's key.
|
|
333
|
+
Omitted, Ship uses the one recommended for the app. See
|
|
334
|
+
[Web servers](#web-servers-asgi-and-wsgi).
|
|
335
|
+
- `services` — one selected service per group; a group without an entry
|
|
336
|
+
means "none". PostgreSQL is `postgres`; `pgsql`, PHP Ship's original name,
|
|
337
|
+
is accepted too (and in `additionalServices` and `serviceNames`), so a
|
|
338
|
+
`ship.json` written by either package reads the same in both.
|
|
339
|
+
- `additionalServices` — extra, named instances (a second database, a second
|
|
340
|
+
Redis, ...). See [Multiple instances of a service](#multiple-instances-of-a-service).
|
|
341
|
+
- `extensions` — entry point names of installed community adapters, services
|
|
342
|
+
and servers to load. See [Extending ship](#extending-ship).
|
|
343
|
+
- `serviceNames` / `externalNetwork` — rename Compose services and attach the
|
|
344
|
+
app to a pre-existing Docker network. See
|
|
345
|
+
[Custom service names and an external network](#custom-service-names-and-an-external-network).
|
|
346
|
+
- `name` — the Compose project name; defaults to the directory name. See
|
|
347
|
+
[Running more than one project at once](#running-more-than-one-project-at-once).
|
|
348
|
+
- `siloImage` — `"standard"` (default, omitted) or `"distroless"`. See
|
|
349
|
+
[Silo on older CPUs](#silo-on-older-cpus).
|
|
350
|
+
- `publishPorts` — defaults to `false`, so production publishes nothing to
|
|
351
|
+
the host. A reverse proxy on the project's Docker network reaches the app on
|
|
352
|
+
port 8000. Set it to `true` only when you intend to expose
|
|
353
|
+
`${APP_PORT:-8000}`; a Docker-published port bypasses most host firewalls.
|
|
354
|
+
Production only — development always publishes what it needs, on
|
|
355
|
+
`127.0.0.1`.
|
|
356
|
+
- `hostUser` — defaults to `true`. See [File ownership in dev](#file-ownership-in-dev).
|
|
357
|
+
- `deployCommands` — commands that run exactly once per deploy, **before**
|
|
358
|
+
the app starts — migrations, typically:
|
|
359
|
+
```json
|
|
360
|
+
"deployCommands": ["python manage.py migrate --noinput"]
|
|
361
|
+
```
|
|
362
|
+
`ship release` writes them into the release's `deploy-commands.sh` rather
|
|
363
|
+
than running them itself; that script starts the infrastructure services,
|
|
364
|
+
waits for them to be healthy, runs each command in a one-off app container,
|
|
365
|
+
and stops at the first failure. This is deliberately not where boot steps
|
|
366
|
+
live: those run at every container start (see
|
|
367
|
+
[Production releases](#production-releases)), which is exactly wrong for a
|
|
368
|
+
migration — several containers would run it at once. Ship never runs
|
|
369
|
+
migrations on its own.
|
|
370
|
+
- `processes` — extra long-running processes from the app's image: a worker,
|
|
371
|
+
a scheduler. Name → command:
|
|
372
|
+
```json
|
|
373
|
+
"processes": {
|
|
374
|
+
"worker": "celery -A project worker --loglevel=info",
|
|
375
|
+
"beat": "celery -A project beat"
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
Each becomes its own Compose service with the app's image, environment and
|
|
379
|
+
networks, no published ports, and a 60s stop grace period so a worker can
|
|
380
|
+
finish its job. They run in development too, against the same bind-mounted
|
|
381
|
+
code. Write each as a shell command, `$VAR` included — Ship escapes every
|
|
382
|
+
`$` so Compose doesn't blank out a variable meant for the container — or as
|
|
383
|
+
an argument list (`["python", "worker.py"]`) to skip the shell.
|
|
384
|
+
- `nodeAssets` — build npm assets into the production image. See
|
|
385
|
+
[Frontend dev server](#frontend-dev-server-vite-hmr).
|
|
386
|
+
- `djangoCollectstatic` — run `collectstatic` at every production boot
|
|
387
|
+
(Django only). The files stay in the container, so serve them from the app
|
|
388
|
+
(for example with WhiteNoise) or from a proxy that shares the volume.
|
|
389
|
+
|
|
390
|
+
Host-port collisions are handled with environment variables, not `ship.json`
|
|
391
|
+
— see [Running more than one project at once](#running-more-than-one-project-at-once).
|
|
392
|
+
|
|
393
|
+
### Adding a service later
|
|
394
|
+
|
|
395
|
+
Add the entry to `ship.json`'s `services` (e.g. `"cache": "redis"`) and run
|
|
396
|
+
`ship up` — it reads `ship.json` fresh every time. The exception is Garage,
|
|
397
|
+
which needs build files in `ship/garage/`; add that one by re-running
|
|
398
|
+
`ship init`.
|
|
399
|
+
|
|
400
|
+
Re-running `ship init` works for everything. Every prompt defaults to the
|
|
401
|
+
current selection, so pressing Enter keeps it; existing `additionalServices`
|
|
402
|
+
are kept, and every field it doesn't prompt for (`serviceNames`,
|
|
403
|
+
`externalNetwork`, `publishPorts`, `hostUser`, `processes`, `deployCommands`,
|
|
404
|
+
`name`, `extensions`, ...) carries over unchanged. It reads the old file
|
|
405
|
+
leniently, so one invalid field doesn't discard the rest.
|
|
406
|
+
|
|
407
|
+
Unlike PHP Ship, re-running `ship init` keeps your `ship/Dockerfile`: it is
|
|
408
|
+
yours to edit. `ship init --force` replaces it with the version matching the
|
|
409
|
+
installed python-ship — commit or back up your edits first. Ship records the
|
|
410
|
+
version that published the Dockerfile in `ship/.ship-version`, and `ship up`,
|
|
411
|
+
`ship init` and `ship config:test` warn when it differs from what's installed.
|
|
412
|
+
|
|
413
|
+
### Multiple instances of a service
|
|
414
|
+
|
|
415
|
+
`services` holds one selection per group. For a second database, a second
|
|
416
|
+
Redis kept apart from the default cache, or a second bucket store, add a
|
|
417
|
+
named instance:
|
|
418
|
+
|
|
419
|
+
```json
|
|
420
|
+
"additionalServices": [
|
|
421
|
+
{"group": "database", "service": "postgres", "name": "analytics"}
|
|
422
|
+
]
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
`ship init` offers these interactively ("Add a named additional service
|
|
426
|
+
instance?") and validates the name. By hand, `name` must be lowercase
|
|
427
|
+
letters, digits and underscores, starting with a letter (`analytics`,
|
|
428
|
+
`queue_2`). It becomes two things:
|
|
429
|
+
|
|
430
|
+
- The variables' prefix: `ANALYTICS_DB_HOST`, `ANALYTICS_DB_PASSWORD`, ...
|
|
431
|
+
instead of `DB_HOST`. Wire them into your settings like any second
|
|
432
|
+
connection — for Django, a second `DATABASES` entry.
|
|
433
|
+
- The Compose service: `postgres-analytics`, with its own volume
|
|
434
|
+
(`postgres-analytics_data`), and `ship db analytics` opens its shell.
|
|
435
|
+
|
|
436
|
+
Only `database`, `cache`, `storage`, `search` and `mail` support this; a
|
|
437
|
+
second browser driver or frontend toolchain isn't a coherent idea.
|
|
438
|
+
|
|
439
|
+
### Custom service names and an external network
|
|
440
|
+
|
|
441
|
+
Every Compose service has a fixed name by default: `app`, and each selected
|
|
442
|
+
service's key (`postgres`, `redis`, ...). Fine for one project on its own,
|
|
443
|
+
but projects that share a Docker network collide on those names. Hand-edit
|
|
444
|
+
`ship.json` when you need to:
|
|
445
|
+
|
|
446
|
+
```json
|
|
447
|
+
{
|
|
448
|
+
"serviceNames": {"app": "client-app", "postgres": "client-db"},
|
|
449
|
+
"externalNetwork": "shared_infra"
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
- `serviceNames` renames the app or a selected service. The hostname a
|
|
454
|
+
service injects follows the rename (`DB_HOST=client-db`), as do `ship shell`
|
|
455
|
+
with no argument, `ship db`, `ship manage` and Mutagen sync. Volumes keep
|
|
456
|
+
their original names, so renaming never orphans data. Commands where you
|
|
457
|
+
type the service (`ship exec`, `ship logs`, `ship shell <service>`) take the
|
|
458
|
+
new name. Additional instances already have distinct names and aren't
|
|
459
|
+
renamed.
|
|
460
|
+
- `externalNetwork` attaches the app (and every `processes` entry) to a
|
|
461
|
+
Docker network created outside Ship, next to the project's own network —
|
|
462
|
+
for reaching a database or cache that another Compose project runs. Point
|
|
463
|
+
your `.env` at that project's hostnames.
|
|
464
|
+
|
|
465
|
+
## Dependencies and `ship uv`
|
|
466
|
+
|
|
467
|
+
The Dockerfile installs your dependencies with uv, in this order:
|
|
468
|
+
|
|
469
|
+
| Project has | Image runs |
|
|
470
|
+
|---|---|
|
|
471
|
+
| `uv.lock` + `pyproject.toml` | `uv sync --locked --no-dev` |
|
|
472
|
+
| `requirements.txt` | `uv pip install -r requirements.txt` |
|
|
473
|
+
| `pyproject.toml` only | `uv sync --no-dev` |
|
|
474
|
+
| none of them | nothing — only the web server |
|
|
475
|
+
|
|
476
|
+
Then it installs the selected web server, so a framework-free app with no
|
|
477
|
+
manifest still runs. Dependencies live in `/opt/ship-venv`, outside the
|
|
478
|
+
bind-mounted `/app`, so the mount can't hide them.
|
|
479
|
+
|
|
480
|
+
`ship uv add httpx`, `ship uv lock` and other dependency-metadata commands
|
|
481
|
+
run uv and the project's Python in a temporary container with the project
|
|
482
|
+
mounted: `pyproject.toml` and `uv.lock` change on the host, and neither host
|
|
483
|
+
Python nor a host `.venv` is involved. Run `ship up` afterwards to rebuild
|
|
484
|
+
the image. `ship uv sync`, `run`, `pip`, `python`, `tool` and `venv` are
|
|
485
|
+
refused, since their effects would vanish with the container — use `ship up`
|
|
486
|
+
to install and `ship exec app ...` to run.
|
|
487
|
+
|
|
488
|
+
## Web servers: ASGI and WSGI
|
|
489
|
+
|
|
490
|
+
Each framework adapter knows whether the app is ASGI (async) or WSGI (sync),
|
|
491
|
+
and `ship init` only offers servers that can run it, recommended first:
|
|
492
|
+
|
|
493
|
+
| App | Interface | Servers (recommended first) |
|
|
494
|
+
|---|---|---|
|
|
495
|
+
| FastAPI, Starlette-style apps | ASGI | Uvicorn, Granian, Hypercorn |
|
|
496
|
+
| Django with `project.asgi:application` | ASGI | Uvicorn, Granian, Hypercorn |
|
|
497
|
+
| Django with `project.wsgi:application` | WSGI | Gunicorn, Granian |
|
|
498
|
+
| Flask | WSGI | Gunicorn, Granian |
|
|
499
|
+
| A plain callable | detected from its signature: `async def app(scope, receive, send)` is ASGI, `def app(environ, start_response)` WSGI | as above |
|
|
500
|
+
|
|
501
|
+
Pick one with `ship init --server granian` or `"server": "granian"` in
|
|
502
|
+
`ship.json`; without one, Ship uses the recommended server. A server that
|
|
503
|
+
can't run the app (Gunicorn for FastAPI, Uvicorn for Flask) is a
|
|
504
|
+
configuration error naming the ones that can. Ship installs the selected
|
|
505
|
+
server into the image, with reload in development. Granian serves both
|
|
506
|
+
interfaces and runs with `--interface asgi` or `--interface wsgi` to match.
|
|
507
|
+
A community package can add another server (see [Extending ship](#extending-ship)).
|
|
508
|
+
|
|
509
|
+
In production, every server reads its tuning from `.env.production`:
|
|
510
|
+
Uvicorn and Gunicorn take `WEB_CONCURRENCY` (worker processes) and
|
|
511
|
+
`FORWARDED_ALLOW_IPS` (which proxies to trust for `X-Forwarded-*`; set it to
|
|
512
|
+
your proxy's address); Granian takes `GRANIAN_WORKERS` and its other
|
|
513
|
+
`GRANIAN_*` settings. Uvicorn runs with `--proxy-headers`.
|
|
514
|
+
|
|
515
|
+
## Background tasks (Celery)
|
|
516
|
+
|
|
517
|
+
Select Celery with a broker:
|
|
518
|
+
|
|
519
|
+
```sh
|
|
520
|
+
ship init --cache redis --tasks celery # Redis as broker and result backend
|
|
521
|
+
ship init --broker rabbitmq --cache redis --tasks celery # RabbitMQ broker, Redis results
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
Ship adds two containers built from the app's own image, with its
|
|
525
|
+
environment, dependencies and (in development) code: `celery` runs a worker,
|
|
526
|
+
`celery-beat` runs the beat scheduler. The app and both containers receive:
|
|
527
|
+
|
|
528
|
+
| Variable | Value |
|
|
529
|
+
|---|---|
|
|
530
|
+
| `CELERY_BROKER_URL` | RabbitMQ when it is selected, otherwise Redis (database 1) |
|
|
531
|
+
| `CELERY_RESULT_BACKEND` | Redis (database 2) when it is selected, otherwise `rpc://` |
|
|
532
|
+
| `CELERY_APP` | What `celery -A` loads. Defaults to the Django project package (`project`) or the app's module (`main`); set it in `.env` when your Celery app lives elsewhere, such as `CELERY_APP=tasks` |
|
|
533
|
+
|
|
534
|
+
Your app declares `celery` (with `celery[redis]` for Redis) and builds its
|
|
535
|
+
Celery app from those variables:
|
|
536
|
+
|
|
537
|
+
```python
|
|
538
|
+
import os
|
|
539
|
+
from celery import Celery
|
|
540
|
+
|
|
541
|
+
celery = Celery("tasks", broker=os.environ["CELERY_BROKER_URL"], backend=os.environ["CELERY_RESULT_BACKEND"])
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
Django projects follow Celery's own Django guide; with
|
|
545
|
+
`app.config_from_object("django.conf:settings", namespace="CELERY")`, the
|
|
546
|
+
injected `CELERY_BROKER_URL` and `CELERY_RESULT_BACKEND` are picked up as
|
|
547
|
+
settings. Canvas works as usual (`chain`, `group`, `chord`); chords need a
|
|
548
|
+
real result backend, so select Redis. Set `CELERY_LOG_LEVEL` to change the
|
|
549
|
+
log level. In development the worker restarts on code changes when
|
|
550
|
+
`watchfiles` is installed; otherwise run `ship up` after changing tasks. The
|
|
551
|
+
worker and beat run in production too, and a release's `deploy-commands.sh`
|
|
552
|
+
starts the broker and database but not them.
|
|
553
|
+
|
|
554
|
+
## Production releases
|
|
555
|
+
|
|
556
|
+
Production is two commands, not a flag on `ship up`:
|
|
557
|
+
|
|
558
|
+
```sh
|
|
559
|
+
ship build # build every project-owned production image
|
|
560
|
+
ship release --tag 1.2.0 # build + assemble the portable release artifact
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
Both build a materially different image from `ship up`'s development one:
|
|
564
|
+
|
|
565
|
+
- **No bind mount.** The code is copied into the image at build time, through
|
|
566
|
+
the `builder` → `production` stages of `ship/Dockerfile`.
|
|
567
|
+
- **No build tools, not root.** The production stage carries the installed
|
|
568
|
+
app and server only: no uv, no pip, and it runs as UID 10001.
|
|
569
|
+
- **Framework boot steps run at container *boot*, not build time.** Django
|
|
570
|
+
gets `manage.py check --deploy` (and `collectstatic` with
|
|
571
|
+
`djangoCollectstatic`) before the server starts, because those steps need
|
|
572
|
+
the real environment, which only exists once the container starts.
|
|
573
|
+
`FrameworkAdapter.release_commands()` is the extension point for this.
|
|
574
|
+
- **Fresh base images.** Production builds always pull the base image
|
|
575
|
+
(`build.pull`), so a release never ships on a stale cached Python.
|
|
576
|
+
- **Development-only services disappear.** Mailpit, Selenium, Playwright and
|
|
577
|
+
Node are absent from the production model, along with their variables.
|
|
578
|
+
- **No override file.** `docker-compose.override.yml` is a development
|
|
579
|
+
convenience and never reaches a production image.
|
|
580
|
+
|
|
581
|
+
### Python security floor
|
|
582
|
+
|
|
583
|
+
Ship refuses to build on a Python release with known security
|
|
584
|
+
vulnerabilities. The current floor comes from the October 2026 expedited
|
|
585
|
+
security releases, which fixed the bundled pip certificate-chain problem,
|
|
586
|
+
tarfile link handling (CVE-2026-114583), and bundled Expat vulnerabilities
|
|
587
|
+
(CVE-2026-77214, CVE-2026-102633):
|
|
588
|
+
|
|
589
|
+
| Branch | Oldest release Ship builds on |
|
|
590
|
+
| --- | --- |
|
|
591
|
+
| 3.11 | 3.11.18 |
|
|
592
|
+
| 3.12 | 3.12.16 |
|
|
593
|
+
| 3.13 | 3.13.18 |
|
|
594
|
+
| 3.14 | 3.14.10 |
|
|
595
|
+
| 3.15 | 3.15.2 |
|
|
596
|
+
| 3.10 and older | none (end of life, no upstream fixes) |
|
|
597
|
+
|
|
598
|
+
It is enforced at three points:
|
|
599
|
+
|
|
600
|
+
- **`ship init`, `ship config:test` and every command that generates a
|
|
601
|
+
Compose file** reject an end-of-life `python` branch, or a pinned patch
|
|
602
|
+
release below the floor (`"3.13.4"`).
|
|
603
|
+
- **The Dockerfile's `base` stage** runs `ship/check-python-security-floor.py`
|
|
604
|
+
against the Python actually in the image, and fails the build if it is below
|
|
605
|
+
the floor. This catches a stale `python:3.13-slim` that Docker keeps reusing
|
|
606
|
+
from its local cache; the fix is in the message: `docker pull` that image.
|
|
607
|
+
- **`ship build`/`ship release` always pull fresh base images.** `ship up`
|
|
608
|
+
doesn't force a pull, so development still works offline.
|
|
609
|
+
|
|
610
|
+
The floor lives in `python_ship.security` and is raised whenever python.org
|
|
611
|
+
ships a security release.
|
|
612
|
+
|
|
613
|
+
### `.env.production`
|
|
614
|
+
|
|
615
|
+
A single project-level file, `.env.production`, is the one source of
|
|
616
|
+
production credentials and config — you create it; Ship never generates one.
|
|
617
|
+
`ship init` adds it to `.gitignore`. `ship build`/`ship release` make its
|
|
618
|
+
values available to `docker compose build`, and `ship release` copies the
|
|
619
|
+
whole file to the release's `.env`, read by the containers at boot.
|
|
620
|
+
`ship release` fails clearly if it doesn't exist.
|
|
621
|
+
|
|
622
|
+
Selected services' secrets (`DB_PASSWORD`, `DB_ROOT_PASSWORD`,
|
|
623
|
+
`MEILISEARCH_KEY`, `AWS_SECRET_ACCESS_KEY`, `GARAGE_RPC_SECRET`,
|
|
624
|
+
`GARAGE_ADMIN_TOKEN`, each with its instance prefix where one applies) are
|
|
625
|
+
*required* in production: Compose itself refuses to start without them, and
|
|
626
|
+
`ship config:test`/`ship build`/`ship release` check before Docker is invoked
|
|
627
|
+
— reporting a missing value, or one still set to a development default such
|
|
628
|
+
as `ship`. Non-secret settings (`DB_NAME`, `DB_USER`, `AWS_BUCKET`, ...) keep
|
|
629
|
+
their defaults unless you set them.
|
|
630
|
+
|
|
631
|
+
### What `ship release --tag` produces
|
|
632
|
+
|
|
633
|
+
```text
|
|
634
|
+
dist/ship/1.2.0/
|
|
635
|
+
├── docker-compose.yml # final images: tags, no build:, no source needed
|
|
636
|
+
├── .env # copied from .env.production (mode 0600)
|
|
637
|
+
├── images/
|
|
638
|
+
│ ├── app.tar # docker save — one per unique image, not per service
|
|
639
|
+
│ └── postgres.tar
|
|
640
|
+
├── release.json # tag, git commit, python-ship version, image digests — no secrets
|
|
641
|
+
├── deploy-commands.sh # only when deployCommands is set
|
|
642
|
+
└── README.md # the exact commands to deploy this release
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
`dist/ship/` is git-ignored, and excluded from the Docker build context along
|
|
646
|
+
with `.env`/`.env.*`, `.npmrc` and `auth.json`, so no earlier release or
|
|
647
|
+
secret can end up in an image; `ship build`/`ship release` re-apply those
|
|
648
|
+
rules as the last lines of `.dockerignore` every time. On POSIX the release
|
|
649
|
+
directory is owner-only; on Windows, restrict it with filesystem ACLs before
|
|
650
|
+
sharing it. Services that build from identical definitions (the app and every
|
|
651
|
+
`processes` entry) share one image and one archive. Infrastructure images are
|
|
652
|
+
archived too, so the server never needs registry access.
|
|
653
|
+
|
|
654
|
+
A deploy, once the folder is on a machine with nothing but Docker:
|
|
655
|
+
|
|
656
|
+
```sh
|
|
657
|
+
docker load -i images/app.tar
|
|
658
|
+
docker load -i images/postgres.tar
|
|
659
|
+
sh deploy-commands.sh # only present when deployCommands is set
|
|
660
|
+
docker compose up -d
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
Ship deliberately stops there — there's no `ship deploy` that SSHes anywhere.
|
|
664
|
+
Getting the folder onto the server is up to you; what Ship guarantees is that
|
|
665
|
+
the artifact needs nothing else once it's there.
|
|
666
|
+
|
|
667
|
+
### CI/CD
|
|
668
|
+
|
|
669
|
+
The same commands, the same artifact:
|
|
670
|
+
|
|
671
|
+
```yaml
|
|
672
|
+
- run: uv tool install python-ship
|
|
673
|
+
- run: ship release --tag ${{ github.ref_name }}
|
|
674
|
+
- run: # upload dist/ship/${{ github.ref_name }} however your pipeline deploys
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
`ship release` fails immediately without `--tag` when it isn't attached to a
|
|
678
|
+
terminal, instead of prompting and hanging the pipeline.
|
|
679
|
+
|
|
680
|
+
## HTTPS / TLS
|
|
681
|
+
|
|
682
|
+
The app listens on plain HTTP on port 8000; Ship doesn't terminate TLS. Put a
|
|
683
|
+
TLS-terminating reverse proxy in front — one you already run (a load
|
|
684
|
+
balancer, Cloudflare, Caddy, Traefik, nginx) or one you add through the
|
|
685
|
+
override file. A proxy on the host can use `publishPorts: true`; for example,
|
|
686
|
+
with `APP_PORT=8000` in `.env.production` and DNS pointing at the host, this
|
|
687
|
+
Caddyfile serves the release over HTTPS:
|
|
688
|
+
|
|
689
|
+
```caddyfile
|
|
690
|
+
example.com {
|
|
691
|
+
reverse_proxy 127.0.0.1:8000
|
|
692
|
+
}
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
Allow public traffic only to the proxy's ports, set `FORWARDED_ALLOW_IPS` so
|
|
696
|
+
the app trusts the proxy's forwarded scheme and client address, and configure
|
|
697
|
+
your framework's trusted hosts, secure cookies and HTTPS redirects. Serving
|
|
698
|
+
the bare published port to the internet means serving plain HTTP.
|
|
699
|
+
|
|
700
|
+
## Backing up data volumes
|
|
701
|
+
|
|
702
|
+
Every stateful service (PostgreSQL, MySQL, Redis, Meilisearch, the S3 stores)
|
|
703
|
+
keeps its data in a named Docker volume; `docker volume ls` lists them. A
|
|
704
|
+
release contains images and configuration, **not** that data. Ship doesn't
|
|
705
|
+
back volumes up; use your database's own tools, from the release directory:
|
|
706
|
+
|
|
707
|
+
```sh
|
|
708
|
+
docker compose exec -T postgres sh -c 'exec pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc' > postgres.dump
|
|
709
|
+
docker compose exec -T postgres sh -c 'exec pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --no-owner' < postgres.dump
|
|
710
|
+
|
|
711
|
+
docker compose exec -T mysql sh -c 'exec mysqldump -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE"' > mysql.sql
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
For Redis, Meilisearch and storage, use their snapshot procedures, or stop the
|
|
715
|
+
service and archive its volumes together (Garage has a data and a metadata
|
|
716
|
+
volume):
|
|
717
|
+
|
|
718
|
+
```sh
|
|
719
|
+
docker run --rm -v <project>_redis_data:/data -v "$PWD":/backup alpine tar czf /backup/redis-data.tar.gz -C /data .
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
Restore into fresh volumes with the same service version, and test a full
|
|
723
|
+
restore on a separate host. `ship down --volumes` deletes development volumes;
|
|
724
|
+
it is not a backup.
|
|
725
|
+
|
|
726
|
+
## Frontend dev server (Vite HMR)
|
|
727
|
+
|
|
728
|
+
Select `--frontend node`, then `ship npm install` and `ship npm run dev`. The
|
|
729
|
+
Node container publishes `${VITE_PORT:-5173}` on `127.0.0.1` — the same port
|
|
730
|
+
inside and outside — but Vite binds the container's loopback by default, which
|
|
731
|
+
the published port can't reach. Add this to `vite.config.js` (`ship init`
|
|
732
|
+
prints it whenever Vite is installed and the config doesn't bind a host yet):
|
|
733
|
+
|
|
734
|
+
```js
|
|
735
|
+
const port = Number(process.env.VITE_PORT ?? 5173);
|
|
736
|
+
|
|
737
|
+
export default defineConfig({
|
|
738
|
+
server: {
|
|
739
|
+
host: '0.0.0.0', // bind inside the container, not just its loopback
|
|
740
|
+
port, // the port Ship publishes on the host
|
|
741
|
+
strictPort: true, // fail fast instead of silently picking an unpublished port
|
|
742
|
+
origin: `http://localhost:${port}`, // asset URLs for pages your Python app renders
|
|
743
|
+
},
|
|
744
|
+
});
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
That is all HMR needs. Vite's browser client opens its WebSocket to the host
|
|
748
|
+
and port it was loaded from, so open the dev server at
|
|
749
|
+
`http://localhost:5173`, or load `http://localhost:5173/@vite/client` and your
|
|
750
|
+
entry module from a template your app renders (as django-vite does). Vite allows `localhost` origins by default, so a page on
|
|
751
|
+
`APP_PORT` can load its modules cross-origin, and `origin` makes imported
|
|
752
|
+
assets resolve against Vite rather than your app. Leave out `hmr.host`: the
|
|
753
|
+
browser then reconnects to wherever the client came from.
|
|
754
|
+
|
|
755
|
+
File changes reach Vite's watcher directly on Linux and macOS. Docker Desktop
|
|
756
|
+
doesn't forward file events from Windows folders, so on Windows Ship sets
|
|
757
|
+
`CHOKIDAR_USEPOLLING=true` for the Node container. Under
|
|
758
|
+
[Mutagen](#faster-file-sync-on-windowsmacos-mutagen) the Node container gets
|
|
759
|
+
its own sync session instead, so events are native and polling is off.
|
|
760
|
+
|
|
761
|
+
Set `VITE_PORT` in `.env` to move both sides at once. Node isn't part of the
|
|
762
|
+
production stack. To compile assets into the production image, set
|
|
763
|
+
`nodeAssets` (`ship init --node-assets`), commit `package-lock.json`, and give
|
|
764
|
+
`package.json` a `build` script that writes to `dist/`: the Dockerfile builds
|
|
765
|
+
them in a separate Node stage and copies `dist/` into the Python image, so
|
|
766
|
+
Node never reaches the runtime.
|
|
767
|
+
|
|
768
|
+
## File ownership in dev
|
|
769
|
+
|
|
770
|
+
On Linux, the development app runs as your own UID and GID (`hostUser`,
|
|
771
|
+
default `true`), so files the container writes into the bind-mounted project —
|
|
772
|
+
migrations, collected static files, a `uv.lock` — stay yours. Set
|
|
773
|
+
`"hostUser": false` to use the image's default user instead. On macOS and
|
|
774
|
+
Windows, Docker Desktop maps bind-mount ownership itself, and under
|
|
775
|
+
`SHIP_MUTAGEN` there's no bind mount, so the setting does nothing there.
|
|
776
|
+
Production is unaffected either way: it always runs as UID 10001.
|
|
777
|
+
|
|
778
|
+
## Debugging (debugpy)
|
|
779
|
+
|
|
780
|
+
The development app can reach your IDE at `host.docker.internal` on every
|
|
781
|
+
platform. To attach a debugger to the app instead, add `debugpy` to your
|
|
782
|
+
development dependencies, publish its port with an override file, and start
|
|
783
|
+
the server under it:
|
|
784
|
+
|
|
785
|
+
```yaml
|
|
786
|
+
# docker-compose.override.yml
|
|
787
|
+
services:
|
|
788
|
+
app:
|
|
789
|
+
ports:
|
|
790
|
+
- "127.0.0.1:5678:5678"
|
|
791
|
+
command: ["python", "-m", "debugpy", "--listen", "0.0.0.0:5678",
|
|
792
|
+
"-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
Then attach your IDE to `localhost:5678`. Remove the override to go back to
|
|
796
|
+
the plain server.
|
|
797
|
+
|
|
798
|
+
## Faster file sync on Windows/macOS (Mutagen)
|
|
799
|
+
|
|
800
|
+
Docker Desktop's file-sharing layer makes bind mounts noticeably slower on
|
|
801
|
+
Windows and macOS than on Linux. [Mutagen](https://mutagen.io/) syncs the
|
|
802
|
+
project into the containers instead. It's opt-in and a per-machine choice —
|
|
803
|
+
pointless on Linux — so it's an environment variable, not a `ship.json` field:
|
|
804
|
+
|
|
805
|
+
```sh
|
|
806
|
+
SHIP_MUTAGEN=1 ship up
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
`ship up` creates a sync session for every container that mounts the project
|
|
810
|
+
(the app, each `processes` entry and Celery container, and the Node frontend)
|
|
811
|
+
after the stack starts, and waits for the first sync before reporting success;
|
|
812
|
+
`ship down` terminates them. Requires the [Mutagen CLI](https://mutagen.io/documentation/introduction/installation/)
|
|
813
|
+
on `PATH`. Virtual environments, `node_modules`, caches, build output, `.env`
|
|
814
|
+
files and VCS data are excluded — dependencies are installed into the image,
|
|
815
|
+
so run `ship up` again after changing them. Never applies in production.
|
|
816
|
+
|
|
817
|
+
## Running more than one project at once
|
|
818
|
+
|
|
819
|
+
Every generated Compose file carries a top-level `name:` (`ship.json`'s
|
|
820
|
+
`name`, or the sanitized directory name), which scopes networks and volumes,
|
|
821
|
+
and production uses `<name>-production`. Set `name` explicitly when it must
|
|
822
|
+
stay the same wherever the project is checked out.
|
|
823
|
+
|
|
824
|
+
Every published port has a variable, read from your shell or the project's
|
|
825
|
+
`.env`:
|
|
826
|
+
|
|
827
|
+
| Port | Variable | Default |
|
|
828
|
+
|---|---|---|
|
|
829
|
+
| App | `APP_PORT` | `8000` |
|
|
830
|
+
| Vite dev server | `VITE_PORT` | `5173` |
|
|
831
|
+
| Mailpit web UI | `MAILPIT_WEB_PORT` | `8025` |
|
|
832
|
+
| Silo console | `SILO_CONSOLE_PORT` | `9001` |
|
|
833
|
+
|
|
834
|
+
```sh
|
|
835
|
+
APP_PORT=8001 VITE_PORT=5174 ship up
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
Every one binds to `127.0.0.1` in development. Production publishes nothing
|
|
839
|
+
unless `publishPorts` is set, and then only the app on `${APP_PORT:-8000}`.
|
|
840
|
+
|
|
841
|
+
## Customizing the stack
|
|
842
|
+
|
|
843
|
+
`ship/docker-compose.generated.yml` is regenerated from `ship.json` by every
|
|
844
|
+
command, so editing it doesn't stick. Add a `docker-compose.override.yml`
|
|
845
|
+
(`compose.override.yaml` works too) at the project root instead — Compose's
|
|
846
|
+
own [merge rules](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/)
|
|
847
|
+
apply, and every development command picks it up:
|
|
848
|
+
|
|
849
|
+
```yaml
|
|
850
|
+
# docker-compose.override.yml
|
|
851
|
+
services:
|
|
852
|
+
adminer:
|
|
853
|
+
image: adminer:5
|
|
854
|
+
ports:
|
|
855
|
+
- "127.0.0.1:8099:8080"
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
Key overrides by the *renamed* service when you use `serviceNames`. The
|
|
859
|
+
override never applies to `ship build`/`ship release`. For the image itself,
|
|
860
|
+
edit `ship/Dockerfile` directly — `ship init` keeps your edits unless you pass
|
|
861
|
+
`--force`.
|
|
862
|
+
|
|
863
|
+
## Extending ship
|
|
864
|
+
|
|
865
|
+
Third-party packages add services, framework adapters and web servers
|
|
866
|
+
without forking Ship. A package registers a Python entry point:
|
|
867
|
+
|
|
868
|
+
```toml
|
|
869
|
+
[project.entry-points."python_ship.services"]
|
|
870
|
+
rabbitmq = "ship_rabbitmq:RabbitMQService"
|
|
871
|
+
|
|
872
|
+
[project.entry-points."python_ship.adapters"]
|
|
873
|
+
flask = "ship_flask:FlaskAdapter"
|
|
874
|
+
|
|
875
|
+
[project.entry-points."python_ship.servers"]
|
|
876
|
+
granian = "ship_granian:GranianServer"
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
Install it next to the `ship` command (`uv tool install python-ship --with
|
|
880
|
+
ship-rabbitmq`) and select it by entry point name:
|
|
881
|
+
|
|
882
|
+
```json
|
|
883
|
+
{
|
|
884
|
+
"extensions": ["rabbitmq"],
|
|
885
|
+
"services": {"queue": "rabbitmq"}
|
|
886
|
+
}
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
Nothing loads unless `extensions` names it. A missing, duplicate or broken
|
|
890
|
+
extension is a configuration error naming the extension. The contracts —
|
|
891
|
+
`ServiceDefinition`, `FrameworkAdapter`, `WebServer`, and the optional
|
|
892
|
+
`ProvidesDatabaseShell`/`ValidatesConfiguration` — are typed protocols in
|
|
893
|
+
[`python_ship.contracts`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/contracts.py).
|
|
894
|
+
See [`docs/adding-a-service.md`](https://github.com/ship-ecosystem/python-ship/blob/main/docs/adding-a-service.md)
|
|
895
|
+
for a worked example, and the installable
|
|
896
|
+
[service](https://github.com/ship-ecosystem/python-ship/tree/main/examples/community-service) and
|
|
897
|
+
[adapter](https://github.com/ship-ecosystem/python-ship/tree/main/examples/community-adapter) examples.
|
|
898
|
+
|
|
899
|
+
## Architecture
|
|
900
|
+
|
|
901
|
+
- [`contracts.py`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/contracts.py) —
|
|
902
|
+
the public extension points and the `ServiceContext` each service receives.
|
|
903
|
+
- [`compose.py`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/compose.py) —
|
|
904
|
+
merges selected services' fragments into the development and production
|
|
905
|
+
Compose models. Fragments merge rather than overwrite; a real conflict is
|
|
906
|
+
an error, not a silent winner.
|
|
907
|
+
- [`config.py`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/config.py) —
|
|
908
|
+
reads and validates `ship.json`, reporting every problem at once.
|
|
909
|
+
- [`plugins.py`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/plugins.py) —
|
|
910
|
+
resolves `extensions` into adapters, services and servers.
|
|
911
|
+
- [`release.py`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/release.py) —
|
|
912
|
+
plans unique images and assembles the release artifact.
|
|
913
|
+
- [`templates/Dockerfile`](https://github.com/ship-ecosystem/python-ship/blob/main/src/python_ship/templates/Dockerfile) —
|
|
914
|
+
multi-stage: `base` (with the security check), `builder`, `production` and
|
|
915
|
+
`development`, plus an `assets` stage with `nodeAssets`.
|
|
916
|
+
|
|
917
|
+
## Contributing
|
|
918
|
+
|
|
919
|
+
See [`docs/adding-a-service.md`](https://github.com/ship-ecosystem/python-ship/blob/main/docs/adding-a-service.md)
|
|
920
|
+
for adding a service or adapter, and
|
|
921
|
+
[`docs/roadmap.md`](https://github.com/ship-ecosystem/python-ship/blob/main/docs/roadmap.md)
|
|
922
|
+
for what's built and what's planned.
|
|
923
|
+
|
|
924
|
+
```sh
|
|
925
|
+
python scripts/check_local.py # Ruff, mypy, unit tests, then build and smoke-test both distributions
|
|
926
|
+
SHIP_DOCKER_TEST=1 python -m unittest tests.test_docker_development tests.test_docker_services
|
|
927
|
+
SHIP_PRODUCTION_DOCKER_TEST=1 python -m unittest tests.test_docker_production
|
|
928
|
+
SHIP_RELEASE_DOCKER_TEST=1 python -m unittest tests.test_docker_release
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
The Docker suites create and remove their own containers, volumes, networks
|
|
932
|
+
and images. Maintainers publish with [`docs/releasing.md`](https://github.com/ship-ecosystem/python-ship/blob/main/docs/releasing.md).
|
|
933
|
+
|
|
934
|
+
## License
|
|
935
|
+
|
|
936
|
+
MIT. See [`LICENSE.md`](https://github.com/ship-ecosystem/python-ship/blob/main/LICENSE.md).
|