Skip to content

Commit 1f79259

Browse files
Merge pull request #121 from blacklanternsecurity/uv
Migrate to uv + Auto Docker Publishing
2 parents 4b28915 + 4aeb27c commit 1f79259

13 files changed

Lines changed: 3051 additions & 4020 deletions

File tree

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
mongodb/
1+
mongodb/
2+
.venv/

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "uv"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
groups:
13+
actions:
14+
patterns:
15+
- "*"

.github/workflows/docker-tests.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ jobs:
1414
docker-test:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v6
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v7
1820
- name: Set up Python
19-
uses: actions/setup-python@v4
20-
with:
21-
python-version: "3.11"
21+
run: uv python install 3.11
2222
- name: Install dependencies
23-
run: |
24-
pip install poetry
25-
poetry install
23+
run: uv sync
2624
- name: Run tests
2725
run: |
28-
BBOT_SERVER_TEST_DOCKER_COMPOSE=true poetry run pytest --disable-warnings --log-cli-level=INFO -k test_docker_compose
26+
BBOT_SERVER_TEST_DOCKER_COMPOSE=true uv run pytest --disable-warnings --log-cli-level=INFO -k test_docker_compose
2927
3028
docker-publish:
3129
runs-on: ubuntu-latest
@@ -36,6 +34,17 @@ jobs:
3634
- name: Checkout code
3735
uses: actions/checkout@v6
3836

37+
- name: Install uv
38+
uses: astral-sh/setup-uv@v7
39+
40+
- name: Get version from pyproject.toml
41+
id: version
42+
run: |
43+
VERSION=$(uv version --short)
44+
echo "version=$VERSION" >> $GITHUB_OUTPUT
45+
echo "major=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT
46+
echo "minor=$(echo $VERSION | cut -d. -f1-2)" >> $GITHUB_OUTPUT
47+
3948
- name: Set up Docker Buildx
4049
uses: docker/setup-buildx-action@v3
4150

@@ -55,9 +64,9 @@ jobs:
5564
type=ref,event=pr
5665
type=sha,prefix=sha-
5766
type=raw,value=latest,enable={{is_default_branch}}
58-
type=raw,value=v1
59-
type=raw,value=v1.0
60-
type=raw,value=v1.0.0
67+
type=raw,value=v${{ steps.version.outputs.major }}
68+
type=raw,value=v${{ steps.version.outputs.minor }}
69+
type=raw,value=v${{ steps.version.outputs.version }}
6170
6271
- name: Build and push Docker image
6372
uses: docker/build-push-action@v6
@@ -72,19 +81,19 @@ jobs:
7281
run: |
7382
# Install jq for JSON processing
7483
sudo apt-get update && sudo apt-get install -y jq
75-
84+
7685
echo "Cleaning up bbot-server tags..."
77-
86+
7887
tags_response=$(curl -s -H "Authorization: Bearer ${{ secrets.DOCKER_TOKEN }}" \
7988
"https://hub.docker.com/v2/repositories/bbot-server}/tags/?page_size=100")
80-
89+
8190
tags_to_delete=$(echo "$tags_response" | jq -r '.results[] | select(.name != "latest") | [.last_updated, .name] | @tsv' | \
8291
sort -r | tail -n +51 | cut -f2)
83-
92+
8493
for tag in $tags_to_delete; do
8594
echo "Deleting bbot-server tag: $tag"
8695
curl -X DELETE -H "Authorization: Bearer ${{ secrets.DOCKER_TOKEN }}" \
8796
"https://hub.docker.com/v2/repositories/bbot-server/tags/$tag/"
8897
done
89-
90-
echo "Cleanup completed for bbot-server. Kept 50 most recent tags plus 'latest'."
98+
99+
echo "Cleanup completed for bbot-server. Kept 50 most recent tags plus 'latest'."

