From 1fe8deb0de0ad16e63eb5787e1131eb8105f5e76 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Tue, 30 Jun 2026 18:55:21 +0000 Subject: [PATCH] ci: add Forgejo CI/CD pipeline with docker save/load deploy to prod Co-Authored-By: Claude Sonnet 4.6 --- .forgejo/workflows/deploy.yml | 52 +++++++++++++++++++++++++++ docker-compose.prod.yml | 66 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 4 +++ 3 files changed, 122 insertions(+) create mode 100644 .forgejo/workflows/deploy.yml create mode 100644 docker-compose.prod.yml diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml new file mode 100644 index 0000000..10bc74d --- /dev/null +++ b/.forgejo/workflows/deploy.yml @@ -0,0 +1,52 @@ +name: CI/CD Pipeline + +on: + push: + branches: + - main + +jobs: + build-and-deploy: + runs-on: shell + steps: + - name: Clone repository + run: git clone --depth 1 "http://192.168.8.174:3000/${GITHUB_REPOSITORY}.git" . + env: + GIT_TERMINAL_PROMPT: '0' + + - name: Ensure Docker CLI + run: | + apk add --no-cache docker-cli docker-cli-compose openssh-client || true + grep -q '^vrubel:' /etc/passwd || echo 'vrubel:x:1000:1000::/data:/bin/sh' >> /etc/passwd + + - name: Setup .env for CI/CD + run: cp .env.example .env + + - name: Build Docker images + run: docker-compose build + + - name: Login to Gitea Container Registry + run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login http://192.168.8.174:3000 -u "${{ secrets.REGISTRY_USER }}" --password-stdin + + - name: Push images to registry + run: | + docker push 192.168.8.174:3000/vrubel/lichess-api:latest + docker push 192.168.8.174:3000/vrubel/lichess-bot:latest + docker push 192.168.8.174:3000/vrubel/lichess-admin:latest + docker push 192.168.8.174:3000/vrubel/lichess-web:latest + + - name: Transfer images to prod + run: | + docker save \ + 192.168.8.174:3000/vrubel/lichess-api:latest \ + 192.168.8.174:3000/vrubel/lichess-bot:latest \ + 192.168.8.174:3000/vrubel/lichess-admin:latest \ + 192.168.8.174:3000/vrubel/lichess-web:latest \ + | ssh -i /data/.ssh/id_ed25519 -o StrictHostKeyChecking=no root@130.17.6.76 docker load + + - name: Deploy on prod host + run: | + cat docker-compose.prod.yml | ssh -i /data/.ssh/id_ed25519 -o StrictHostKeyChecking=no root@130.17.6.76 \ + "cat > ~/services/LichessStatTgWeb/docker-compose.yml" + ssh -i /data/.ssh/id_ed25519 -o StrictHostKeyChecking=no root@130.17.6.76 \ + "cd ~/services/LichessStatTgWeb && docker compose up -d --remove-orphans" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..e483a0c --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,66 @@ +services: + lichess-api: + image: 192.168.8.174:3000/vrubel/lichess-api:latest + container_name: lichess-api + ports: + - "8002:8000" + environment: + - PYTHONUNBUFFERED=1 + restart: always + healthcheck: + test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + lichess-bot: + image: 192.168.8.174:3000/vrubel/lichess-bot:latest + container_name: lichess-telegram-bot + volumes: + - ./data:/app/data + env_file: + - .env + environment: + - PYTHONPATH=/app + - PYTHONUNBUFFERED=1 + network_mode: "host" + restart: always + depends_on: + - lichess-api + healthcheck: + test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost:8002/health', timeout=5)"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + admin-bot: + image: 192.168.8.174:3000/vrubel/lichess-admin:latest + container_name: lichess-admin-bot + volumes: + - ./data:/app/data + env_file: + - .env + environment: + - PYTHONPATH=/app + - PYTHONUNBUFFERED=1 + network_mode: "host" + restart: always + depends_on: + - lichess-api + + web-view: + image: 192.168.8.174:3000/vrubel/lichess-web:latest + container_name: lichess-web-view + ports: + - "5000:5000" + volumes: + - ./data:/app/data:ro + restart: always + depends_on: + - lichess-bot + +networks: + default: + name: lichess-network diff --git a/docker-compose.yml b/docker-compose.yml index c405a41..10c187e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ services: # Lichess Web Services (API) lichess-api: build: ./LichessWebServices + image: 192.168.8.174:3000/vrubel/lichess-api:latest container_name: lichess-api ports: - "8002:8000" @@ -20,6 +21,7 @@ services: # Telegram Bot lichess-bot: build: ./LichessClientTG_bot + image: 192.168.8.174:3000/vrubel/lichess-bot:latest container_name: lichess-telegram-bot volumes: - ./LichessClientTG_bot/data:/app/data @@ -45,6 +47,7 @@ services: build: context: ./LichessClientTG_bot dockerfile: Dockerfile.admin + image: 192.168.8.174:3000/vrubel/lichess-admin:latest container_name: lichess-admin-bot volumes: - ./LichessClientTG_bot/data:/app/data @@ -62,6 +65,7 @@ services: # Web View Interface web-view: build: ./LichessWebView + image: 192.168.8.174:3000/vrubel/lichess-web:latest container_name: lichess-web-view ports: - "5000:5000"