Provision OpsProof test database
This commit is contained in:
parent
f88f92293c
commit
193a44b1f1
|
|
@ -34,11 +34,14 @@ The Debian installation is owned by the Jeannie pipeline:
|
|||
./jeannie deploy-opsproof
|
||||
```
|
||||
|
||||
The command downloads a checksum-pinned Go 1.27 toolchain into the OpsProof
|
||||
data directory, checks out an exact Laravel Go starter commit, normalizes the UI
|
||||
overlay with that starter's pinned formatter, runs its frontend checks and
|
||||
build, runs its Go tests, builds the binary, installs a hardened systemd unit,
|
||||
and verifies `/up`. It does not replace Debian's system Go.
|
||||
The command starts a dedicated, persistent PostgreSQL container, downloads a
|
||||
checksum-pinned Go 1.27 toolchain into the OpsProof data directory, checks out
|
||||
an exact Laravel Go starter commit, normalizes the UI overlay with that
|
||||
starter's pinned formatter, runs its frontend checks and build, runs the Go
|
||||
feature tests against PostgreSQL, builds the binary, applies database
|
||||
migrations, installs a hardened systemd unit, and verifies `/up`. Database
|
||||
credentials are generated once and retained in the private OpsProof data
|
||||
directory. It does not replace Debian's system Go.
|
||||
|
||||
## Security boundary
|
||||
|
||||
|
|
|
|||
|
|
@ -651,6 +651,11 @@ checksum-verified and does not replace Debian's system Go.
|
|||
: Pin the Laravel Go starter source used for the OpsProof build. The commit must
|
||||
be a full Git SHA.
|
||||
|
||||
`LAB_OPSPROOF_POSTGRES_IMAGE`, `LAB_OPSPROOF_POSTGRES_PORT`
|
||||
: Override the pinned OpsProof PostgreSQL image and its loopback-only host port.
|
||||
Defaults are `docker.io/postgres:18-alpine` and `55439`. The deployment
|
||||
preserves generated database credentials and data under the OpsProof root.
|
||||
|
||||
`LAB_RPI_INSTALL_DOCKER=true`
|
||||
: Allow `rpi-services` to install Docker through `get.docker.com` on the
|
||||
Raspberry Pi when Docker is missing. Default is to fail.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ OpsProof on Debian
|
|||
|-- session, Dex identity, authorization
|
||||
|-- incident/proposal/audit records
|
||||
|-- redaction and public-demo projection
|
||||
|-- dedicated PostgreSQL database
|
||||
|
|
||||
| authenticated structured requests
|
||||
v
|
||||
|
|
@ -51,6 +52,8 @@ confirmed by deterministic validation.
|
|||
## Deployment constraints
|
||||
|
||||
- Run on Debian so a Kubernetes outage does not remove the incident UI.
|
||||
- Keep OpsProof records in its own persistent PostgreSQL service and use the
|
||||
same database contract for feature tests, migrations, and runtime.
|
||||
- Build with a pinned Laravel Go dependency and Go 1.27 or newer.
|
||||
- Publish a health endpoint independently from Jeannie health.
|
||||
- Send Laravel Go's OpenTelemetry traces to the existing Debian monitoring
|
||||
|
|
|
|||
|
|
@ -5676,11 +5676,19 @@ deploy_opsproof() {
|
|||
local starter_repo="${LAB_OPSPROOF_STARTER_REPO:-https://github.com/laravel/go.git}"
|
||||
local overlay_dir="${REPO_ROOT}/apps/opsproof/overlay"
|
||||
local service_user="${LAB_OPSPROOF_SERVICE_USER:-$(id -un)}"
|
||||
local postgres_image="${LAB_OPSPROOF_POSTGRES_IMAGE:-docker.io/postgres:18-alpine}"
|
||||
local postgres_port="${LAB_OPSPROOF_POSTGRES_PORT:-55439}"
|
||||
local postgres_container="${LAB_OPSPROOF_POSTGRES_CONTAINER:-opsproof-postgres}"
|
||||
local postgres_db="${LAB_OPSPROOF_POSTGRES_DB:-opsproof}"
|
||||
local postgres_user="${LAB_OPSPROOF_POSTGRES_USER:-opsproof}"
|
||||
local toolchain_dir="${install_dir}/toolchains/go${go_version}"
|
||||
local release_dir="${install_dir}/releases/${starter_commit}"
|
||||
local database_env="${install_dir}/.database.env"
|
||||
local build_dir=""
|
||||
local archive=""
|
||||
local app_key=""
|
||||
local postgres_password=""
|
||||
local database_url=""
|
||||
local elapsed=0
|
||||
local node_major=""
|
||||
local required
|
||||
|
|
@ -5707,8 +5715,18 @@ deploy_opsproof() {
|
|||
echo "LAB_OPSPROOF_SERVICE_USER is invalid." >&2
|
||||
return 1
|
||||
fi
|
||||
if ! [[ "${postgres_port}" =~ ^[0-9]+$ ]] || ((postgres_port < 1 || postgres_port > 65535)); then
|
||||
echo "LAB_OPSPROOF_POSTGRES_PORT must be a valid TCP port." >&2
|
||||
return 1
|
||||
fi
|
||||
if ! [[ "${postgres_container}" =~ ^[a-zA-Z0-9][a-zA-Z0-9_.-]+$ ]] ||
|
||||
! [[ "${postgres_db}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] ||
|
||||
! [[ "${postgres_user}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
|
||||
echo "OpsProof PostgreSQL container, database, or user name is invalid." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
for required in curl git npm openssl sha256sum systemctl tar; do
|
||||
for required in curl docker git npm openssl sha256sum systemctl tar; do
|
||||
if ! command -v "${required}" >/dev/null 2>&1; then
|
||||
echo "OpsProof deployment requires ${required} on Debian." >&2
|
||||
return 1
|
||||
|
|
@ -5726,6 +5744,51 @@ deploy_opsproof() {
|
|||
|
||||
sudo install -d -o "${service_user}" -g "${service_user}" -m 0750 \
|
||||
"${install_dir}" "${install_dir}/releases" "${install_dir}/toolchains"
|
||||
sudo install -d -m 0700 "${install_dir}/postgres"
|
||||
|
||||
if [[ -s "${database_env}" ]]; then
|
||||
postgres_password="$(sed -n 's/^POSTGRES_PASSWORD=//p' "${database_env}" | head -n 1)"
|
||||
fi
|
||||
if ! [[ "${postgres_password}" =~ ^[[:xdigit:]]{64}$ ]]; then
|
||||
postgres_password="$(openssl rand -hex 32)"
|
||||
fi
|
||||
umask 077
|
||||
printf '%s\n' \
|
||||
"POSTGRES_DB=${postgres_db}" \
|
||||
"POSTGRES_USER=${postgres_user}" \
|
||||
"POSTGRES_PASSWORD=${postgres_password}" >"${database_env}"
|
||||
chmod 0600 "${database_env}"
|
||||
database_url="postgres://${postgres_user}:${postgres_password}@127.0.0.1:${postgres_port}/${postgres_db}?sslmode=disable"
|
||||
|
||||
cat >"${install_dir}/compose.yaml" <<COMPOSE_EOF
|
||||
services:
|
||||
database:
|
||||
image: ${postgres_image}
|
||||
container_name: ${postgres_container}
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .database.env
|
||||
ports:
|
||||
- "127.0.0.1:${postgres_port}:5432"
|
||||
volumes:
|
||||
- ./postgres:/var/lib/postgresql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${postgres_user} -d ${postgres_db}"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
COMPOSE_EOF
|
||||
(cd "${install_dir}" && sudo docker compose --env-file "${database_env}" up -d database)
|
||||
elapsed=0
|
||||
until [[ "$(sudo docker inspect --format '{{.State.Health.Status}}' "${postgres_container}" 2>/dev/null)" == "healthy" ]]; do
|
||||
if ((elapsed >= 120)); then
|
||||
echo "Timed out waiting for the OpsProof PostgreSQL service." >&2
|
||||
(cd "${install_dir}" && sudo docker compose ps && sudo docker compose logs --tail=120 database) >&2 || true
|
||||
return 1
|
||||
fi
|
||||
sleep 3
|
||||
elapsed=$((elapsed + 3))
|
||||
done
|
||||
|
||||
if [[ ! -x "${toolchain_dir}/bin/go" ]]; then
|
||||
archive="$(mktemp "${install_dir}/go${go_version}.XXXXXX.tar.gz")"
|
||||
|
|
@ -5760,7 +5823,7 @@ deploy_opsproof() {
|
|||
npm run check:fix
|
||||
npm run check
|
||||
npm run build
|
||||
PATH="${toolchain_dir}/bin:${PATH}" GOTOOLCHAIN=local go test ./...
|
||||
DATABASE_URL="${database_url}" PATH="${toolchain_dir}/bin:${PATH}" GOTOOLCHAIN=local go test ./...
|
||||
PATH="${toolchain_dir}/bin:${PATH}" GOTOOLCHAIN=local go build -trimpath -o opsproof .
|
||||
)
|
||||
|
||||
|
|
@ -5784,6 +5847,7 @@ deploy_opsproof() {
|
|||
"APP_URL=http://${bind_ip}:${http_port}" \
|
||||
"SERVER_HOST=${bind_ip}" \
|
||||
"SERVER_PORT=${http_port}" \
|
||||
"DATABASE_URL=${database_url}" \
|
||||
"SESSION_DRIVER=file" \
|
||||
"CACHE_STORE=file" \
|
||||
"QUEUE_CONNECTION=sync" \
|
||||
|
|
@ -5791,11 +5855,20 @@ deploy_opsproof() {
|
|||
"LOG_LEVEL=info" >"${install_dir}/.env"
|
||||
chmod 0600 "${install_dir}/.env"
|
||||
|
||||
sudo -u "${service_user}" env \
|
||||
APP_ENV=production \
|
||||
APP_KEY="${app_key}" \
|
||||
DATABASE_URL="${database_url}" \
|
||||
CACHE_STORE=file \
|
||||
SESSION_DRIVER=file \
|
||||
QUEUE_CONNECTION=sync \
|
||||
"${release_dir}/opsproof" migrate --force
|
||||
|
||||
sudo tee /etc/systemd/system/opsproof.service >/dev/null <<UNIT_EOF
|
||||
[Unit]
|
||||
Description=OpsProof evidence-first operations UI
|
||||
After=network-online.target jeannie-server.service
|
||||
Wants=network-online.target
|
||||
After=network-online.target docker.service jeannie-server.service
|
||||
Wants=network-online.target docker.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
|
|
@ -5828,7 +5901,7 @@ UNIT_EOF
|
|||
sleep 3
|
||||
elapsed=$((elapsed + 3))
|
||||
done
|
||||
echo "OpsProof Laravel Go shell is healthy at http://${bind_ip}:${http_port}/."
|
||||
echo "OpsProof Laravel Go shell and PostgreSQL service are healthy at http://${bind_ip}:${http_port}/."
|
||||
}
|
||||
|
||||
deploy_matrix() {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,16 @@ class OpsProofPipelineTests(unittest.TestCase):
|
|||
self.assertIn("npm run check", pipeline)
|
||||
self.assertIn('cp -a "${overlay_dir}/." "${build_dir}/"', pipeline)
|
||||
self.assertIn("GOTOOLCHAIN=local go test ./...", pipeline)
|
||||
self.assertIn(
|
||||
'postgres_image="${LAB_OPSPROOF_POSTGRES_IMAGE:-docker.io/postgres:18-alpine}"',
|
||||
pipeline,
|
||||
)
|
||||
self.assertIn('DATABASE_URL="${database_url}"', pipeline)
|
||||
self.assertIn('"${release_dir}/opsproof" migrate --force', pipeline)
|
||||
self.assertLess(
|
||||
pipeline.index('docker compose --env-file "${database_env}" up -d database'),
|
||||
pipeline.index("GOTOOLCHAIN=local go test ./..."),
|
||||
)
|
||||
self.assertIn("opsproof.service", pipeline)
|
||||
self.assertIn("deploy-opsproof)", command)
|
||||
self.assertIn('"deploy-opsproof": true', server)
|
||||
|
|
|
|||
Loading…
Reference in New Issue