Complete SSO role mapping and offline StateCorp release tooling
Some checks failed
State Corp Backend CI/CD / Quality gate (push) Failing after 9m34s
State Corp Backend CI/CD / Build linux/amd64 images once (push) Has been skipped
State Corp Backend CI/CD / Release dev (push) Has been skipped
State Corp Backend CI/CD / Refresh and release internal main (push) Has been skipped
State Corp Backend CI/CD / Release customer main (push) Has been skipped
Some checks failed
State Corp Backend CI/CD / Quality gate (push) Failing after 9m34s
State Corp Backend CI/CD / Build linux/amd64 images once (push) Has been skipped
State Corp Backend CI/CD / Release dev (push) Has been skipped
State Corp Backend CI/CD / Refresh and release internal main (push) Has been skipped
State Corp Backend CI/CD / Release customer main (push) Has been skipped
This commit is contained in:
6
deploy/offline/.gitignore
vendored
Normal file
6
deploy/offline/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
release/
|
||||
.env
|
||||
secrets/
|
||||
data/
|
||||
media/
|
||||
staticfiles/
|
||||
29
deploy/offline/README.md
Normal file
29
deploy/offline/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# StateCorp isolated installation
|
||||
|
||||
`build-release.sh FRONTEND_CHECKOUT RELEASE_DIRECTORY RELEASE_ID` builds five
|
||||
`linux/amd64` OCI image archives and an immutable release manifest. Run it on a
|
||||
connected build host with Docker Buildx and `jq`; the target host needs only Docker
|
||||
and Compose. The release directory can be transported as a tar archive. It contains
|
||||
no database, media, private key, shared exchange token, or populated `.env`.
|
||||
|
||||
On the isolated host, unpack the release, run `./install.sh install` once to create
|
||||
`.env`, set strong local credentials and host names there, then run it again. Supply
|
||||
the IAS ECP public PEM separately at `secrets/sso-public.pem`; only enable SSO after
|
||||
validating the callback and `SSO_GROUP_ROLE_MAP_JSON` allowlist. The PEM is mounted
|
||||
read-only at `/run/secrets/sso_public_key` and is not stored in the archive.
|
||||
|
||||
`./install.sh health` checks Compose state and the backend readiness endpoint.
|
||||
For an upgrade, retain a verified database backup separately and replace only
|
||||
the release files (`compose.yml`, `env.example`, `install.sh`, `README.md`,
|
||||
`release-manifest.json`, `SHA256SUMS`, and `images/`) **in the existing installation
|
||||
directory**. Do not replace `.env` or `secrets/`, and do not remove the
|
||||
Compose-managed database, Redis, media, or staticfiles volumes.
|
||||
Then run `./install.sh upgrade`; it preserves local credentials and switches image
|
||||
pins to the new release. `rollback`
|
||||
reselects previous image names from `.env.previous` only; it does not reverse schema
|
||||
migrations or restore a database. A full rollback requires the separate backup.
|
||||
|
||||
The initial database is empty and migrations run before web/worker/Beat/frontend.
|
||||
Import business data later through the encrypted exchange CLI/API; never place the
|
||||
exchange package or its token inside this release. All services set
|
||||
`pull_policy: never`, so installation cannot silently contact a registry.
|
||||
84
deploy/offline/build-release.sh
Executable file
84
deploy/offline/build-release.sh
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Usage: build-release.sh FRONTEND_CHECKOUT RELEASE_DIRECTORY RELEASE_ID
|
||||
# The output directory must not exist and should be outside all source trees.
|
||||
backend_root=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
frontend_root=$(cd "${1:?frontend checkout required}" && pwd)
|
||||
release_dir=${2:?release directory required}
|
||||
release_id=${3:?release id required}
|
||||
case "$release_id" in
|
||||
*[!a-zA-Z0-9._-]*|'') echo 'Invalid release id' >&2; exit 2 ;;
|
||||
esac
|
||||
if [[ -e "$release_dir" ]]; then
|
||||
echo 'Release directory already exists; refusing to overwrite it' >&2
|
||||
exit 2
|
||||
fi
|
||||
mkdir -p "$release_dir/images"
|
||||
release_dir=$(cd "$release_dir" && pwd)
|
||||
|
||||
web_image="ecos-state-corp-web:$release_id"
|
||||
worker_image="ecos-state-corp-worker:$release_id"
|
||||
frontend_image="ecos-state-corp-frontend:$release_id"
|
||||
postgres_image="ecos-offline-postgres:$release_id"
|
||||
redis_image="ecos-offline-redis:$release_id"
|
||||
|
||||
docker buildx build --platform linux/amd64 --target runtime-web \
|
||||
-f "$backend_root/docker/Dockerfile" -t "$web_image" \
|
||||
--output "type=oci,dest=$release_dir/images/web.tar" "$backend_root"
|
||||
docker buildx build --platform linux/amd64 --target runtime-celery \
|
||||
-f "$backend_root/docker/Dockerfile" -t "$worker_image" \
|
||||
--output "type=oci,dest=$release_dir/images/worker.tar" "$backend_root"
|
||||
docker buildx build --platform linux/amd64 -f "$frontend_root/Dockerfile" \
|
||||
-t "$frontend_image" --output "type=oci,dest=$release_dir/images/frontend.tar" \
|
||||
"$frontend_root"
|
||||
|
||||
# Resolve the upstream multi-arch tags once, then build the amd64 variant from
|
||||
# the immutable manifest digest. The release records both upstream digests.
|
||||
postgres_digest=$(docker buildx imagetools inspect postgres:15.10 --format '{{.Manifest.Digest}}')
|
||||
redis_digest=$(docker buildx imagetools inspect redis:7.4.2-alpine --format '{{.Manifest.Digest}}')
|
||||
printf 'FROM postgres@%s\n' "$postgres_digest" | docker buildx build \
|
||||
--platform linux/amd64 -f - -t "$postgres_image" \
|
||||
--output "type=oci,dest=$release_dir/images/postgres.tar" "$backend_root/deploy/offline"
|
||||
printf 'FROM redis@%s\n' "$redis_digest" | docker buildx build \
|
||||
--platform linux/amd64 -f - -t "$redis_image" \
|
||||
--output "type=oci,dest=$release_dir/images/redis.tar" "$backend_root/deploy/offline"
|
||||
|
||||
cp "$backend_root/deploy/offline/compose.yml" "$release_dir/compose.yml"
|
||||
cp "$backend_root/deploy/offline/env.example" "$release_dir/env.example"
|
||||
cp "$backend_root/deploy/offline/install.sh" "$release_dir/install.sh"
|
||||
cp "$backend_root/deploy/offline/README.md" "$release_dir/README.md"
|
||||
chmod +x "$release_dir/install.sh"
|
||||
sed -i.bak \
|
||||
-e "s|ecos-state-corp-web:RELEASE|$web_image|" \
|
||||
-e "s|ecos-state-corp-worker:RELEASE|$worker_image|" \
|
||||
-e "s|ecos-state-corp-frontend:RELEASE|$frontend_image|" \
|
||||
-e "s|postgres:15.10|$postgres_image|" \
|
||||
-e "s|redis:7.4.2-alpine|$redis_image|" \
|
||||
"$release_dir/env.example"
|
||||
rm "$release_dir/env.example.bak"
|
||||
|
||||
archive_digest() {
|
||||
tar -xOf "$1" index.json | jq -r '.manifests[0].digest'
|
||||
}
|
||||
jq -n \
|
||||
--arg release "$release_id" \
|
||||
--arg backend_commit "$(git -C "$backend_root" rev-parse HEAD)" \
|
||||
--arg frontend_commit "$(git -C "$frontend_root" rev-parse HEAD)" \
|
||||
--arg postgres_upstream "$postgres_digest" \
|
||||
--arg redis_upstream "$redis_digest" \
|
||||
--arg web "$(archive_digest "$release_dir/images/web.tar")" \
|
||||
--arg worker "$(archive_digest "$release_dir/images/worker.tar")" \
|
||||
--arg frontend "$(archive_digest "$release_dir/images/frontend.tar")" \
|
||||
--arg postgres "$(archive_digest "$release_dir/images/postgres.tar")" \
|
||||
--arg redis "$(archive_digest "$release_dir/images/redis.tar")" \
|
||||
'{release_id:$release, platform:"linux/amd64", backend_commit:$backend_commit,
|
||||
frontend_commit:$frontend_commit,
|
||||
upstream:{postgres:$postgres_upstream,redis:$redis_upstream},
|
||||
images:{web:$web,worker:$worker,frontend:$frontend,postgres:$postgres,redis:$redis}}' \
|
||||
> "$release_dir/release-manifest.json"
|
||||
(
|
||||
cd "$release_dir"
|
||||
sha256sum compose.yml env.example install.sh README.md release-manifest.json images/*.tar > SHA256SUMS
|
||||
)
|
||||
echo "Release ready: $release_dir"
|
||||
125
deploy/offline/compose.yml
Normal file
125
deploy/offline/compose.yml
Normal file
@@ -0,0 +1,125 @@
|
||||
services:
|
||||
db:
|
||||
image: ${POSTGRES_IMAGE:?}
|
||||
pull_policy: never
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:?}
|
||||
POSTGRES_USER: ${POSTGRES_USER:?}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:?} -d ${POSTGRES_DB:?}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 12
|
||||
redis:
|
||||
image: ${REDIS_IMAGE:?}
|
||||
pull_policy: never
|
||||
restart: unless-stopped
|
||||
command: ["redis-server", "--appendonly", "yes"]
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 12
|
||||
migrate:
|
||||
image: ${STATE_WEB_IMAGE:?}
|
||||
pull_policy: never
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
environment:
|
||||
RUN_MIGRATIONS: "1"
|
||||
COLLECTSTATIC_ON_MIGRATE: "1"
|
||||
volumes:
|
||||
- media:/app/media
|
||||
- staticfiles:/app/staticfiles
|
||||
secrets:
|
||||
- sso_public_key
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
command: ["migrate"]
|
||||
restart: "no"
|
||||
web:
|
||||
image: ${STATE_WEB_IMAGE:?}
|
||||
pull_policy: never
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
environment:
|
||||
RUN_MIGRATIONS: "0"
|
||||
volumes:
|
||||
- media:/app/media
|
||||
- staticfiles:/app/staticfiles
|
||||
secrets:
|
||||
- sso_public_key
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-fsS", "http://localhost:8000/health/ready/"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 12
|
||||
worker:
|
||||
image: ${STATE_WORKER_IMAGE:?}
|
||||
pull_policy: never
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
environment:
|
||||
RUN_MIGRATIONS: "0"
|
||||
CELERY_WORKER_CONCURRENCY: "1"
|
||||
volumes:
|
||||
- media:/app/media
|
||||
secrets:
|
||||
- sso_public_key
|
||||
depends_on:
|
||||
web:
|
||||
condition: service_healthy
|
||||
command: ["celery-worker"]
|
||||
beat:
|
||||
image: ${STATE_WORKER_IMAGE:?}
|
||||
pull_policy: never
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
environment:
|
||||
RUN_MIGRATIONS: "0"
|
||||
secrets:
|
||||
- sso_public_key
|
||||
depends_on:
|
||||
web:
|
||||
condition: service_healthy
|
||||
command: ["celery-beat"]
|
||||
frontend:
|
||||
image: ${STATE_FRONTEND_IMAGE:?}
|
||||
pull_policy: never
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
BACKEND_UPSTREAM: web:8000
|
||||
SSO_ENABLED: ${SSO_ENABLED:-false}
|
||||
SSO_AUTO_REDIRECT: ${SSO_AUTO_REDIRECT:-false}
|
||||
ports:
|
||||
- "${STATE_FRONTEND_PORT:-8080}:80"
|
||||
depends_on:
|
||||
web:
|
||||
condition: service_healthy
|
||||
secrets:
|
||||
sso_public_key:
|
||||
file: ./secrets/sso-public.pem
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
media:
|
||||
staticfiles:
|
||||
29
deploy/offline/env.example
Normal file
29
deploy/offline/env.example
Normal file
@@ -0,0 +1,29 @@
|
||||
# Copy to .env on the isolated host. Never put this file with actual values in a release archive.
|
||||
STATE_WEB_IMAGE=ecos-state-corp-web:RELEASE
|
||||
STATE_WORKER_IMAGE=ecos-state-corp-worker:RELEASE
|
||||
STATE_FRONTEND_IMAGE=ecos-state-corp-frontend:RELEASE
|
||||
POSTGRES_IMAGE=postgres:15.10
|
||||
REDIS_IMAGE=redis:7.4.2-alpine
|
||||
POSTGRES_DB=state_corp
|
||||
POSTGRES_USER=state_corp
|
||||
POSTGRES_PASSWORD=CHANGE_ME
|
||||
SECRET_KEY=CHANGE_ME
|
||||
ALLOWED_HOSTS=localhost
|
||||
BACKEND_UPSTREAM=web:8000
|
||||
DJANGO_SETTINGS_MODULE=settings.production
|
||||
POSTGRES_HOST=db
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_SSLMODE=disable
|
||||
REDIS_URL=redis://redis:6379/0
|
||||
REDIS_CACHE_URL=redis://redis:6379/1
|
||||
CELERY_BROKER_URL=redis://redis:6379/0
|
||||
CELERY_RESULT_BACKEND=redis://redis:6379/0
|
||||
SECURE_SSL_REDIRECT=false
|
||||
SSO_ENABLED=false
|
||||
SSO_AUTO_REDIRECT=false
|
||||
SSO_PROVIDER_URL=https://divopk.vniicentr.ru/sso-redirect/
|
||||
SSO_SERVICE_CODE=fkc
|
||||
SSO_ISSUER=dvr
|
||||
SSO_PUBLIC_KEY_PATH=/run/secrets/sso_public_key
|
||||
SSO_GROUP_ROLE_MAP_JSON={}
|
||||
SSO_MANAGE_LINKED_USER_ROLES=false
|
||||
70
deploy/offline/install.sh
Executable file
70
deploy/offline/install.sh
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
action=${1:-install}
|
||||
case "$action" in
|
||||
install|upgrade|rollback|health) ;;
|
||||
*) echo 'Usage: install.sh {install|upgrade|rollback|health}' >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
if [[ "$action" == health ]]; then
|
||||
docker compose --env-file .env -f compose.yml ps
|
||||
docker compose --env-file .env -f compose.yml exec -T web \
|
||||
curl -fsS http://localhost:8000/health/ready/
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$action" == rollback ]]; then
|
||||
if [[ ! -f .env.previous ]]; then
|
||||
echo 'No previous local image configuration available' >&2
|
||||
exit 2
|
||||
fi
|
||||
cp .env.previous .env
|
||||
chmod 600 .env
|
||||
docker compose --env-file .env -f compose.yml up -d --wait
|
||||
echo 'Image rollback complete. Database schema was not reversed.'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sha256sum -c SHA256SUMS
|
||||
if [[ ! -f .env ]]; then
|
||||
cp env.example .env
|
||||
chmod 600 .env
|
||||
echo 'Edit .env with unique local credentials, then rerun install.sh' >&2
|
||||
exit 2
|
||||
fi
|
||||
if grep -q CHANGE_ME .env; then
|
||||
echo 'Replace all CHANGE_ME values in .env before installation' >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$action" == upgrade ]]; then
|
||||
cp .env .env.previous
|
||||
chmod 600 .env.previous
|
||||
# Keep local credentials and volumes, but select the images in this release.
|
||||
for key in STATE_WEB_IMAGE STATE_WORKER_IMAGE STATE_FRONTEND_IMAGE POSTGRES_IMAGE REDIS_IMAGE; do
|
||||
image=$(sed -n "s/^${key}=//p" env.example | head -n 1)
|
||||
if [[ -z "$image" ]] || ! grep -q "^${key}=" .env; then
|
||||
echo "Missing image pin: $key" >&2
|
||||
exit 2
|
||||
fi
|
||||
env_temp=$(mktemp .env.XXXXXX)
|
||||
sed "s|^${key}=.*|${key}=${image}|" .env > "$env_temp"
|
||||
chmod 600 "$env_temp"
|
||||
mv "$env_temp" .env
|
||||
done
|
||||
fi
|
||||
mkdir -p secrets
|
||||
if [[ ! -e secrets/sso-public.pem ]]; then
|
||||
: > secrets/sso-public.pem
|
||||
fi
|
||||
if grep -qi '^SSO_ENABLED=true$' .env && [[ ! -s secrets/sso-public.pem ]]; then
|
||||
echo 'SSO requires a real public PEM in secrets/sso-public.pem' >&2
|
||||
exit 2
|
||||
fi
|
||||
for archive in images/*.tar; do
|
||||
docker load -i "$archive"
|
||||
done
|
||||
docker compose --env-file .env -f compose.yml config -q
|
||||
docker compose --env-file .env -f compose.yml up -d --wait
|
||||
"$0" health
|
||||
Reference in New Issue
Block a user