diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml new file mode 100644 index 0000000..1654601 --- /dev/null +++ b/.forgejo/workflows/build.yaml @@ -0,0 +1,22 @@ +on: [push] + +jobs: + build-bot: + runs-on: nix + steps: + - uses: https://code.forgejo.org/actions/checkout@v4 + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: git.m3.fyi + username: ${{ vars.FORGEJO_USER }} + password: ${{ secrets.FORGEJO_TOKEN }} + - name: Setup Docker + uses: docker/setup-buildx-action@v3 + - name: Build and push container + uses: docker/build-push-action@v5 + with: + context: src/bot/ + file: ./src/bot/Dockerfile + push: true + tags: git.m3.fyi/metrik/vc-stats-bot:${{gitea.sha}},git.m3.fyi/metrik/vc-stats-bot:latest diff --git a/src/bot/Dockerfile b/src/bot/Dockerfile new file mode 100644 index 0000000..1c891da --- /dev/null +++ b/src/bot/Dockerfile @@ -0,0 +1,30 @@ +FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim + +# Enable bytecode compilation +ENV UV_COMPILE_BYTECODE=1 + +# Copy from the cache instead of linking since it's a mounted volume +ENV UV_LINK_MODE=copy +# Install the project's dependencies using the lockfile and settings +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --frozen --no-install-project --no-dev +# Then, add the rest of the project source code and install it +# Installing separately from its dependencies allows optimal layer caching +RUN mkdir app +ADD bot.py app/ +ADD pyproject.toml app/ +ADD uv.lock app/ +WORKDIR /app + +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --no-dev +# Place executables in the environment at the front of the path +ENV PATH="/app/.venv/bin:$PATH" + +# Reset the entrypoint, don't invoke `uv` +ENTRYPOINT [] + +CMD ["python3","bot.py"] + diff --git a/src/bot/devenv.nix b/src/bot/devenv.nix index 717757b..cbc9181 100644 --- a/src/bot/devenv.nix +++ b/src/bot/devenv.nix @@ -2,15 +2,22 @@ { dotenv.enable = true; + packages = [pkgs.docker]; # https://devenv.sh/languages/ languages.python.enable = true; languages.python.venv.enable = true; languages.python.uv.enable = true; languages.python.uv.sync.enable = true; - - processes.bot.exec = "uv run bot.py"; - containers."bot".name = "vc-stats-bot"; - containers."bot".startupCommand = config.processes.bot.exec; - containers."bot".registry = "docker://git.m3.fyi/metrik/"; - containers."bot".enableLayerDeduplication = true; + + tasks."vc-stats-bot:build" = { + exec = '' + docker build -t git.m3.fyi/metrik/vc-stats-bot:latest . + ''; + }; + + tasks."vc-stats-bot:publish" = { + exec = '' + docker push git.m3.fyi/metrik/vc-stats-bot:latest + ''; + }; }