diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 5025cc7d..68888e7b 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -31,28 +31,26 @@ jobs: echo "full=$SHA" >> "$GITHUB_OUTPUT" - name: Build backend image + env: + REGISTRY: 172.16.0.1:5000 run: | - docker build -t 127.0.0.1:5000/tloto-backend:${{ steps.meta.outputs.sha }} ./backend - docker tag 127.0.0.1:5000/tloto-backend:${{ steps.meta.outputs.sha }} 127.0.0.1:5000/tloto-backend:sha-${{ steps.meta.outputs.sha }} + docker build -t ${REGISTRY}/tloto-backend:${{ steps.meta.outputs.sha }} ./backend - name: Build web image + env: + REGISTRY: 172.16.0.1:5000 run: | docker build \ --build-arg VITE_API_BASE_URL=http://127.0.0.1:9080 \ --build-arg VITE_WS_URL=ws://127.0.0.1:9080/ws/v1/games/candle-predict \ --build-arg VITE_WS_ENABLED=true \ - -t 127.0.0.1:5000/tloto-web:${{ steps.meta.outputs.sha }} \ + -t ${REGISTRY}/tloto-web:${{ steps.meta.outputs.sha }} \ ./prediqo_web - name: Push images to local registry + env: + REGISTRY: 172.16.0.1:5000 run: | - # Host registry published on 127.0.0.1:5000; from job container use gateway. - # act_runner with docker.sock builds on host daemon — 127.0.0.1:5000 works. - docker push 127.0.0.1:5000/tloto-backend:${{ steps.meta.outputs.sha }} - docker push 127.0.0.1:5000/tloto-web:${{ steps.meta.outputs.sha }} - - - name: Record artifact markers - run: | - mkdir -p .ci-out - echo "${{ steps.meta.outputs.full }}" > .ci-out/sha.txt + docker push ${REGISTRY}/tloto-backend:${{ steps.meta.outputs.sha }} + docker push ${REGISTRY}/tloto-web:${{ steps.meta.outputs.sha }} echo "CI_OK ${{ steps.meta.outputs.sha }}" diff --git a/deploy/gitea-stack/attach-git-to-app.sh b/deploy/gitea-stack/attach-git-to-app.sh new file mode 100644 index 00000000..bea8db71 --- /dev/null +++ b/deploy/gitea-stack/attach-git-to-app.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Turn ~/games_app tarball into a git checkout of Gitea main while preserving .env and Docker state. +set -euo pipefail +APP="${HOME}/games_app" +TOKEN_FILE="${HOME}/gitea-push-credentials.txt" +TOKEN="$(grep -A1 'Push token' "$TOKEN_FILE" | tail -1 | tr -d ' \r')" +URL="http://tloto-admin:${TOKEN}@127.0.0.1:3000/tloto-admin/games_app.git" + +cd "$APP" +cp -a .env /tmp/games_app.env.bak +if [[ ! -d .git ]]; then + git init -b main + git remote add origin "$URL" +else + git remote remove origin 2>/dev/null || true + git remote add origin "$URL" +fi +git fetch origin main +git checkout -f -B main origin/main +# restore secrets +cp -a /tmp/games_app.env.bak .env +chmod 600 .env +# sanitize remote URL (no token) +git remote set-url origin "http://127.0.0.1:3000/tloto-admin/games_app.git" +git status -sb +git rev-parse --short HEAD +echo "APP_GIT_OK" diff --git a/deploy/gitea-stack/check-actions.sh b/deploy/gitea-stack/check-actions.sh new file mode 100644 index 00000000..450aca75 --- /dev/null +++ b/deploy/gitea-stack/check-actions.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail +cd ~/gitea +set -a; source .env; set +a +echo "== containers ==" +sudo docker ps -a --format '{{.Names}} {{.Status}}' | head -50 +echo "== runner ==" +sudo docker logs tloto_act_runner --tail 40 +echo "== tasks api ==" +curl -s -u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASSWORD}" \ + 'http://127.0.0.1:3000/api/v1/repos/tloto-admin/games_app/actions/tasks' | head -c 2000 +echo +echo "== runs api alt ==" +curl -s -u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASSWORD}" \ + 'http://127.0.0.1:3000/api/v1/repos/tloto-admin/games_app/actions/runs' | head -c 2000 +echo diff --git a/deploy/gitea-stack/configure-docker-insecure-registry.sh b/deploy/gitea-stack/configure-docker-insecure-registry.sh new file mode 100644 index 00000000..83524aab --- /dev/null +++ b/deploy/gitea-stack/configure-docker-insecure-registry.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Allow HTTP push/pull to local registry from Docker daemon / job containers. +set -euo pipefail +DAEMON=/etc/docker/daemon.json +sudo mkdir -p /etc/docker +if [[ -f "$DAEMON" ]]; then + sudo python3 - <<'PY' +import json +from pathlib import Path +p=Path("/etc/docker/daemon.json") +data=json.loads(p.read_text() or "{}") +regs=set(data.get("insecure-registries") or []) +regs.update(["172.16.0.1:5000", "127.0.0.1:5000"]) +data["insecure-registries"]=sorted(regs) +p.write_text(json.dumps(data, indent=2)+"\n") +print(data) +PY +else + echo '{"insecure-registries":["127.0.0.1:5000","172.16.0.1:5000"]}' | sudo tee "$DAEMON" +fi +sudo systemctl restart docker +sleep 3 +# restart stacks after docker restart +cd ~/gitea && sudo docker compose up -d gitea registry +sudo docker compose --profile runner up -d runner +cd ~/games_app && sudo docker compose --profile http --profile clamav up -d +curl -fsS http://127.0.0.1:9080/health | head -c 80; echo +curl -fsS http://127.0.0.1:3000/api/v1/version; echo +echo "DOCKER_REGISTRY_OK" diff --git a/deploy/gitea-stack/docker-compose.yml b/deploy/gitea-stack/docker-compose.yml index e62bf6b4..9a47f665 100644 --- a/deploy/gitea-stack/docker-compose.yml +++ b/deploy/gitea-stack/docker-compose.yml @@ -38,7 +38,8 @@ services: GITEA__security__INTERNAL_TOKEN: ${GITEA_INTERNAL_TOKEN} GITEA__session__PROVIDER: memory GITEA__actions__ENABLED: "true" - GITEA__actions__DEFAULT_ACTIONS_URL: self + # Resolve actions/checkout etc. from GitHub (not this instance) + GITEA__actions__DEFAULT_ACTIONS_URL: github GITEA__openid__ENABLE_OPENID_SIGNIN: "false" GITEA__openid__ENABLE_OPENID_SIGNUP: "false" GITEA__mailer__ENABLED: "false" @@ -68,9 +69,10 @@ services: REGISTRY_STORAGE_DELETE_ENABLED: "true" volumes: - registry-data:/var/lib/registry - # Localhost only — CI runner reaches it via Docker network; host builds via 127.0.0.1 + # Host loopback + docker0 (job containers cannot use 127.0.0.1 of the host) ports: - "127.0.0.1:5000:5000" + - "172.16.0.1:5000:5000" networks: - gitea-net healthcheck: diff --git a/deploy/gitea-stack/fix-stuck-actions.sh b/deploy/gitea-stack/fix-stuck-actions.sh new file mode 100644 index 00000000..7cc226d4 --- /dev/null +++ b/deploy/gitea-stack/fix-stuck-actions.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail +NOW="$(date +%s)" +sudo -u postgres psql -d gitea <