feat(test-env): add 1C test environment (#11)

* feat(test-env): add 1C test environment manifests (#11)

- PostgreSQL 18.x-2.1C StatefulSet with ru_RU.UTF-8 locale init
- 1C server (ragent+crserver+ras) StatefulSet with stable hostname
- Gitea runner Deployment with edt label for apk-ci-ng
- NodePort services for external 1C access (31540-31545)
- Deploy/verify script: dev/deploy-test-env.sh
- config.yaml for ApplicationSet integration
- test-env only in dev cluster (not in prod AppSet)

* fix(test-env): use initContainer for PG data + remove custom entrypoint

PVC mount on /var/lib/postgresql wipes the image's pre-built cluster.
Solution: initContainer copies cluster data from image to PVC on first run.
Removed custom pg-entrypoint.sh ConfigMap — image has its own.

* feat(test-env): DinD sidecar for runner + auto-registration Job

- Add Docker-in-Docker sidecar to gitea-runner Deployment
- Add register-job.yaml: Job that obtains Gitea runner token via API,
  creates Secret, and scales runner to 1
- RBAC: ServiceAccount + Role/ClusterRole for cross-namespace secret access
- Runner labels: edt (for apk-ci-ng), ubuntu-latest

---------

Co-authored-by: XoR <xor@benadis.ru>
This commit is contained in:
Dear XoR
2026-03-12 12:33:50 +03:00
committed by GitHub
parent 01623cb260
commit efb2427586
16 changed files with 782 additions and 0 deletions

134
dev/deploy-test-env.sh Executable file
View File

@@ -0,0 +1,134 @@
#!/bin/bash
# deploy-test-env.sh — Deploy test-env to dev cluster and verify
#
# Usage:
# bash dev/deploy-test-env.sh [--check-only] [--create-secrets]
#
# Prerequisites:
# - kubectl configured for dev cluster
# - Images benadis/pg-1c:18.1-2.1C and benadis/ar-edt:6.2.27.1 accessible
#
# This script:
# 1. Validates kustomize build
# 2. Applies manifests via kustomize
# 3. Creates secrets if --create-secrets
# 4. Waits for pods to be ready
# 5. Runs smoke tests (pg_isready, ragent check)
set -euo pipefail
cd "$(dirname "$0")/.."
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
CHECK_ONLY=false
CREATE_SECRETS=false
for arg in "$@"; do
case $arg in
--check-only) CHECK_ONLY=true ;;
--create-secrets) CREATE_SECRETS=true ;;
esac
done
echo "=== test-env deployment ==="
# --- Step 1: Validate kustomize ---
echo -e "\n${YELLOW}[1/5] Validating kustomize build...${NC}"
if kubectl kustomize test-env/ > /dev/null 2>&1; then
echo -e "${GREEN} ✓ kustomize build OK${NC}"
else
echo -e "${RED} ✗ kustomize build FAILED${NC}"
kubectl kustomize test-env/ 2>&1 | head -20
exit 1
fi
if $CHECK_ONLY; then
echo -e "\n${GREEN}Validation passed (--check-only)${NC}"
kubectl kustomize test-env/ | grep -c 'kind:' | xargs -I{} echo " {} resources"
exit 0
fi
# --- Step 2: Apply manifests ---
echo -e "\n${YELLOW}[2/5] Applying manifests...${NC}"
kubectl apply -k test-env/
echo -e "${GREEN} ✓ Manifests applied${NC}"
# --- Step 3: Create secrets if needed ---
if $CREATE_SECRETS; then
echo -e "\n${YELLOW}[3/5] Creating secrets...${NC}"
kubectl -n test-env create secret generic test-env-secrets \
--from-literal=pg-password=usr1cv8 \
--dry-run=client -o yaml | kubectl apply -f -
echo -e "${GREEN} ✓ Secrets created${NC}"
else
echo -e "\n${YELLOW}[3/5] Checking secrets...${NC}"
if kubectl -n test-env get secret test-env-secrets > /dev/null 2>&1; then
echo -e "${GREEN} ✓ test-env-secrets exists${NC}"
else
echo -e "${RED} ✗ test-env-secrets missing — run with --create-secrets${NC}"
fi
fi
# --- Step 4: Wait for pods ---
echo -e "\n${YELLOW}[4/5] Waiting for pods (timeout 120s)...${NC}"
wait_for_pod() {
local label=$1
local timeout=${2:-120}
local start=$(date +%s)
while true; do
local phase=$(kubectl -n test-env get pods -l "$label" -o jsonpath='{.items[0].status.phase}' 2>/dev/null || echo "Pending")
if [ "$phase" = "Running" ]; then
echo -e "${GREEN}$label → Running${NC}"
return 0
fi
local elapsed=$(( $(date +%s) - start ))
if [ $elapsed -gt $timeout ]; then
echo -e "${RED}$label$phase (timeout ${timeout}s)${NC}"
return 1
fi
sleep 5
done
}
wait_for_pod "app=test-pg" 120
wait_for_pod "app=onec-server" 120
# --- Step 5: Smoke tests ---
echo -e "\n${YELLOW}[5/5] Smoke tests...${NC}"
# PostgreSQL ready
PG_POD=$(kubectl -n test-env get pod -l app=test-pg -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
if [ -n "$PG_POD" ]; then
if kubectl -n test-env exec "$PG_POD" -- su - postgres -c "/usr/lib/postgresql/18/bin/pg_isready" > /dev/null 2>&1; then
echo -e "${GREEN} ✓ PostgreSQL is ready${NC}"
else
echo -e "${RED} ✗ PostgreSQL pg_isready failed${NC}"
fi
fi
# 1C server ragent running
ONEC_POD=$(kubectl -n test-env get pod -l app=onec-server -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
if [ -n "$ONEC_POD" ]; then
if kubectl -n test-env exec "$ONEC_POD" -- pgrep ragent > /dev/null 2>&1; then
echo -e "${GREEN} ✓ ragent is running${NC}"
else
echo -e "${RED} ✗ ragent not running${NC}"
fi
if kubectl -n test-env exec "$ONEC_POD" -- pgrep crserver > /dev/null 2>&1; then
echo -e "${GREEN} ✓ crserver is running${NC}"
else
echo -e "${RED} ✗ crserver not running${NC}"
fi
fi
# Summary
echo -e "\n=== Status ==="
kubectl -n test-env get pods -o wide
echo ""
kubectl -n test-env get svc
echo ""
kubectl -n test-env get pvc