implement deploy services
This commit is contained in:
6 files changed
+266
No files matched your search
@@ -0,0 +1,119 @@
|
||||
# Production deployment: `warehouse-allocation.mvphub.ir`
|
||||
|
||||
## Current layout
|
||||
|
||||
| Item | Value |
|
||||
|---|---|
|
||||
| SSH host | `ict` |
|
||||
| Public URL | `https://warehouse-allocation.mvphub.ir` |
|
||||
| Release root | `/srv/apps/warehouse-allocation` |
|
||||
| Current release | `/srv/apps/warehouse-allocation/current` |
|
||||
| Shared environment | `/srv/apps/warehouse-allocation/shared/.env` |
|
||||
| Compose project | `warehouse-allocation` |
|
||||
| API loopback address | `127.0.0.1:18081` |
|
||||
| Nginx site | `/etc/nginx/sites-available/warehouse-allocation.mvphub.ir` |
|
||||
| Certificate | `/etc/letsencrypt/live/warehouse-allocation.mvphub.ir` |
|
||||
| ACME webroot | `/var/www/letsencrypt` |
|
||||
|
||||
The API and Redis belong to a dedicated Compose project. Redis has no host port, and
|
||||
the API port is bound only to loopback. Public traffic can reach it only through
|
||||
the hostname-specific Nginx reverse proxy.
|
||||
|
||||
## Status and logs
|
||||
|
||||
```bash
|
||||
ssh ict
|
||||
|
||||
docker compose \
|
||||
--env-file /srv/apps/warehouse-allocation/shared/.env \
|
||||
-f /srv/apps/warehouse-allocation/current/deploy/compose.server.yaml \
|
||||
ps
|
||||
|
||||
docker logs --tail 100 warehouse-allocation-api-1
|
||||
docker logs --tail 100 warehouse-allocation-redis-1
|
||||
|
||||
curl -fsS http://127.0.0.1:18081/health/ready
|
||||
curl -fsS https://warehouse-allocation.mvphub.ir/health/ready
|
||||
nginx -t
|
||||
```
|
||||
|
||||
Do not print or commit `/srv/apps/warehouse-allocation/shared/.env`. It contains the
|
||||
inventory administration token.
|
||||
|
||||
## Starting or reconciling the current release
|
||||
|
||||
```bash
|
||||
docker compose \
|
||||
--env-file /srv/apps/warehouse-allocation/shared/.env \
|
||||
-f /srv/apps/warehouse-allocation/current/deploy/compose.server.yaml \
|
||||
up -d --build
|
||||
```
|
||||
|
||||
The production Compose file is
|
||||
[`compose.server.yaml`](compose.server.yaml). It must be used instead of the local
|
||||
root `compose.yaml`, because it provides the isolated loopback port, restart
|
||||
policy, resource limits, persistent Redis volume, and production environment.
|
||||
|
||||
## Safe release process
|
||||
|
||||
1. Run tests and quality checks locally.
|
||||
2. Package tracked and required untracked source files without `.env`, `.git`, or
|
||||
virtual environments.
|
||||
3. Upload the archive to the server and verify its SHA-256 checksum.
|
||||
4. Extract it into a new immutable directory under
|
||||
`/srv/apps/warehouse-allocation/releases/<release-id>`.
|
||||
5. Validate the new Compose file using the shared environment.
|
||||
6. Point `/srv/apps/warehouse-allocation/current` at the new release.
|
||||
7. Run Compose with `up -d --build`.
|
||||
8. Wait for both containers to become healthy.
|
||||
9. Verify loopback health, public HTTPS health, OpenAPI, and one allocation smoke
|
||||
test.
|
||||
|
||||
Never modify another application's Compose project, loopback port, Nginx site, or
|
||||
volume as part of this release.
|
||||
|
||||
## Nginx and TLS
|
||||
|
||||
The repository contains:
|
||||
|
||||
- [`nginx/warehouse-allocation.bootstrap.conf`](nginx/warehouse-allocation.bootstrap.conf)
|
||||
for initial HTTP/ACME validation;
|
||||
- [`nginx/warehouse-allocation.mvphub.ir.conf`](nginx/warehouse-allocation.mvphub.ir.conf)
|
||||
for the final HTTP-to-HTTPS redirect and reverse proxy.
|
||||
|
||||
Always run `nginx -t` before `systemctl reload nginx`. A reload is graceful and
|
||||
must only happen after the full server configuration passes validation.
|
||||
|
||||
The certificate uses Certbot's webroot authenticator. The existing
|
||||
`certbot.timer` renews it automatically.
|
||||
|
||||
## Rollback
|
||||
|
||||
Identify the prior release first:
|
||||
|
||||
```bash
|
||||
find /srv/apps/warehouse-allocation/releases -mindepth 1 -maxdepth 1 -type d -print
|
||||
readlink -f /srv/apps/warehouse-allocation/current
|
||||
```
|
||||
|
||||
Point `current` at the explicit prior release, validate Compose, and start it:
|
||||
|
||||
```bash
|
||||
ln -sfn /srv/apps/warehouse-allocation/releases/<prior-release-id> \
|
||||
/srv/apps/warehouse-allocation/current
|
||||
|
||||
docker compose \
|
||||
--env-file /srv/apps/warehouse-allocation/shared/.env \
|
||||
-f /srv/apps/warehouse-allocation/current/deploy/compose.server.yaml \
|
||||
config --quiet
|
||||
|
||||
docker compose \
|
||||
--env-file /srv/apps/warehouse-allocation/shared/.env \
|
||||
-f /srv/apps/warehouse-allocation/current/deploy/compose.server.yaml \
|
||||
up -d --build
|
||||
```
|
||||
|
||||
Then verify `/health/ready` on loopback and HTTPS. The Redis volume is deliberately
|
||||
shared between releases, so rolling application code back does not discard
|
||||
inventory data.
|
||||
|
||||
Reference in new issue
Block a user