auto deploy on production server now finalized ready for smoke test.
This commit is contained in:
@@ -1,13 +1,84 @@
|
||||
# Dyolink — Production Server Deploy Guide
|
||||
|
||||
Deploy the full stack (Postgres, NestJS API, Next.js, Nginx, Let's Encrypt) on a fresh Linux server using **Docker Hub** images.
|
||||
Linux VPS serves **`https://nudentic.ir` only**. Images come from the **Gitea registry** (`wixur.ir:3000`) on git tags. Staging is Windows (`https://wixur.ir`) — see [`STAGING-DEPLOY.md`](STAGING-DEPLOY.md).
|
||||
|
||||
**Example used in production:** `https://wixur.ir` on server `185.243.48.140`.
|
||||
**Automated path:** tag `v1.0.1` → [`.gitea/workflows/prod-tag-deploy.yml`](../.gitea/workflows/prod-tag-deploy.yml) (Windows runner builds, SSH to this server).
|
||||
|
||||
**Manual / first SSL:** Docker Hub + [`scripts/build-and-push-prod.sh`](scripts/build-and-push-prod.sh) is still documented below as a fallback.
|
||||
|
||||
**Example host:** `https://nudentic.ir` (do not point `wixur.ir` at this VPS).
|
||||
|
||||
---
|
||||
|
||||
## Automated deploy (Gitea tags)
|
||||
|
||||
```
|
||||
git tag v1.0.1 && git push origin v1.0.1
|
||||
↓
|
||||
Windows act_runner builds frontend with https://nudentic.ir
|
||||
↓
|
||||
Push wixur.ir:3000/<owner>/dyolink-*:v1.0.1 (never :latest)
|
||||
↓
|
||||
SSH → Linux docker login wixur.ir:3000 → compose pull + up
|
||||
↓
|
||||
https://nudentic.ir
|
||||
```
|
||||
|
||||
`:latest` is **staging only** (wixur.ir baked in). Production compose must pin `TAG=v1.0.1`.
|
||||
|
||||
### One-time on the Linux server
|
||||
|
||||
1. **HTTP registry** — Gitea is `http://wixur.ir:3000`. In `/etc/docker/daemon.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"insecure-registries": ["wixur.ir:3000"]
|
||||
}
|
||||
```
|
||||
|
||||
Then `sudo systemctl restart docker` (containers restart).
|
||||
|
||||
2. **`.env`** in `/opt/dyolink/infrastructure/` — from [`deploy.prod.env.example`](deploy.prod.env.example):
|
||||
|
||||
- `DOMAIN=nudentic.ir`
|
||||
- `REGISTRY_PREFIX=wixur.ir:3000/<gitea-owner>` (same owner as Gitea `REGISTRY_OWNER`)
|
||||
- `TAG=v1.0.1` (CI overrides per release)
|
||||
|
||||
3. **`secrets/backend.env`:** `FRONTEND_URL=https://nudentic.ir`, `COOKIE_SECURE=true`
|
||||
|
||||
4. **SSH** — user that can run `docker` (e.g. `dyolink` in the `docker` group). Put the matching **public** key in `~/.ssh/authorized_keys`.
|
||||
|
||||
5. **Test pull** (after a staging or prod image exists):
|
||||
|
||||
```bash
|
||||
docker login wixur.ir:3000 -u <gitea-user>
|
||||
docker pull wixur.ir:3000/<owner>/dyolink-backend:<sha-or-tag>
|
||||
```
|
||||
|
||||
### Gitea (same repo as staging)
|
||||
|
||||
**Variables:** `PROD_PUBLIC_BASE_URL=https://nudentic.ir`, `PROD_REGISTRY_HOST=wixur.ir:3000`, `PROD_INFRA_DIR=/opt/dyolink/infrastructure`, plus existing `REGISTRY_HOST` / `REGISTRY_OWNER` / `CLONE_HOST`.
|
||||
|
||||
**Secrets:** `PROD_SSH_HOST`, `PROD_SSH_USER`, `PROD_SSH_KEY` (private key). Reuse `REGISTRY_USERNAME` / `REGISTRY_PASSWORD`. Optional `PROD_SSH_PORT` (default 22).
|
||||
|
||||
OpenSSH must be on the Windows runner (`ssh.exe` / `scp.exe`).
|
||||
|
||||
### Release
|
||||
|
||||
```bash
|
||||
git tag v1.0.1
|
||||
git push origin v1.0.1
|
||||
```
|
||||
|
||||
Or Gitea → Actions → **Production — tag build, push, deploy** → Run → tag `v1.0.1`.
|
||||
|
||||
Check `https://nudentic.ir/api/health`.
|
||||
|
||||
---
|
||||
|
||||
## Architecture
|
||||
|
||||
|
||||
```
|
||||
Internet → Nginx (:80 / :443)
|
||||
├── / → frontend:3000 (Next.js)
|
||||
@@ -18,8 +89,8 @@ Internet → Nginx (:80 / :443)
|
||||
| Service | Image | Notes |
|
||||
|-----------|------------------------------------|--------------------------------|
|
||||
| postgres | `postgres:15-alpine` | Data in Docker volume |
|
||||
| backend | `dyolink/dyolink-backend:latest` | Runs migrations + seed on start |
|
||||
| frontend | `dyolink/dyolink-frontend:latest` | URLs baked in at **build time** |
|
||||
| backend | `REGISTRY_PREFIX/dyolink-backend:TAG` | Gitea `v*` or Hub `dyolink/…` |
|
||||
| frontend | `REGISTRY_PREFIX/dyolink-frontend:TAG` | URLs baked in at **build time** |
|
||||
| nginx | `nginx:alpine` | SSL termination + reverse proxy |
|
||||
| certbot | `certbot/certbot` | Auto-renews certificates |
|
||||
|
||||
@@ -289,16 +360,19 @@ Open `https://YOUR_DOMAIN` in a browser.
|
||||
|
||||
## Updating the app (new release)
|
||||
|
||||
**On Mac** — build & push:
|
||||
**Preferred:** `git tag vX.Y.Z && git push origin vX.Y.Z` (Gitea production workflow).
|
||||
|
||||
**Fallback (Docker Hub from a Mac):**
|
||||
|
||||
```bash
|
||||
./infrastructure/scripts/build-and-push-prod.sh wixur.ir latest
|
||||
./infrastructure/scripts/build-and-push-prod.sh nudentic.ir v1.0.1
|
||||
```
|
||||
|
||||
**On server:**
|
||||
**On server** (if not using CI):
|
||||
|
||||
```bash
|
||||
cd /opt/dyolink/infrastructure
|
||||
# TAG in .env or: TAG=v1.0.1 docker compose -f docker-compose.prod.yml --env-file .env pull backend frontend
|
||||
docker compose -f docker-compose.prod.yml --env-file .env pull backend frontend
|
||||
docker compose -f docker-compose.prod.yml --env-file .env up -d
|
||||
```
|
||||
@@ -361,6 +435,10 @@ docker volume rm dyolink_postgres_data_prod
|
||||
./scripts/deploy-prod.sh
|
||||
```
|
||||
|
||||
### Docker login to `wixur.ir:3000`: `http response to HTTPS client`
|
||||
|
||||
Add `"insecure-registries": ["wixur.ir:3000"]` to `/etc/docker/daemon.json` and restart Docker.
|
||||
|
||||
### View logs
|
||||
|
||||
```bash
|
||||
@@ -385,12 +463,13 @@ docker compose -f docker-compose.prod.yml --env-file .env exec frontend \
|
||||
|
||||
| Path on server | Purpose |
|
||||
|----------------|---------|
|
||||
| `/opt/dyolink/infrastructure/.env` | Domain, Docker Hub user, Let's Encrypt email |
|
||||
| `/opt/dyolink/infrastructure/.env` | `DOMAIN`, `REGISTRY_PREFIX`, `TAG`, Let's Encrypt email |
|
||||
| `/opt/dyolink/secrets/database.env` | Postgres credentials |
|
||||
| `/opt/dyolink/secrets/backend.env` | API secrets, DATABASE_URL, JWT, SMS |
|
||||
| `/opt/dyolink/secrets/backend.env` | API secrets, DATABASE_URL, JWT, SMS, `FRONTEND_URL` |
|
||||
| `/opt/dyolink/infrastructure/nginx/generated/default.conf` | Auto-generated nginx SSL config |
|
||||
| `/opt/dyolink/infrastructure/scripts/deploy-prod.sh` | Main deploy entry point |
|
||||
| `/opt/dyolink/infrastructure/scripts/build-and-push-prod.sh` | Build & push (run on Mac) |
|
||||
| `/opt/dyolink/infrastructure/scripts/prod-remote-deploy.sh` | Tag deploy (CI SSH) |
|
||||
| `/opt/dyolink/infrastructure/scripts/deploy-prod.sh` | First-time SSL + stack up |
|
||||
| `.gitea/workflows/prod-tag-deploy.yml` | CI: build, push `:v*`, SSH deploy |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user