From 873ca512bdafe6407c189c97b965b27373d6abc0 Mon Sep 17 00:00:00 2001 From: shay Date: Sat, 18 Apr 2026 00:52:46 -0400 Subject: [PATCH] feat(readme): update Docker badge to reflect new deployment workflow. --- .github/workflows/{docker.yml => deploy.yml} | 30 +++++++- README.md | 2 +- deploy/compose.yml | 78 ++++++++++++++++++++ deploy/deploy.sh | 13 ++++ edge/Dockerfile | 3 +- 5 files changed, 120 insertions(+), 6 deletions(-) rename .github/workflows/{docker.yml => deploy.yml} (65%) create mode 100644 deploy/compose.yml create mode 100755 deploy/deploy.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/deploy.yml similarity index 65% rename from .github/workflows/docker.yml rename to .github/workflows/deploy.yml index b7b2061..9403828 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: docker +name: build and deploy on: push: @@ -11,7 +11,7 @@ env: jobs: build: - name: ${{ matrix.service }} + name: build ${{ matrix.service }} runs-on: ubuntu-latest permissions: contents: read @@ -20,6 +20,8 @@ jobs: fail-fast: false matrix: service: [fetcher, generator, edge] + outputs: + image_tag: ${{ steps.tag.outputs.value }} steps: - uses: actions/checkout@v4 @@ -33,6 +35,12 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Compute image tag (sha-) + id: tag + env: + SHA: ${{ github.sha }} + run: echo "value=sha-${SHA:0:7}" >> "$GITHUB_OUTPUT" + - name: Compute image name (lowercase) id: img env: @@ -46,8 +54,7 @@ jobs: with: images: ${{ steps.img.outputs.name }} tags: | - type=ref,event=branch - type=sha,format=short + type=raw,value=${{ steps.tag.outputs.value }} type=raw,value=latest,enable={{is_default_branch}} - name: Build ${{ matrix.service }} image @@ -59,3 +66,18 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha,scope=${{ matrix.service }} cache-to: type=gha,mode=max,scope=${{ matrix.service }} + + deploy: + name: deploy to mini PC + needs: build + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: [self-hosted, minipc] + steps: + - uses: actions/checkout@v4 + + - name: Deploy compose stack + env: + IMAGE_TAG: ${{ needs.build.outputs.image_tag }} + GITHUB_PAT: ${{ secrets.FETCHER_GITHUB_PAT }} + FETCHER_INTERNAL_TOKEN: ${{ secrets.FETCHER_INTERNAL_TOKEN }} + run: ./deploy/deploy.sh diff --git a/README.md b/README.md index c64bd20..56e9bc8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # github-readme-stats [![tests](https://github.com/ShayManor/github-readme-stats/actions/workflows/tests.yml/badge.svg)](https://github.com/ShayManor/github-readme-stats/actions/workflows/tests.yml) -[![docker](https://github.com/ShayManor/github-readme-stats/actions/workflows/docker.yml/badge.svg)](https://github.com/ShayManor/github-readme-stats/actions/workflows/docker.yml) +[![build and deploy](https://github.com/ShayManor/github-readme-stats/actions/workflows/deploy.yml/badge.svg)](https://github.com/ShayManor/github-readme-stats/actions/workflows/deploy.yml) A monorepo of three independent Python services plus a React frontend, each self-contained. See each service's README for details. diff --git a/deploy/compose.yml b/deploy/compose.yml new file mode 100644 index 0000000..657d70c --- /dev/null +++ b/deploy/compose.yml @@ -0,0 +1,78 @@ +name: ghstats + +services: + fetcher: + image: ghcr.io/shaymanor/ghstats-fetcher:${IMAGE_TAG:-latest} + container_name: ghstats-fetcher + restart: unless-stopped + environment: + GITHUB_PAT: ${GITHUB_PAT:?missing GITHUB_PAT} + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN} + volumes: + - ${HOME}/ghstats/data/fetcher:/app/data + ports: + - "127.0.0.1:5001:5001" + + fetcher-cron: + image: ghcr.io/shaymanor/ghstats-fetcher:${IMAGE_TAG:-latest} + container_name: ghstats-fetcher-cron + restart: unless-stopped + command: ["python", "-m", "src.cron"] + environment: + GITHUB_PAT: ${GITHUB_PAT:?missing GITHUB_PAT} + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN} + volumes: + - ${HOME}/ghstats/data/fetcher:/app/data + depends_on: + - fetcher + + generator: + image: ghcr.io/shaymanor/ghstats-generator:${IMAGE_TAG:-latest} + container_name: ghstats-generator + restart: unless-stopped + environment: + FETCHER_URL: http://fetcher:5001 + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN} + volumes: + - ${HOME}/ghstats/data/generator:/app/data + ports: + - "5002:5002" + depends_on: + - fetcher + + generator-worker: + image: ghcr.io/shaymanor/ghstats-generator:${IMAGE_TAG:-latest} + container_name: ghstats-generator-worker + restart: unless-stopped + command: ["python", "-m", "src.worker"] + environment: + FETCHER_URL: http://fetcher:5001 + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN} + volumes: + - ${HOME}/ghstats/data/generator:/app/data + depends_on: + - generator + + generator-cron: + image: ghcr.io/shaymanor/ghstats-generator:${IMAGE_TAG:-latest} + container_name: ghstats-generator-cron + restart: unless-stopped + command: ["python", "-m", "src.cron"] + environment: + FETCHER_URL: http://fetcher:5001 + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN} + volumes: + - ${HOME}/ghstats/data/generator:/app/data + depends_on: + - generator + + edge: + image: ghcr.io/shaymanor/ghstats-edge:${IMAGE_TAG:-latest} + container_name: ghstats-edge + restart: unless-stopped + environment: + GENERATOR_URL: http://generator:5002 + ports: + - "5003:5003" + depends_on: + - generator diff --git a/deploy/deploy.sh b/deploy/deploy.sh new file mode 100755 index 0000000..8651e3a --- /dev/null +++ b/deploy/deploy.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Pulls the current image tag and brings up the compose stack. +# Expects GITHUB_PAT, FETCHER_INTERNAL_TOKEN, and IMAGE_TAG to be present in +# the environment (exported by the GitHub Actions deploy job). +set -euo pipefail + +cd "$(dirname "$0")" + +mkdir -p "$HOME/ghstats/data/fetcher" "$HOME/ghstats/data/generator" + +docker compose pull +docker compose up -d --remove-orphans +docker compose ps diff --git a/edge/Dockerfile b/edge/Dockerfile index e23d1fd..586e613 100644 --- a/edge/Dockerfile +++ b/edge/Dockerfile @@ -6,4 +6,5 @@ RUN pip install --no-cache-dir -r requirements.txt COPY src ./src EXPOSE 5003 -CMD ["gunicorn", "-b", "0.0.0.0:5003", "-w", "2", "src.api:app"] +# Bind to $PORT when set (e.g. Cloud Run injects PORT=8080); default to 5003. +CMD ["sh", "-c", "exec gunicorn -b 0.0.0.0:${PORT:-5003} -w 2 src.api:app"]