Cache npm and Docker bases on the Windows Gitea host for Iran-only builds.
CI installs via local Verdaccio and prefers Gitea copies of node/postgres/nginx so staging and prod can still ship when Docker Hub and npmjs are unreachable.
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
# CLONE_HOST git clone, e.g. 127.0.0.1:3000
|
||||
# PROD_PUBLIC_BASE_URL https://nudentic.ir (no trailing slash)
|
||||
# NEXT_PUBLIC_SENTRY_DSN GlitchTip frontend project DSN
|
||||
# NODE_IMAGE_SOURCE extra base-image ref(s) for seed/resolve
|
||||
# NPM_REGISTRY default http://host.docker.internal:4873 (Verdaccio on Windows)
|
||||
# PROD_REGISTRY_HOST Linux pull host, e.g. wixur.ir:3000 (HTTP; insecure-registries on the VPS)
|
||||
# PROD_INFRA_DIR /opt/dyolink/infrastructure
|
||||
#
|
||||
@@ -101,7 +103,28 @@ jobs:
|
||||
$pass.Trim() | docker login "${{ vars.REGISTRY_HOST }}" -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
- name: Resolve node:20-bookworm-slim (Gitea, then mirrors, Hub last)
|
||||
- name: Seed Gitea base images (node, postgres, nginx, certbot, verdaccio)
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$prefix = "${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}".Trim()
|
||||
$extra = '${{ vars.NODE_IMAGE_SOURCE }}'.Trim()
|
||||
if ($extra -like '*NODE_IMAGE_SOURCE*') { $extra = '' }
|
||||
$scriptArgs = @{ RegistryPrefix = $prefix }
|
||||
if (-not [string]::IsNullOrWhiteSpace($extra)) { $scriptArgs['ExtraSources'] = $extra }
|
||||
& .\infrastructure\scripts\seed-gitea-base-images.ps1 @scriptArgs
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
- name: Resolve npm registry (Verdaccio on Windows host)
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$reg = '${{ vars.NPM_REGISTRY }}'.Trim()
|
||||
if ($reg -like '*NPM_REGISTRY*') { $reg = '' }
|
||||
$scriptArgs = @{}
|
||||
if (-not [string]::IsNullOrWhiteSpace($reg)) { $scriptArgs['Registry'] = $reg }
|
||||
& .\infrastructure\scripts\ci-resolve-npm-registry.ps1 @scriptArgs
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
- name: Resolve dyolink-node (Gitea, then mirrors, Hub last)
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$prefix = "${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}".Trim()
|
||||
@@ -124,12 +147,21 @@ jobs:
|
||||
Write-Host "Missing .ci-node-image"
|
||||
exit 1
|
||||
}
|
||||
$npmReg = ([System.IO.File]::ReadAllText((Join-Path (Get-Location) '.ci-npm-registry'))).Trim()
|
||||
if ([string]::IsNullOrWhiteSpace($npmReg)) {
|
||||
Write-Host "Missing .ci-npm-registry"
|
||||
exit 1
|
||||
}
|
||||
if (Test-Path '.ci-use-legacy-builder') { $env:DOCKER_BUILDKIT = '0' }
|
||||
Write-Host "Building $prefix/dyolink-backend:$tag (NODE_IMAGE=$nodeImage)"
|
||||
Write-Host "Building $prefix/dyolink-backend:$tag (NODE_IMAGE=$nodeImage NPM_REGISTRY=$npmReg)"
|
||||
$ok = $false
|
||||
for ($i = 1; $i -le 3; $i++) {
|
||||
Write-Host "docker build attempt $i/3"
|
||||
docker build --build-arg "NODE_IMAGE=$nodeImage" -t "$prefix/dyolink-backend:$tag" ./backend
|
||||
docker build `
|
||||
--add-host "host.docker.internal:host-gateway" `
|
||||
--build-arg "NODE_IMAGE=$nodeImage" `
|
||||
--build-arg "NPM_REGISTRY=$npmReg" `
|
||||
-t "$prefix/dyolink-backend:$tag" ./backend
|
||||
if ($LASTEXITCODE -eq 0) { $ok = $true; break }
|
||||
if ($i -lt 3) { Start-Sleep -Seconds (20 * $i) }
|
||||
}
|
||||
@@ -151,21 +183,28 @@ jobs:
|
||||
Write-Host "Missing .ci-node-image"
|
||||
exit 1
|
||||
}
|
||||
$npmReg = ([System.IO.File]::ReadAllText((Join-Path (Get-Location) '.ci-npm-registry'))).Trim()
|
||||
if ([string]::IsNullOrWhiteSpace($npmReg)) {
|
||||
Write-Host "Missing .ci-npm-registry"
|
||||
exit 1
|
||||
}
|
||||
if (Test-Path '.ci-use-legacy-builder') { $env:DOCKER_BUILDKIT = '0' }
|
||||
$base = $env:PROD_PUBLIC_BASE_URL.Trim()
|
||||
if ([string]::IsNullOrWhiteSpace($base)) { $base = 'https://nudentic.ir' }
|
||||
$base = $base.TrimEnd('/')
|
||||
Write-Host "Building $prefix/dyolink-frontend:$tag (NODE_IMAGE=$nodeImage)"
|
||||
Write-Host "Building $prefix/dyolink-frontend:$tag (NODE_IMAGE=$nodeImage NPM_REGISTRY=$npmReg)"
|
||||
$ok = $false
|
||||
for ($i = 1; $i -le 3; $i++) {
|
||||
Write-Host "docker build attempt $i/3"
|
||||
docker build `
|
||||
--add-host "host.docker.internal:host-gateway" `
|
||||
--build-arg "NEXT_PUBLIC_API_URL=$base/api" `
|
||||
--build-arg "NEXT_PUBLIC_APP_URL=$base" `
|
||||
--build-arg "NEXT_PUBLIC_APP_NAME=Dyolink" `
|
||||
--build-arg "NEXT_PUBLIC_SENTRY_DSN=$env:NEXT_PUBLIC_SENTRY_DSN" `
|
||||
--build-arg "NEXT_PUBLIC_SENTRY_ENVIRONMENT=production" `
|
||||
--build-arg "NODE_IMAGE=$nodeImage" `
|
||||
--build-arg "NPM_REGISTRY=$npmReg" `
|
||||
-t "$prefix/dyolink-frontend:$tag" `
|
||||
./frontend
|
||||
if ($LASTEXITCODE -eq 0) { $ok = $true; break }
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
# CLONE_HOST git clone host when runner = Gitea host → 127.0.0.1:3000
|
||||
# NODE_IMAGE_SOURCE extra base-image ref(s), comma-separated, tried before built-in mirrors
|
||||
# e.g. docker.arvancloud.ir/library/node:20-bookworm-slim
|
||||
# NPM_REGISTRY npm registry for docker build (default http://host.docker.internal:4873 = Verdaccio)
|
||||
#
|
||||
# Same Windows PC runs Gitea + runner + deploy:
|
||||
# CLONE_HOST → 127.0.0.1:3000 (git runs on Windows host)
|
||||
@@ -86,7 +87,28 @@ jobs:
|
||||
$pass.Trim() | docker login "${{ vars.REGISTRY_HOST }}" -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
- name: Resolve node:20-bookworm-slim (Gitea, then mirrors, Hub last)
|
||||
- name: Seed Gitea base images (node, postgres, nginx, certbot, verdaccio)
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$prefix = "${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}".Trim()
|
||||
$extra = '${{ vars.NODE_IMAGE_SOURCE }}'.Trim()
|
||||
if ($extra -like '*NODE_IMAGE_SOURCE*') { $extra = '' }
|
||||
$scriptArgs = @{ RegistryPrefix = $prefix }
|
||||
if (-not [string]::IsNullOrWhiteSpace($extra)) { $scriptArgs['ExtraSources'] = $extra }
|
||||
& .\infrastructure\scripts\seed-gitea-base-images.ps1 @scriptArgs
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
- name: Resolve npm registry (Verdaccio on Windows host)
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$reg = '${{ vars.NPM_REGISTRY }}'.Trim()
|
||||
if ($reg -like '*NPM_REGISTRY*') { $reg = '' }
|
||||
$scriptArgs = @{}
|
||||
if (-not [string]::IsNullOrWhiteSpace($reg)) { $scriptArgs['Registry'] = $reg }
|
||||
& .\infrastructure\scripts\ci-resolve-npm-registry.ps1 @scriptArgs
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
- name: Resolve dyolink-node (Gitea, then mirrors, Hub last)
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$prefix = "${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}".Trim()
|
||||
@@ -112,13 +134,20 @@ jobs:
|
||||
Write-Host "Missing .ci-node-image"
|
||||
exit 1
|
||||
}
|
||||
$npmReg = ([System.IO.File]::ReadAllText((Join-Path (Get-Location) '.ci-npm-registry'))).Trim()
|
||||
if ([string]::IsNullOrWhiteSpace($npmReg)) {
|
||||
Write-Host "Missing .ci-npm-registry"
|
||||
exit 1
|
||||
}
|
||||
if (Test-Path '.ci-use-legacy-builder') { $env:DOCKER_BUILDKIT = '0' }
|
||||
Write-Host "Building $prefix/dyolink-backend:$tag (NODE_IMAGE=$nodeImage)"
|
||||
Write-Host "Building $prefix/dyolink-backend:$tag (NODE_IMAGE=$nodeImage NPM_REGISTRY=$npmReg)"
|
||||
$ok = $false
|
||||
for ($i = 1; $i -le 3; $i++) {
|
||||
Write-Host "docker build attempt $i/3"
|
||||
docker build `
|
||||
--add-host "host.docker.internal:host-gateway" `
|
||||
--build-arg "NODE_IMAGE=$nodeImage" `
|
||||
--build-arg "NPM_REGISTRY=$npmReg" `
|
||||
-t "$prefix/dyolink-backend:$tag" `
|
||||
-t "$prefix/dyolink-backend:latest" `
|
||||
./backend
|
||||
@@ -145,18 +174,25 @@ jobs:
|
||||
Write-Host "Missing .ci-node-image"
|
||||
exit 1
|
||||
}
|
||||
$npmReg = ([System.IO.File]::ReadAllText((Join-Path (Get-Location) '.ci-npm-registry'))).Trim()
|
||||
if ([string]::IsNullOrWhiteSpace($npmReg)) {
|
||||
Write-Host "Missing .ci-npm-registry"
|
||||
exit 1
|
||||
}
|
||||
if (Test-Path '.ci-use-legacy-builder') { $env:DOCKER_BUILDKIT = '0' }
|
||||
Write-Host "Building $prefix/dyolink-frontend:$tag (NODE_IMAGE=$nodeImage)"
|
||||
Write-Host "Building $prefix/dyolink-frontend:$tag (NODE_IMAGE=$nodeImage NPM_REGISTRY=$npmReg)"
|
||||
$ok = $false
|
||||
for ($i = 1; $i -le 3; $i++) {
|
||||
Write-Host "docker build attempt $i/3"
|
||||
docker build `
|
||||
--add-host "host.docker.internal:host-gateway" `
|
||||
--build-arg "NEXT_PUBLIC_API_URL=$base/api" `
|
||||
--build-arg "NEXT_PUBLIC_APP_URL=$base" `
|
||||
--build-arg "NEXT_PUBLIC_APP_NAME=Dyolink" `
|
||||
--build-arg "NEXT_PUBLIC_SENTRY_DSN=$env:NEXT_PUBLIC_SENTRY_DSN" `
|
||||
--build-arg "NEXT_PUBLIC_SENTRY_ENVIRONMENT=staging" `
|
||||
--build-arg "NODE_IMAGE=$nodeImage" `
|
||||
--build-arg "NPM_REGISTRY=$npmReg" `
|
||||
-t "$prefix/dyolink-frontend:$tag" `
|
||||
-t "$prefix/dyolink-frontend:latest" `
|
||||
./frontend
|
||||
@@ -227,7 +263,9 @@ jobs:
|
||||
"IMAGE_TAG=$imageTag",
|
||||
"STAGING_HTTP_PORT=$stagingPort",
|
||||
"STAGING_LOCAL_PORT=$localPort",
|
||||
"DEPLOY_SECRETS_DIR=$SD"
|
||||
"DEPLOY_SECRETS_DIR=$SD",
|
||||
"POSTGRES_IMAGE=$prefix/postgres:15-alpine",
|
||||
"NGINX_IMAGE=$prefix/nginx:alpine"
|
||||
)
|
||||
Set-Location infrastructure
|
||||
$utf8 = New-Object System.Text.UTF8Encoding $false
|
||||
@@ -246,7 +284,7 @@ jobs:
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-Location infrastructure
|
||||
docker compose -f docker-compose.registry.yml --env-file deploy.registry.env pull backend frontend
|
||||
docker compose -f docker-compose.registry.yml --env-file deploy.registry.env pull
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
docker compose -f docker-compose.registry.yml --env-file deploy.registry.env up -d
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
@@ -34,6 +34,7 @@ Workflow: [`.gitea/workflows/registry-build-deploy.yml`](.gitea/workflows/regist
|
||||
|------|------|
|
||||
| `backend/Dockerfile` | API image |
|
||||
| `frontend/Dockerfile` | Web image (`standalone` + copy `public/` for catalog icons) |
|
||||
| `infrastructure/STAGING-DEPLOY.md` | Staging setup, CI variables, testing |
|
||||
| `infrastructure/STAGING-DEPLOY.md` | Staging setup, Verdaccio, CI variables, blackout checklist |
|
||||
| `infrastructure/docker-compose.registry.yml` | Pull-only staging stack (registry images + nginx + postgres) |
|
||||
| `infrastructure/docker-compose.verdaccio.yml` | Local npm warehouse on the Windows build PC |
|
||||
| `infrastructure/deploy.registry.env.example` | Template for `deploy.registry.env` |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# CI can pass a Gitea-hosted mirror when Docker Hub TLS fails (see ci-resolve-node-image.ps1).
|
||||
# CI passes Gitea-hosted dyolink-node (node + dumb-init). See seed-gitea-base-images.ps1.
|
||||
ARG NODE_IMAGE=node:20-bookworm-slim
|
||||
|
||||
# ============================================
|
||||
@@ -6,25 +6,29 @@ ARG NODE_IMAGE=node:20-bookworm-slim
|
||||
# ============================================
|
||||
FROM ${NODE_IMAGE} AS builder
|
||||
|
||||
# CI passes Verdaccio (http://host.docker.internal:4873). Default is official npm for laptop builds.
|
||||
ARG NPM_REGISTRY=https://registry.npmjs.com
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
COPY .npmrc ./
|
||||
COPY prisma ./prisma/
|
||||
|
||||
# Debian bookworm-slim (glibc). Single npm ci + BuildKit cache (no nested retries).
|
||||
# Staging runners that flake on registry.npmjs.org (ETIMEDOUT / ECONNRESET) surface
|
||||
# as "Exit handler never called!". Point npm + lockfile tarball hosts at
|
||||
# registry.npmjs.com for this build only — does not change package-lock.json in git.
|
||||
# Debian bookworm-slim (glibc). Single npm ci + BuildKit cache.
|
||||
# CI: Verdaccio on :4873 (online fills cache from npmjs; blackout serves disk).
|
||||
# Does not change package-lock.json in git.
|
||||
ENV NODE_OPTIONS=--max-old-space-size=3072
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm config set registry https://registry.npmjs.com \
|
||||
npm config set registry "${NPM_REGISTRY}" \
|
||||
&& npm config set fetch-retries 5 \
|
||||
&& npm config set fetch-retry-maxtimeout 120000 \
|
||||
&& npm config set maxsockets 5 \
|
||||
&& sed -i \
|
||||
-e 's|https://registry.npmmirror.com/|https://registry.npmjs.com/|g' \
|
||||
-e 's|https://registry.npmjs.org/|https://registry.npmjs.com/|g' \
|
||||
-e "s|https://registry.npmmirror.com|${NPM_REGISTRY}|g" \
|
||||
-e "s|https://registry.npmjs.org|${NPM_REGISTRY}|g" \
|
||||
-e "s|https://registry.npmjs.com|${NPM_REGISTRY}|g" \
|
||||
-e "s|http://host.docker.internal:4873|${NPM_REGISTRY}|g" \
|
||||
package-lock.json \
|
||||
&& npm ci --no-audit --no-fund \
|
||||
&& test -e node_modules/.bin/prisma \
|
||||
@@ -42,9 +46,13 @@ RUN npm prune --omit=dev
|
||||
# ============================================
|
||||
FROM ${NODE_IMAGE}
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends dumb-init \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
# dyolink-node already has dumb-init. Vanilla node: apt-get while online only.
|
||||
USER root
|
||||
RUN if ! command -v dumb-init >/dev/null 2>&1; then \
|
||||
apt-get update \
|
||||
&& apt-get install -y --no-install-recommends dumb-init \
|
||||
&& rm -rf /var/lib/apt/lists/*; \
|
||||
fi
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
# CI can pass a Gitea-hosted mirror when Docker Hub TLS fails (see ci-resolve-node-image.ps1).
|
||||
# CI passes Gitea-hosted dyolink-node (node + dumb-init). See seed-gitea-base-images.ps1.
|
||||
ARG NODE_IMAGE=node:20-bookworm-slim
|
||||
|
||||
# Build stage — produces `.next/standalone` (see next.config.ts output: standalone)
|
||||
FROM ${NODE_IMAGE} AS builder
|
||||
|
||||
# CI passes Verdaccio (http://host.docker.internal:4873). Default is official npm for laptop builds.
|
||||
ARG NPM_REGISTRY=https://registry.npmjs.com
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
# Same as backend: bookworm-slim + single npm ci; rewrite lockfile hosts → npmjs.com
|
||||
# when the runner flakes on .org / leftover npmmirror URLs (see backend/Dockerfile).
|
||||
# Same as backend: rewrite lockfile hosts to NPM_REGISTRY for this build only.
|
||||
ENV NODE_OPTIONS=--max-old-space-size=3072
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm config set registry https://registry.npmjs.com \
|
||||
npm config set registry "${NPM_REGISTRY}" \
|
||||
&& npm config set fetch-retries 5 \
|
||||
&& npm config set fetch-retry-maxtimeout 120000 \
|
||||
&& npm config set maxsockets 5 \
|
||||
&& sed -i \
|
||||
-e 's|https://registry.npmmirror.com/|https://registry.npmjs.com/|g' \
|
||||
-e 's|https://registry.npmjs.org/|https://registry.npmjs.com/|g' \
|
||||
-e "s|https://registry.npmmirror.com|${NPM_REGISTRY}|g" \
|
||||
-e "s|https://registry.npmjs.org|${NPM_REGISTRY}|g" \
|
||||
-e "s|https://registry.npmjs.com|${NPM_REGISTRY}|g" \
|
||||
-e "s|http://host.docker.internal:4873|${NPM_REGISTRY}|g" \
|
||||
package-lock.json \
|
||||
&& npm ci --no-audit --no-fund \
|
||||
&& test -e node_modules/.bin/next
|
||||
@@ -43,9 +47,12 @@ RUN npm run build
|
||||
# Production — minimal runtime using Next.js standalone bundle
|
||||
FROM ${NODE_IMAGE} AS runner
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends dumb-init \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
USER root
|
||||
RUN if ! command -v dumb-init >/dev/null 2>&1; then \
|
||||
apt-get update \
|
||||
&& apt-get install -y --no-install-recommends dumb-init \
|
||||
&& rm -rf /var/lib/apt/lists/*; \
|
||||
fi
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@@ -78,6 +78,25 @@ Check `https://nudentic.ir/api/health`. AdminJS is `https://nudentic.ir/admin`.
|
||||
|
||||
---
|
||||
|
||||
## Iran-local builds (international blackout)
|
||||
|
||||
Production **build** still happens on the Windows Gitea runner. Linux only **pulls** from `wixur.ir:3000`.
|
||||
|
||||
1. On Windows, Verdaccio + seed (see [`STAGING-DEPLOY.md`](STAGING-DEPLOY.md) §1b). One online staging build fills the npm cache.
|
||||
2. On this Linux server, `.env` must name Gitea copies of runtime images (after seed):
|
||||
|
||||
```
|
||||
POSTGRES_IMAGE=wixur.ir:3000/<owner>/postgres:15-alpine
|
||||
NGINX_IMAGE=wixur.ir:3000/<owner>/nginx:alpine
|
||||
CERTBOT_IMAGE=wixur.ir:3000/<owner>/certbot:latest
|
||||
```
|
||||
|
||||
`prod-remote-deploy.sh` fills these from `REGISTRY_PREFIX` if omitted.
|
||||
|
||||
**During a blackout:** tag `v*` as usual. Do not prune Docker on Windows or Linux. Let's Encrypt **renew** needs public ACME — existing certs keep working until expiry.
|
||||
|
||||
---
|
||||
|
||||
## Architecture
|
||||
|
||||
|
||||
@@ -91,11 +110,11 @@ Internet → Nginx (:80 / :443)
|
||||
|
||||
| Service | Image | Notes |
|
||||
|-----------|------------------------------------|--------------------------------|
|
||||
| postgres | `postgres:15-alpine` | Data in Docker volume |
|
||||
| postgres | `POSTGRES_IMAGE` (Gitea copy of `postgres:15-alpine`) | Data in Docker volume |
|
||||
| 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 |
|
||||
| nginx | `NGINX_IMAGE` (Gitea copy of `nginx:alpine`) | SSL termination + reverse proxy |
|
||||
| certbot | `CERTBOT_IMAGE` (Gitea copy of `certbot/certbot`) | Auto-renews certificates (needs ACME online) |
|
||||
|
||||
---
|
||||
|
||||
@@ -479,13 +498,13 @@ docker compose -f docker-compose.prod.yml --env-file .env exec frontend \
|
||||
|
||||
| Path on server | Purpose |
|
||||
|----------------|---------|
|
||||
| `/opt/dyolink/infrastructure/.env` | `DOMAIN`, `REGISTRY_PREFIX`, `TAG`, Let's Encrypt email |
|
||||
| `/opt/dyolink/infrastructure/.env` | `DOMAIN`, `REGISTRY_PREFIX`, `TAG`, `POSTGRES_IMAGE`, `NGINX_IMAGE`, `CERTBOT_IMAGE` |
|
||||
| `/opt/dyolink/secrets/database.env` | Postgres credentials |
|
||||
| `/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/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 |
|
||||
| `.gitea/workflows/prod-tag-deploy.yml` | CI: Verdaccio + Gitea bases, push `:v*`, SSH deploy |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ http://wixur.ir:3000 → Gitea (native, no Docker)
|
||||
|
||||
| Service | Image source |
|
||||
|----------|---------------------------------------------------|
|
||||
| postgres | `postgres:15-alpine` (pulled from Docker Hub) |
|
||||
| postgres | `<REGISTRY_PREFIX>/postgres:15-alpine` (Gitea copy; seed script) |
|
||||
| backend | `<REGISTRY_HOST>/<owner>/dyolink-backend:<sha>` |
|
||||
| frontend | `<REGISTRY_HOST>/<owner>/dyolink-frontend:<sha>` |
|
||||
| nginx | `nginx:alpine` |
|
||||
| nginx | `<REGISTRY_PREFIX>/nginx:alpine` (Gitea copy) |
|
||||
|
||||
Frontend public URLs are **baked in at build time** via `PUBLIC_BASE_URL`. After changing the public URL, re-run the Gitea workflow (or push to `master`) and set `FRONTEND_URL` in `C:\dyolink\secrets\backend.staging.env` to the same origin. The same `frontend/Dockerfile` must copy `public/` into the standalone image (catalog icons).
|
||||
|
||||
@@ -77,7 +77,7 @@ Workflow file: [`.gitea/workflows/registry-build-deploy.yml`](../.gitea/workflow
|
||||
### 1. Docker Desktop
|
||||
|
||||
- Install and keep **Docker Desktop running** during builds/deploys.
|
||||
- **WSL2 memory** (Docker Desktop no longer shows a RAM slider): optional `C:\Users\<user>\.wslconfig` with `[wsl2] memory=8GB` if builds feel tight. The usual CI `npm ci` failure on this host is **blocked `registry.npmjs.org`**, not RAM — Dockerfiles use **npmmirror** for installs.
|
||||
- **WSL2 memory** (Docker Desktop no longer shows a RAM slider): optional `C:\Users\<user>\.wslconfig` with `[wsl2] memory=8GB` if builds feel tight. The usual CI `npm ci` failure on this host is **blocked `registry.npmjs.org`**, not RAM — CI installs through **Verdaccio** on this PC (see §1b).
|
||||
- **Settings → Docker Engine** — allow HTTP registry:
|
||||
|
||||
```json
|
||||
@@ -94,6 +94,44 @@ Apply & restart Docker Desktop.
|
||||
|
||||
**Why `host.docker.internal`?** Docker Desktop runs in a Linux VM. `docker login` runs from that VM — `127.0.0.1:3000` is the VM, not Gitea on Windows.
|
||||
|
||||
### 1b. Verdaccio (local npm warehouse) + Gitea base images
|
||||
|
||||
App builds download npm packages through **Verdaccio on this Windows PC**, not through Chinese/Iranian public mirrors. While international internet works, Verdaccio fetches from official npmjs.org and **saves the tarballs on disk**. During a blackout it serves that disk only.
|
||||
|
||||
**Start Verdaccio once and leave it running** (same idea as Gitea):
|
||||
|
||||
```powershell
|
||||
cd C:\path\to\dyolink\infrastructure
|
||||
docker compose -f docker-compose.verdaccio.yml up -d
|
||||
# check: http://127.0.0.1:4873 should load the Verdaccio UI
|
||||
```
|
||||
|
||||
Storage is the Docker volume `dyolink_verdaccio_storage`. **Do not delete it.** **Do not `docker system prune -a`.**
|
||||
|
||||
**Seed Hub images into Gitea** (while online — also run by CI after `docker login`):
|
||||
|
||||
```powershell
|
||||
docker login host.docker.internal:3000 -u <gitea-user>
|
||||
cd C:\path\to\dyolink
|
||||
.\infrastructure\scripts\seed-gitea-base-images.ps1 -RegistryPrefix "host.docker.internal:3000/<owner>"
|
||||
```
|
||||
|
||||
That copies `node`, `dyolink-node` (node + dumb-init), `postgres`, `nginx`, `certbot`, and `verdaccio` into Gitea Packages.
|
||||
|
||||
Point Verdaccio itself at the Gitea copy so it can start in a blackout. In `deploy.registry.env` (or a one-line env file):
|
||||
|
||||
```
|
||||
VERDACCIO_IMAGE=host.docker.internal:3000/<owner>/verdaccio:5
|
||||
```
|
||||
|
||||
```powershell
|
||||
docker compose -f docker-compose.verdaccio.yml --env-file deploy.registry.env up -d
|
||||
```
|
||||
|
||||
**Warm the npm cache:** run the staging workflow **once while online**. That `npm ci` fills Verdaccio. Later blackout builds reuse it. Adding a **new** npm package during a blackout will fail until the net returns once.
|
||||
|
||||
Optional Gitea variable `NPM_REGISTRY` (default `http://host.docker.internal:4873`).
|
||||
|
||||
### 2b. Gitea `app.ini` — match registry URL
|
||||
|
||||
Edit `C:\gitea\custom\conf\app.ini`:
|
||||
@@ -171,6 +209,7 @@ Rules:
|
||||
| `CLONE_HOST` | `127.0.0.1:3000` | Git clone (runs on Windows host, not inside Docker VM) |
|
||||
| `STAGING_HTTP_PORT` | `80` | Public HTTP port (portproxy). Optional; workflow default is 80. |
|
||||
| `STAGING_LOCAL_PORT` | `18088` | Docker bind on `127.0.0.1`. Must not be `80` if portproxy already uses 80. |
|
||||
| `NPM_REGISTRY` | `http://host.docker.internal:4873` | Optional. CI default is Verdaccio on this PC. |
|
||||
|
||||
**Naming note:** Gitea rejects variable names starting with `GITEA_` or `GITHUB_`. Use `CLONE_HOST`, not `GITEA_CLONE_URL`.
|
||||
|
||||
@@ -232,6 +271,8 @@ curl http://wixur.ir/health
|
||||
### Before first run
|
||||
|
||||
- [ ] Docker Desktop running
|
||||
- [ ] `dyolink_verdaccio` running (`http://127.0.0.1:4873`)
|
||||
- [ ] Seed script ran once (Gitea Packages show `dyolink-node`, `postgres`, `nginx`)
|
||||
- [ ] `act_runner.exe daemon` running
|
||||
- [ ] All Variables + Secrets set (including `CLONE_HOST`)
|
||||
- [ ] Secret env files exist under `DEPLOY_SECRETS_DIR`
|
||||
@@ -275,7 +316,26 @@ curl http://wixur.ir/api/health
|
||||
|
||||
Expected: `{"status":"ok",...}`
|
||||
|
||||
**Gitea packages:** profile/org → **Packages** — should list `dyolink-backend` and `dyolink-frontend` after first build.
|
||||
**Gitea packages:** profile/org → **Packages** — should list `dyolink-backend`, `dyolink-frontend`, plus seeded `dyolink-node`, `postgres`, `nginx` after seed/first build.
|
||||
|
||||
---
|
||||
|
||||
## International internet blackout
|
||||
|
||||
Iran domestic network (this Windows PC, `wixur.ir`, Linux `nudentic.ir`) must still work. Foreign sites (Docker Hub, npmjs.org, Let's Encrypt ACME) can be down.
|
||||
|
||||
**While online (do once, keep fresh after big dependency upgrades):**
|
||||
|
||||
1. Verdaccio running; seed script succeeded; one staging build filled the npm cache.
|
||||
2. Linux `.env` has `POSTGRES_IMAGE` / `NGINX_IMAGE` / `CERTBOT_IMAGE` pointing at `wixur.ir:3000/<owner>/…` (see [`deploy.prod.env.example`](deploy.prod.env.example)).
|
||||
|
||||
**During a blackout:**
|
||||
|
||||
- Push `master` / tag `v*` as usual. CI clones Gitea locally, builds via Verdaccio + Gitea `dyolink-node`, deploys staging locally, prod pulls `wixur.ir:3000`.
|
||||
- Keep Gitea, Docker Desktop, act_runner, and Verdaccio running.
|
||||
- Do **not** `docker system prune -a` or delete `dyolink_verdaccio_storage`.
|
||||
|
||||
**Still impossible offline:** brand-new npm package never cached; first-time Docker install from abroad; Let's Encrypt **renew** (existing certs keep serving until they expire).
|
||||
|
||||
---
|
||||
|
||||
@@ -301,8 +361,9 @@ On the Windows host, from repo `infrastructure/`:
|
||||
| Runner can't register on public IP | Use `http://127.0.0.1:3000` for `--instance` |
|
||||
| Variable name rejected in Gitea | No `GITEA_*` / `GITHUB_*` prefixes; use `CLONE_HOST` |
|
||||
| `413 Request Entity Too Large` on `docker push` to `https://gitea.wixur.ir/v2/…/blobs/uploads` | Nginx (or Cloudflare) in front of Gitea is rejecting the image layer. **Fix the proxy** (then `nginx -s reload`): in the `server { server_name gitea.wixur.ir; }` block set `client_max_body_size 0;` and `proxy_request_buffering off;` — snippet: [`nginx/windows-gitea.wixur.snippet.conf`](nginx/windows-gitea.wixur.snippet.conf). **Or skip the proxy:** set `REGISTRY_HOST=host.docker.internal:3000` (and Gitea `ROOT_URL`) so CI pushes to `:3000`. If the hostname is orange-clouded on Cloudflare, grey-cloud it (free plan caps uploads at 100MB). |
|
||||
| `TLS handshake timeout` to `registry-1.docker.io` / `node:20-bookworm-slim` | Docker Hub is blocked or slow from the Windows runner. CI pulls `node:20-bookworm-slim` from **Arvan / ECR Public / GCR**, then pushes `<REGISTRY_PREFIX>/node:20-bookworm-slim` to Gitea (later builds skip Hub). Optional variable `NODE_IMAGE_SOURCE` (comma-separated image refs). One-time on the runner: `docker pull docker.arvancloud.ir/library/node:20-bookworm-slim` then tag/push to Gitea. |
|
||||
| `npm error Exit handler never called!` during backend/frontend image build | Almost always **network**: `registry.npmjs.org` unreachable (`ECONNRESET` / ~25 min hang). Confirm: `docker run --rm <REGISTRY_PREFIX>/node:20-bookworm-slim npm ping` fails, while `npm ping --registry https://registry.npmmirror.com` works. Dockerfiles already rewrite lockfile hosts to **npmmirror** for `npm ci` — ensure that commit is on the branch CI builds. Nested retries do not help. |
|
||||
| `TLS handshake timeout` to `registry-1.docker.io` / `node:20-bookworm-slim` | Docker Hub blocked. Run [`scripts/seed-gitea-base-images.ps1`](scripts/seed-gitea-base-images.ps1) while Arvan/Hub works. CI prefers Gitea `dyolink-node`. Optional `NODE_IMAGE_SOURCE`. |
|
||||
| `Cannot reach http://127.0.0.1:4873/-/ping` | Verdaccio is down. `docker compose -f docker-compose.verdaccio.yml up -d` then re-run CI. |
|
||||
| `npm error Exit handler never called!` during backend/frontend image build | Build is not using Verdaccio, or Verdaccio cache is empty and npmjs is blocked. Confirm `docker ps` has `dyolink_verdaccio`. First successful **online** staging build fills the cache. Do not point CI at npmmirror. |
|
||||
| `docker login` connection refused on `127.0.0.1:3000` | **Docker Desktop on Windows:** set `REGISTRY_HOST=host.docker.internal:3000`, add it to insecure-registries, set Gitea `ROOT_URL=http://host.docker.internal:3000/`. Keep `CLONE_HOST=127.0.0.1:3000` for git. |
|
||||
| `docker login` / push denied, redirect to public IP | Set Gitea `ROOT_URL` to a host Docker can reach (`host.docker.internal:3000` on Windows Docker Desktop). |
|
||||
| `server gave HTTP response to HTTPS client` | Add registry host to Docker **insecure-registries**, restart Docker |
|
||||
@@ -332,8 +393,13 @@ docker logs dyolink_frontend_staging --tail 50
|
||||
|
||||
| Path | Role |
|
||||
|------|------|
|
||||
| `.gitea/workflows/registry-build-deploy.yml` | CI: build, push, deploy |
|
||||
| `infrastructure/scripts/ci-resolve-node-image.ps1` | CI: cache `node:20-bookworm-slim` on Gitea so builds do not depend on Docker Hub |
|
||||
| `.gitea/workflows/registry-build-deploy.yml` | CI: seed bases, build via Verdaccio, push, deploy |
|
||||
| `infrastructure/scripts/seed-gitea-base-images.ps1` | Copy node/postgres/nginx/certbot/verdaccio + build dyolink-node into Gitea |
|
||||
| `infrastructure/scripts/ci-resolve-node-image.ps1` | CI: prefer Gitea `dyolink-node` |
|
||||
| `infrastructure/scripts/ci-resolve-npm-registry.ps1` | CI: Verdaccio URL + ping |
|
||||
| `infrastructure/docker-compose.verdaccio.yml` | Local npm warehouse on :4873 |
|
||||
| `infrastructure/verdaccio/config.yaml` | Verdaccio: uplink npmjs while online, cache for blackout |
|
||||
| `infrastructure/docker/dyolink-node.Dockerfile` | node:20-bookworm-slim + dumb-init |
|
||||
| `infrastructure/docker-compose.registry.yml` | Staging stack (pull-only images) |
|
||||
| `infrastructure/deploy.registry.env.example` | Manual deploy env template |
|
||||
| `infrastructure/database.staging.env.example` | Postgres secrets template |
|
||||
|
||||
@@ -12,6 +12,11 @@ REGISTRY_PREFIX=wixur.ir:3000/admin
|
||||
# (staging already owns :latest with the wixur.ir frontend bake).
|
||||
TAG=v1.0.1
|
||||
|
||||
# Runtime bases copied into Gitea by seed-gitea-base-images.ps1 (Iran-local pulls).
|
||||
POSTGRES_IMAGE=wixur.ir:3000/admin/postgres:15-alpine
|
||||
NGINX_IMAGE=wixur.ir:3000/admin/nginx:alpine
|
||||
CERTBOT_IMAGE=wixur.ir:3000/admin/certbot:latest
|
||||
|
||||
# Hub-only fallback: comment out REGISTRY_PREFIX and use:
|
||||
# REGISTRY_PREFIX=dyolink
|
||||
# TAG=latest
|
||||
|
||||
@@ -12,6 +12,12 @@ REGISTRY_PREFIX=wixur.ir:3000/yourgiteauser
|
||||
# Short git SHA from CI, or "latest" after a manual pull of :latest
|
||||
IMAGE_TAG=latest
|
||||
|
||||
# Gitea copies of Hub runtime images (seed-gitea-base-images.ps1). Hub fallback: omit these.
|
||||
POSTGRES_IMAGE=wixur.ir:3000/yourgiteauser/postgres:15-alpine
|
||||
NGINX_IMAGE=wixur.ir:3000/yourgiteauser/nginx:alpine
|
||||
# Verdaccio container (same Windows PC). After seed, point at the Gitea copy:
|
||||
# VERDACCIO_IMAGE=host.docker.internal:3000/yourgiteauser/verdaccio:5
|
||||
|
||||
# Public HTTP port (router + Windows portproxy listen here) — 80 so users open http://wixur.ir
|
||||
STAGING_HTTP_PORT=80
|
||||
# Docker nginx bind on localhost only (must differ from 80 if portproxy owns 80)
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
# HTTPS via Let's Encrypt (certbot) on this host only (nudentic.ir).
|
||||
#
|
||||
# Gitea tag deploy: set REGISTRY_PREFIX=wixur.ir:3000/<owner> and TAG=v1.0.1 in .env
|
||||
# Hub fallback: omit REGISTRY_PREFIX, set DOCKER_USERNAME=dyolink (image dyolink/dyolink-*).
|
||||
# Runtime bases (postgres/nginx/certbot) should also come from that prefix after seed.
|
||||
# Hub fallback: POSTGRES_IMAGE=postgres:15-alpine NGINX_IMAGE=nginx:alpine CERTBOT_IMAGE=certbot/certbot:latest
|
||||
# and REGISTRY_PREFIX=dyolink for app images.
|
||||
#
|
||||
# First SSL: ./scripts/init-letsencrypt.sh then up -d
|
||||
# Tag updates: CI runs scripts/prod-remote-deploy.sh (or pull + up locally)
|
||||
@@ -11,7 +13,7 @@ name: dyolink-prod
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
image: ${POSTGRES_IMAGE:-postgres:15-alpine}
|
||||
container_name: dyolink_db_prod
|
||||
env_file:
|
||||
- ${DEPLOY_SECRETS_DIR:-./secrets}/database.env
|
||||
@@ -97,7 +99,7 @@ services:
|
||||
start_period: 60s
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
image: ${NGINX_IMAGE:-nginx:alpine}
|
||||
container_name: dyolink_nginx_prod
|
||||
ports:
|
||||
- "80:80"
|
||||
@@ -117,7 +119,7 @@ services:
|
||||
max-file: "3"
|
||||
|
||||
certbot:
|
||||
image: certbot/certbot:latest
|
||||
image: ${CERTBOT_IMAGE:-certbot/certbot:latest}
|
||||
container_name: dyolink_certbot_prod
|
||||
volumes:
|
||||
- certbot_conf:/etc/letsencrypt
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
# Required env (see deploy.registry.env.example):
|
||||
# REGISTRY_PREFIX e.g. host.docker.internal:3000/admin (Windows CI) or wixur.ir:3000/admin (no protocol)
|
||||
# IMAGE_TAG short sha or "latest" (CI sets this per deploy)
|
||||
# POSTGRES_IMAGE Gitea copy, e.g. host.docker.internal:3000/admin/postgres:15-alpine
|
||||
# NGINX_IMAGE Gitea copy, e.g. host.docker.internal:3000/admin/nginx:alpine
|
||||
# Optional:
|
||||
# DEPLOY_SECRETS_DIR absolute path on the server to database/backend *.env files (see below)
|
||||
#
|
||||
@@ -15,7 +17,7 @@ name: dyolink-registry
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
image: ${POSTGRES_IMAGE:-postgres:15-alpine}
|
||||
container_name: dyolink_postgres_staging
|
||||
env_file:
|
||||
- ${DEPLOY_SECRETS_DIR:-.}/database.staging.env
|
||||
@@ -86,7 +88,7 @@ services:
|
||||
start_period: 60s
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
image: ${NGINX_IMAGE:-nginx:alpine}
|
||||
container_name: dyolink_nginx_staging
|
||||
depends_on:
|
||||
backend:
|
||||
|
||||
27
infrastructure/docker-compose.verdaccio.yml
Normal file
27
infrastructure/docker-compose.verdaccio.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
# Local npm warehouse for Windows CI (port 4873).
|
||||
# Start once (while online), keep running like Gitea.
|
||||
#
|
||||
# docker compose -f docker-compose.verdaccio.yml --env-file deploy.registry.env up -d
|
||||
#
|
||||
# After seed-gitea-base-images.ps1, set VERDACCIO_IMAGE to the Gitea copy so this
|
||||
# container can start during an international blackout:
|
||||
# VERDACCIO_IMAGE=host.docker.internal:3000/<owner>/verdaccio:5
|
||||
#
|
||||
# Docker builds use http://host.docker.internal:4873 (see NPM_REGISTRY / Dockerfiles).
|
||||
|
||||
name: dyolink-verdaccio
|
||||
|
||||
services:
|
||||
verdaccio:
|
||||
image: ${VERDACCIO_IMAGE:-verdaccio/verdaccio:5}
|
||||
container_name: dyolink_verdaccio
|
||||
ports:
|
||||
- "4873:4873"
|
||||
volumes:
|
||||
- ./verdaccio/config.yaml:/verdaccio/conf/config.yaml:ro
|
||||
- verdaccio_storage:/verdaccio/storage
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
verdaccio_storage:
|
||||
name: dyolink_verdaccio_storage
|
||||
9
infrastructure/docker/dyolink-node.Dockerfile
Normal file
9
infrastructure/docker/dyolink-node.Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
# Node 20 + dumb-init. App Dockerfiles skip apt when CI uses this image.
|
||||
# Seed: infrastructure/scripts/seed-gitea-base-images.ps1
|
||||
ARG NODE_IMAGE=node:20-bookworm-slim
|
||||
FROM ${NODE_IMAGE}
|
||||
|
||||
USER root
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends dumb-init \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
@@ -1,5 +1,5 @@
|
||||
# Prefer a Gitea-hosted node:20-bookworm-slim so docker build does not HEAD registry-1.docker.io.
|
||||
# Order: Gitea -> optional NODE_IMAGE_SOURCE -> regional/official mirrors -> Docker Hub last.
|
||||
# Prefer Gitea-hosted dyolink-node (node + dumb-init) so docker build does not HEAD registry-1.docker.io
|
||||
# or run apt-get. Order: Gitea dyolink-node -> Gitea node -> NODE_IMAGE_SOURCE -> Arvan/mirrors -> Hub last.
|
||||
# ASCII only: Windows PowerShell 5.1 + act_runner mis-parses backtick escapes in this file.
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$RegistryPrefix,
|
||||
@@ -10,7 +10,9 @@ param(
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Continue'
|
||||
$mirror = "$RegistryPrefix/node:20-bookworm-slim"
|
||||
$prefix = $RegistryPrefix.Trim().TrimEnd('/')
|
||||
$dyolink = "$prefix/dyolink-node:20-bookworm-slim"
|
||||
$mirror = "$prefix/node:20-bookworm-slim"
|
||||
$nl = [char]10
|
||||
|
||||
function Test-Image([string]$Name) {
|
||||
@@ -35,22 +37,33 @@ function Save-Choice([string]$Name) {
|
||||
Write-Host "NODE_IMAGE=$Name"
|
||||
}
|
||||
|
||||
function Publish-Mirror([string]$Src) {
|
||||
Write-Host "Tagging $Src as $mirror"
|
||||
docker tag $Src $mirror
|
||||
function Publish-Mirror([string]$Src, [string]$Dest) {
|
||||
Write-Host "Tagging $Src as $Dest"
|
||||
docker tag $Src $Dest
|
||||
if ($LASTEXITCODE -ne 0) { return $false }
|
||||
docker push $mirror
|
||||
docker push $Dest
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Could not push $mirror - docker build will use the local tag (legacy builder)."
|
||||
Write-Host "Could not push $Dest - docker build will use the local tag (legacy builder)."
|
||||
$flag = Join-Path (Get-Location) '.ci-use-legacy-builder'
|
||||
New-Item -ItemType File -Path $flag -Force | Out-Null
|
||||
}
|
||||
Save-Choice $mirror
|
||||
Save-Choice $Dest
|
||||
return $true
|
||||
}
|
||||
|
||||
if (Test-Image $dyolink) {
|
||||
Write-Host "Using local $dyolink"
|
||||
Save-Choice $dyolink
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (Invoke-Pull $dyolink 1) {
|
||||
Save-Choice $dyolink
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (Test-Image $mirror) {
|
||||
Write-Host "Using local $mirror"
|
||||
Write-Host "Using local $mirror (no dumb-init; Dockerfile may apt-get)"
|
||||
Save-Choice $mirror
|
||||
exit 0
|
||||
}
|
||||
@@ -67,7 +80,6 @@ if (-not [string]::IsNullOrWhiteSpace($ExtraSources)) {
|
||||
if ($src.Length -gt 0) { [void]$sources.Add($src) }
|
||||
}
|
||||
}
|
||||
# Iran-reachable proxy of Docker Hub official images, then public official mirrors, Hub last.
|
||||
foreach ($src in @(
|
||||
'docker.arvancloud.ir/library/node:20-bookworm-slim',
|
||||
'public.ecr.aws/docker/library/node:20-bookworm-slim',
|
||||
@@ -80,21 +92,17 @@ foreach ($src in @(
|
||||
foreach ($src in $sources) {
|
||||
if (Test-Image $src) {
|
||||
Write-Host "Found local $src"
|
||||
if (Publish-Mirror $src) { exit 0 }
|
||||
if (Publish-Mirror $src $mirror) { exit 0 }
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($src in $sources) {
|
||||
if (Invoke-Pull $src 2) {
|
||||
if (Publish-Mirror $src) { exit 0 }
|
||||
if (Publish-Mirror $src $mirror) { exit 0 }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Could not pull node:20-bookworm-slim from Gitea, mirrors, or Docker Hub."
|
||||
Write-Host "Set repository variable NODE_IMAGE_SOURCE to a reachable image, for example:"
|
||||
Write-Host " docker.arvancloud.ir/library/node:20-bookworm-slim"
|
||||
Write-Host "Or on the Windows runner:"
|
||||
Write-Host " docker pull docker.arvancloud.ir/library/node:20-bookworm-slim"
|
||||
Write-Host " docker tag docker.arvancloud.ir/library/node:20-bookworm-slim $mirror"
|
||||
Write-Host " docker push $mirror"
|
||||
Write-Host "While online run: infrastructure/scripts/seed-gitea-base-images.ps1"
|
||||
Write-Host "Set repository variable NODE_IMAGE_SOURCE if you have another reachable image."
|
||||
exit 1
|
||||
|
||||
40
infrastructure/scripts/ci-resolve-npm-registry.ps1
Normal file
40
infrastructure/scripts/ci-resolve-npm-registry.ps1
Normal file
@@ -0,0 +1,40 @@
|
||||
# Write .ci-npm-registry for docker --build-arg NPM_REGISTRY.
|
||||
# Default: Verdaccio on the Windows Docker host. Override with Gitea var NPM_REGISTRY.
|
||||
# ASCII only: Windows PowerShell 5.1 + act_runner.
|
||||
param(
|
||||
[AllowEmptyString()]
|
||||
[string]$Registry = '',
|
||||
[string]$OutFile = '.ci-npm-registry',
|
||||
[string]$DefaultRegistry = 'http://host.docker.internal:4873'
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$nl = [char]10
|
||||
$reg = $Registry.Trim()
|
||||
if ([string]::IsNullOrWhiteSpace($reg) -or $reg -like '*NPM_REGISTRY*') {
|
||||
$reg = $DefaultRegistry
|
||||
}
|
||||
|
||||
$utf8 = New-Object System.Text.UTF8Encoding $false
|
||||
$path = Join-Path (Get-Location) $OutFile
|
||||
[System.IO.File]::WriteAllText($path, ($reg + $nl), $utf8)
|
||||
Write-Host "NPM_REGISTRY=$reg"
|
||||
|
||||
# Docker build runs in the Desktop VM (host.docker.internal). This script runs on Windows.
|
||||
$pingBase = $reg
|
||||
if ($reg -match 'host\.docker\.internal') {
|
||||
$pingBase = $reg -replace 'host\.docker\.internal', '127.0.0.1'
|
||||
}
|
||||
$ping = $pingBase.TrimEnd('/') + '/-/ping'
|
||||
try {
|
||||
$resp = Invoke-WebRequest -Uri $ping -UseBasicParsing -TimeoutSec 8
|
||||
Write-Host "Verdaccio ping $ping -> $($resp.StatusCode)"
|
||||
} catch {
|
||||
Write-Host "Cannot reach $ping"
|
||||
Write-Host "Start Verdaccio on the Windows host (port 4873) before CI builds:"
|
||||
Write-Host " cd infrastructure"
|
||||
Write-Host " docker compose -f docker-compose.verdaccio.yml up -d"
|
||||
Write-Host "First online staging build fills the cache. During a blackout, keep Verdaccio running."
|
||||
exit 1
|
||||
}
|
||||
exit 0
|
||||
@@ -19,6 +19,17 @@ fi
|
||||
|
||||
export TAG
|
||||
|
||||
# Default runtime bases to Gitea copies when .env has REGISTRY_PREFIX but no *IMAGE lines.
|
||||
DEPLOY_TAG="$TAG"
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
. ./.env
|
||||
set +a
|
||||
export TAG="$DEPLOY_TAG"
|
||||
export POSTGRES_IMAGE="${POSTGRES_IMAGE:-${REGISTRY_PREFIX}/postgres:15-alpine}"
|
||||
export NGINX_IMAGE="${NGINX_IMAGE:-${REGISTRY_PREFIX}/nginx:alpine}"
|
||||
export CERTBOT_IMAGE="${CERTBOT_IMAGE:-${REGISTRY_PREFIX}/certbot:latest}"
|
||||
|
||||
# Windows Gitea often RSTs concurrent or long pulls (connection reset by peer).
|
||||
# Pull one image at a time with backoff so a flake does not fail the whole tag.
|
||||
pull_one() {
|
||||
@@ -42,9 +53,12 @@ pull_one() {
|
||||
done
|
||||
}
|
||||
|
||||
echo "Pulling backend/frontend :$TAG from Gitea (REGISTRY_PREFIX in .env)"
|
||||
echo "Pulling backend/frontend :$TAG and runtime bases from Gitea (REGISTRY_PREFIX in .env)"
|
||||
pull_one backend
|
||||
pull_one frontend
|
||||
pull_one postgres
|
||||
pull_one nginx
|
||||
pull_one certbot
|
||||
|
||||
if [ -f nginx/nginx.ssl.conf.template ]; then
|
||||
echo "Rendering nginx SSL config (includes /admin → backend)"
|
||||
|
||||
172
infrastructure/scripts/seed-gitea-base-images.ps1
Normal file
172
infrastructure/scripts/seed-gitea-base-images.ps1
Normal file
@@ -0,0 +1,172 @@
|
||||
# Copy Hub (or Arvan) base images into the Gitea registry so CI/compose can run
|
||||
# when Docker Hub is unreachable. ASCII only: Windows PowerShell 5.1 + act_runner.
|
||||
#
|
||||
# Run from repo root after docker login to REGISTRY_HOST:
|
||||
# .\infrastructure\scripts\seed-gitea-base-images.ps1 -RegistryPrefix "host.docker.internal:3000/admin"
|
||||
#
|
||||
# Also invoked by Gitea workflows after docker login.
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$RegistryPrefix,
|
||||
[AllowEmptyString()]
|
||||
[string]$ExtraSources = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Continue'
|
||||
$prefix = $RegistryPrefix.Trim().TrimEnd('/')
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$repoRoot = (Resolve-Path (Join-Path $scriptDir '..\..')).Path
|
||||
$nodeDockerfile = Join-Path $repoRoot 'infrastructure\docker\dyolink-node.Dockerfile'
|
||||
|
||||
function Test-Image([string]$Name) {
|
||||
docker image inspect $Name 2>&1 | Out-Null
|
||||
return ($LASTEXITCODE -eq 0)
|
||||
}
|
||||
|
||||
function Invoke-Pull([string]$Name, [int]$Attempts) {
|
||||
for ($i = 1; $i -le $Attempts; $i++) {
|
||||
Write-Host "docker pull $Name (attempt $i/$Attempts)"
|
||||
docker pull $Name
|
||||
if ($LASTEXITCODE -eq 0) { return $true }
|
||||
if ($i -lt $Attempts) { Start-Sleep -Seconds 5 }
|
||||
}
|
||||
return $false
|
||||
}
|
||||
|
||||
function Publish-ToGitea([string]$Src, [string]$Dest) {
|
||||
if ($Src -ne $Dest) {
|
||||
Write-Host "Tagging $Src as $Dest"
|
||||
docker tag $Src $Dest
|
||||
if ($LASTEXITCODE -ne 0) { return $false }
|
||||
}
|
||||
Write-Host "docker push $Dest"
|
||||
docker push $Dest
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Could not push $Dest - local tag remains for this machine."
|
||||
return $false
|
||||
}
|
||||
return $true
|
||||
}
|
||||
|
||||
function Ensure-GiteaImage([string]$Dest, [string[]]$Sources) {
|
||||
if (Test-Image $Dest) {
|
||||
Write-Host "Already local: $Dest"
|
||||
docker push $Dest 2>&1 | Out-Null
|
||||
return $true
|
||||
}
|
||||
if (Invoke-Pull $Dest 1) {
|
||||
Write-Host "Pulled from Gitea: $Dest"
|
||||
return $true
|
||||
}
|
||||
foreach ($src in $Sources) {
|
||||
if ([string]::IsNullOrWhiteSpace($src)) { continue }
|
||||
if (Test-Image $src) {
|
||||
Write-Host "Found local $src"
|
||||
if (Publish-ToGitea $src $Dest) { return $true }
|
||||
}
|
||||
}
|
||||
foreach ($src in $Sources) {
|
||||
if ([string]::IsNullOrWhiteSpace($src)) { continue }
|
||||
if (Invoke-Pull $src 2) {
|
||||
if (Publish-ToGitea $src $Dest) { return $true }
|
||||
}
|
||||
}
|
||||
Write-Host "FAILED to seed $Dest"
|
||||
return $false
|
||||
}
|
||||
|
||||
Write-Host "Seeding Gitea base images at $prefix"
|
||||
|
||||
$extraList = New-Object System.Collections.ArrayList
|
||||
if (-not [string]::IsNullOrWhiteSpace($ExtraSources)) {
|
||||
foreach ($part in ($ExtraSources -split ',')) {
|
||||
$s = $part.Trim()
|
||||
if ($s.Length -gt 0) { [void]$extraList.Add($s) }
|
||||
}
|
||||
}
|
||||
|
||||
$ok = $true
|
||||
|
||||
$nodeDest = "$prefix/node:20-bookworm-slim"
|
||||
$nodeSources = New-Object System.Collections.ArrayList
|
||||
foreach ($s in $extraList) { [void]$nodeSources.Add($s) }
|
||||
foreach ($s in @(
|
||||
'docker.arvancloud.ir/library/node:20-bookworm-slim',
|
||||
'public.ecr.aws/docker/library/node:20-bookworm-slim',
|
||||
'mirror.gcr.io/library/node:20-bookworm-slim',
|
||||
'node:20-bookworm-slim'
|
||||
)) {
|
||||
if (-not $nodeSources.Contains($s)) { [void]$nodeSources.Add($s) }
|
||||
}
|
||||
if (-not (Ensure-GiteaImage $nodeDest @($nodeSources.ToArray()))) { $ok = $false }
|
||||
|
||||
$pgDest = "$prefix/postgres:15-alpine"
|
||||
if (-not (Ensure-GiteaImage $pgDest @(
|
||||
'docker.arvancloud.ir/library/postgres:15-alpine',
|
||||
'postgres:15-alpine'
|
||||
))) { $ok = $false }
|
||||
|
||||
$ngxDest = "$prefix/nginx:alpine"
|
||||
if (-not (Ensure-GiteaImage $ngxDest @(
|
||||
'docker.arvancloud.ir/library/nginx:alpine',
|
||||
'nginx:alpine'
|
||||
))) { $ok = $false }
|
||||
|
||||
$cbDest = "$prefix/certbot:latest"
|
||||
if (-not (Ensure-GiteaImage $cbDest @(
|
||||
'docker.arvancloud.ir/certbot/certbot:latest',
|
||||
'certbot/certbot:latest'
|
||||
))) {
|
||||
Write-Host "WARN: certbot not seeded (prod Linux only). Re-run while online."
|
||||
}
|
||||
|
||||
$verDest = "$prefix/verdaccio:5"
|
||||
if (-not (Ensure-GiteaImage $verDest @(
|
||||
'docker.arvancloud.ir/verdaccio/verdaccio:5',
|
||||
'verdaccio/verdaccio:5'
|
||||
))) {
|
||||
Write-Host "WARN: verdaccio image not in Gitea. Keep the running container; do not prune."
|
||||
}
|
||||
|
||||
$dyoDest = "$prefix/dyolink-node:20-bookworm-slim"
|
||||
if (Test-Image $dyoDest) {
|
||||
Write-Host "Already local: $dyoDest"
|
||||
docker push $dyoDest 2>&1 | Out-Null
|
||||
} elseif (Invoke-Pull $dyoDest 1) {
|
||||
Write-Host "Pulled from Gitea: $dyoDest"
|
||||
} else {
|
||||
if (-not (Test-Path $nodeDockerfile)) {
|
||||
Write-Host "Missing $nodeDockerfile"
|
||||
$ok = $false
|
||||
} elseif (-not (Test-Image $nodeDest)) {
|
||||
Write-Host "Cannot build dyolink-node without $nodeDest"
|
||||
$ok = $false
|
||||
} else {
|
||||
Write-Host "Building $dyoDest from $nodeDest (installs dumb-init; needs apt once)"
|
||||
$ctx = Join-Path $repoRoot 'infrastructure\docker'
|
||||
docker build --build-arg "NODE_IMAGE=$nodeDest" -t $dyoDest -f $nodeDockerfile $ctx
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "FAILED to build $dyoDest"
|
||||
$ok = $false
|
||||
} else {
|
||||
docker push $dyoDest
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Could not push $dyoDest - local tag remains."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $ok) {
|
||||
Write-Host "One or more base images could not be seeded. App builds may still work if Gitea already has dyolink-node."
|
||||
Write-Host "While online, re-run this script. Do not docker system prune -a on the runner."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Gitea base images ready:"
|
||||
Write-Host " $dyoDest"
|
||||
Write-Host " $nodeDest"
|
||||
Write-Host " $pgDest"
|
||||
Write-Host " $ngxDest"
|
||||
Write-Host " $cbDest"
|
||||
Write-Host " $verDest"
|
||||
exit 0
|
||||
47
infrastructure/verdaccio/config.yaml
Normal file
47
infrastructure/verdaccio/config.yaml
Normal file
@@ -0,0 +1,47 @@
|
||||
# Local npm warehouse on the Windows build PC.
|
||||
# Online: miss → fetch from registry.npmjs.org → save to storage.
|
||||
# Blackout: serve cached tarballs only (short uplink timeout so builds do not hang).
|
||||
#
|
||||
# Official image paths: conf=/verdaccio/conf config.yaml, storage=/verdaccio/storage
|
||||
|
||||
storage: /verdaccio/storage
|
||||
plugins: /verdaccio/plugins
|
||||
|
||||
web:
|
||||
title: Dyolink npm cache
|
||||
darkMode: false
|
||||
|
||||
auth:
|
||||
htpasswd:
|
||||
file: /verdaccio/storage/htpasswd
|
||||
max_users: -1
|
||||
|
||||
uplinks:
|
||||
npmjs:
|
||||
url: https://registry.npmjs.org/
|
||||
timeout: 8s
|
||||
max_fails: 2
|
||||
fail_timeout: 30m
|
||||
cache: true
|
||||
|
||||
packages:
|
||||
'@*/*':
|
||||
access: $all
|
||||
publish: $all
|
||||
unpublish: $authenticated
|
||||
proxy: npmjs
|
||||
'**':
|
||||
access: $all
|
||||
publish: $all
|
||||
unpublish: $authenticated
|
||||
proxy: npmjs
|
||||
|
||||
server:
|
||||
keepAliveTimeout: 60
|
||||
|
||||
middlewares:
|
||||
audit:
|
||||
enabled: false
|
||||
|
||||
logs:
|
||||
- { type: stdout, format: pretty, level: http }
|
||||
Reference in New Issue
Block a user