Add workflow
All checks were successful
/ build-bot (push) Successful in 19s

c

a
This commit is contained in:
Marsn3 2025-02-26 13:25:02 +01:00
parent f9743f8a84
commit 125eade964
3 changed files with 65 additions and 6 deletions

View file

@ -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

30
src/bot/Dockerfile Normal file
View file

@ -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"]

View file

@ -2,15 +2,22 @@
{ {
dotenv.enable = true; dotenv.enable = true;
packages = [pkgs.docker];
# https://devenv.sh/languages/ # https://devenv.sh/languages/
languages.python.enable = true; languages.python.enable = true;
languages.python.venv.enable = true; languages.python.venv.enable = true;
languages.python.uv.enable = true; languages.python.uv.enable = true;
languages.python.uv.sync.enable = true; languages.python.uv.sync.enable = true;
processes.bot.exec = "uv run bot.py"; tasks."vc-stats-bot:build" = {
containers."bot".name = "vc-stats-bot"; exec = ''
containers."bot".startupCommand = config.processes.bot.exec; docker build -t git.m3.fyi/metrik/vc-stats-bot:latest .
containers."bot".registry = "docker://git.m3.fyi/metrik/"; '';
containers."bot".enableLayerDeduplication = true; };
tasks."vc-stats-bot:publish" = {
exec = ''
docker push git.m3.fyi/metrik/vc-stats-bot:latest
'';
};
} }