.github/workflows/tests.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@ jobs:
2727
ports:
2828
- 127.0.0.1:6379:6379
2929
steps:
30-
- uses: actions/checkout@v4
30+
- uses: actions/checkout@v6
31+
- name: Install uv
32+
uses: astral-sh/setup-uv@v7
3133
- name: Set up Python
32-
uses: actions/setup-python@v4
33-
with:
34-
python-version: ${{ matrix.python-version }}
34+
run: uv python install ${{ matrix.python-version }}
3535
- name: Install dependencies
36-
run: |
37-
pip install poetry
38-
poetry install
36+
run: uv sync
3937
- name: Lint
4038
run: |
41-
poetry run ruff check
42-
poetry run ruff format --check
39+
uv run ruff check
40+
uv run ruff format --check
4341
- name: Run tests
4442
run: |
45-
NO_COLOR=true poetry run pytest --reruns 2 --disable-warnings --log-cli-level=INFO --cov-report xml:cov.xml --cov=bbot_server .
43+
NO_COLOR=true uv run pytest --reruns 2 --disable-warnings --log-cli-level=INFO --cov-report xml:cov.xml --cov=bbot_server .
4644
- name: Upload Code Coverage
47-
uses: codecov/codecov-action@v3
45+
uses: codecov/codecov-action@v5
4846
with:
4947
token: ${{ secrets.CODECOV_TOKEN }}
5048
files: ./cov.xml

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
FROM python:3.11
2-
RUN apt-get -y update
3-
RUN apt-get -y install curl jq
1+
FROM ghcr.io/astral-sh/uv:python3.11-trixie
2+
RUN apt-get -y update && apt-get -y install curl jq
43
COPY . /app
54
WORKDIR /app
6-
# install bbot_server in editable mode
7-
RUN pip install -e .
5+
RUN uv sync --frozen
6+
ENV PATH="/app/.venv/bin:$PATH"
87
EXPOSE 8807
9-
CMD ["bbctl", "server", "start", "--api-only"]
8+
CMD ["uv", "run", "bbctl", "server", "start", "--api-only"]

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ BBOT Server is a database and multiplayer hub for all your [BBOT](https://github
2727
# clone the repo and cd into it
2828
git clone git@github.com:blacklanternsecurity/bbot-server.git && cd bbot-server
2929

30-
# Install in editable mode
31-
pipx install -e .
30+
# Install dependencies and create virtual environment
31+
uv sync
3232
```
3333

34-
Note: to update to the latest version, run `git pull` in the `bbot-server` directory.
34+
Note: to update to the latest version, run `git pull && uv sync` in the `bbot-server` directory.
35+
36+
To install `uv`, see the [uv installation docs](https://docs.astral.sh/uv/getting-started/installation/).
37+
38+
Commands shown below as `bbctl` can be run with `uv run bbctl` from the project directory, or you can activate the virtual environment first with `source .venv/bin/activate`.
3539

3640
## Start the server
3741

@@ -459,10 +463,10 @@ Then execute `pytest`:
459463

460464
```bash
461465
# run all tests
462-
poetry run pytest -v
466+
uv run pytest -v
463467
464468
# run specific tests
465-
poetry run pytest -v -k test_applet_scans
469+
uv run pytest -v -k test_applet_scans
466470
```
467471

468472
## Screenshots

bbot_server/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import os
2+
from importlib.metadata import version, PackageNotFoundError
23
from pathlib import Path
34

5+
try:
6+
__version__ = version("bbot-server")
7+
except PackageNotFoundError:
8+
__version__ = "unknown"
9+
410
BBOT_SERVER_PROJECT_ROOT = Path(__file__).parent.parent
511

612
# set up logging
@@ -17,4 +23,4 @@
1723
from .interfaces import BBOTServer
1824

1925

20-
__all__ = ["BBOTServer", "BBOT_SERVER_DIR", "BBOT_SERVER_CONFIG", "BBOT_SERVER_PROJECT_ROOT"]
26+
__all__ = ["BBOTServer", "BBOT_SERVER_DIR", "BBOT_SERVER_CONFIG", "BBOT_SERVER_PROJECT_ROOT", "__version__"]

bbot_server/cli/themes.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
import typer
2-
# from textual.theme import Theme
1+
from typer import rich_utils
32

43
COLOR = "bold dark_orange"
54
DARK_COLOR = "grey50"
65

7-
# # textual theme
8-
# TEXTUAL_THEME = Theme(
9-
# name="bbot",
10-
# primary="#000000",
11-
# secondary="#1a1a1a",
12-
# accent="#FF8400",
13-
# warning="#FF8400",
14-
# error="#ff4500",
15-
# success="#FF8400",
16-
# foreground="#ffffff",
17-
# )
18-
196
# typer theme
20-
typer.rich_utils.STYLE_OPTION = "bold dark_orange"
21-
typer.rich_utils.STYLE_NEGATIVE_OPTION = "bold red"
22-
typer.rich_utils.STYLE_NEGATIVE_SWITCH = "bold red"
23-
typer.rich_utils.STYLE_SWITCH = "bold orange1"
24-
typer.rich_utils.STYLE_USAGE = "bright_white"
25-
typer.rich_utils.STYLE_METAVAR = "bold dark_orange"
26-
typer.rich_utils.STYLE_OPTION_ENVVAR = "dim orange1"
27-
typer.rich_utils.STYLE_COMMANDS_TABLE_FIRST_COLUMN = "bold dark_orange"
7+
rich_utils.STYLE_OPTION = "bold dark_orange"
8+
rich_utils.STYLE_NEGATIVE_OPTION = "bold red"
9+
rich_utils.STYLE_NEGATIVE_SWITCH = "bold red"
10+
rich_utils.STYLE_SWITCH = "bold orange1"
11+
rich_utils.STYLE_USAGE = "bright_white"
12+
rich_utils.STYLE_METAVAR = "bold dark_orange"
13+
rich_utils.STYLE_OPTION_ENVVAR = "dim orange1"
14+
rich_utils.STYLE_COMMANDS_TABLE_FIRST_COLUMN = "bold dark_orange"

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ x-bbot-server-base: &bbot-server-base
44
restart: unless-stopped
55
volumes:
66
- "${BBOT_SERVER_CONFIG:-~/.config/bbot_server/config.yml}:/root/.config/bbot_server/config.yml"
7-
- .:/app
7+
- ./bbot_server:/app/bbot_server
88
- ./bbot_server/defaults_docker.yml:/app/bbot_server/defaults.yml
99

1010
services:

0 commit comments

Comments
 (0)