106 lines
3.8 KiB
Markdown
106 lines
3.8 KiB
Markdown
# Production deployment: `warehouse-allocation.mvphub.ir`
|
|
|
|
## Runtime layout
|
|
|
|
| Item | Value |
|
|
|---|---|
|
|
| Public URL | `https://warehouse-allocation.mvphub.ir` |
|
|
| Release root | `/srv/apps/warehouse-allocation` |
|
|
| Shared environment | `/srv/apps/warehouse-allocation/shared/.env` |
|
|
| Compose project | `warehouse-allocation` |
|
|
| Blue slot | `127.0.0.1:18081` |
|
|
| Green slot | `127.0.0.1:18082` |
|
|
| Shared Redis | `warehouse-allocation-redis-1`, no host port |
|
|
| Nginx upstream | `/etc/nginx/conf.d/10-warehouse-allocation-upstream.conf` |
|
|
| Restricted account | `warehouse-deploy` |
|
|
| Deployment program | `/usr/local/sbin/warehouse-allocation-deploy` |
|
|
|
|
Only one API slot receives traffic after a deployment. During cutover both slots
|
|
run briefly, allowing Nginx to switch without an API interruption. Redis and its
|
|
named volume remain shared between releases.
|
|
|
|
## GitLab pipeline
|
|
|
|
The authoritative pipeline is [`.gitlab-ci.yml`](../.gitlab-ci.yml). It runs
|
|
quality checks, tests with a real Redis service, coverage, optional SonarQube,
|
|
container build validation, release packaging, and automatic protected-`main`
|
|
deployment.
|
|
|
|
Required protected GitLab variables:
|
|
|
|
| Variable | Type/value |
|
|
|---|---|
|
|
| `DEPLOY_HOST` | `188.137.233.91` |
|
|
| `DEPLOY_PORT` | `22` |
|
|
| `DEPLOY_USER` | `warehouse-deploy` |
|
|
| `DEPLOY_SSH_PRIVATE_KEY` | File variable containing the dedicated private key |
|
|
| `DEPLOY_KNOWN_HOSTS` | File variable containing the pinned server host key |
|
|
|
|
Optional SonarQube variables are `SONAR_HOST_URL` and masked `SONAR_TOKEN`. If both
|
|
exist, the quality gate becomes mandatory for deployment.
|
|
|
|
The CI account has no Docker-group membership and no general sudo access. It may
|
|
invoke only the root-owned deployment program through `/etc/sudoers.d`.
|
|
|
|
## Deployment transaction
|
|
|
|
The deploy job uploads:
|
|
|
|
```text
|
|
/home/warehouse-deploy/incoming/release-<40-character-commit-sha>.tar.gz
|
|
```
|
|
|
|
It then invokes:
|
|
|
|
```bash
|
|
sudo /usr/local/sbin/warehouse-allocation-deploy <commit-sha> <sha256>
|
|
```
|
|
|
|
The program:
|
|
|
|
1. serializes deployments with `flock`;
|
|
2. validates the commit ID, checksum, and archive paths;
|
|
3. extracts an immutable release;
|
|
4. builds an exact commit-tagged image while the old slot serves traffic;
|
|
5. starts and checks the inactive slot;
|
|
6. switches only the warehouse-allocation Nginx upstream;
|
|
7. runs public health, OpenAPI, and exact Swagger-example tests twice;
|
|
8. commits the active-slot metadata and removes the old API container;
|
|
9. retains five recent releases and application images.
|
|
|
|
If any step before commit fails, the upstream is restored, Nginx is reloaded,
|
|
the failed candidate is removed, and the previous release remains current.
|
|
|
|
## Status and logs
|
|
|
|
```bash
|
|
ssh ict
|
|
|
|
source /srv/apps/warehouse-allocation/shared/.env
|
|
echo "$ACTIVE_SLOT"
|
|
readlink -f /srv/apps/warehouse-allocation/current
|
|
|
|
docker ps --filter name=warehouse-allocation
|
|
docker logs --tail 100 warehouse-allocation-api-blue-1
|
|
docker logs --tail 100 warehouse-allocation-api-green-1
|
|
docker logs --tail 100 warehouse-allocation-redis-1
|
|
|
|
curl -fsS https://warehouse-allocation.mvphub.ir/health/ready
|
|
nginx -t
|
|
```
|
|
|
|
Do not print or commit the shared `.env`; it contains the inventory administration
|
|
token. Do not use the root development `compose.yaml` for production.
|
|
|
|
## Manual rollback
|
|
|
|
Normal failures roll back automatically before the old slot is stopped. For a
|
|
post-deployment application regression, redeploy the desired older commit
|
|
artifact through the same deployment program. This performs the same health,
|
|
traffic-switch, and rollback protections instead of manually editing Nginx.
|
|
|
|
The deployment program is scoped to warehouse-allocation release directories,
|
|
images, two API containers, and its dedicated upstream file. It never prunes or
|
|
restarts bank-flow containers, unrelated images, Nginx sites, certificates, or
|
|
volumes.
|