Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 91 additions & 1 deletion .github/workflows/docker-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,42 @@ jobs:
run: |
BBOT_SERVER_TEST_DOCKER_COMPOSE=true uv run pytest --disable-warnings --log-cli-level=INFO -k test_docker_compose

helm-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'

- name: Install Python dependencies
run: pip install requests

- name: Install kubectl
uses: azure/setup-kubectl@v4

- name: Install Helm
uses: azure/setup-helm@v4

- name: Install minikube
uses: medyagh/setup-minikube@latest

- name: Run helm deployment tests
run: python helm_deployment_test.py

- name: Cleanup minikube
if: always()
run: minikube delete

docker-publish:
runs-on: ubuntu-latest
needs: docker-test
needs:
- helm-test
- docker-test
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/stable' || github.ref == 'refs/heads/dev') }}

steps:
Expand Down Expand Up @@ -104,3 +137,60 @@ jobs:
done

echo "Cleanup completed for bbot-server."


helm-publish:
runs-on: ubuntu-latest
needs:
- helm-test
- docker-test
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/stable' || github.ref == 'refs/heads/dev') }}

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Get version from pyproject.toml
id: version
run: |
VERSION=$(uv version --short)
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Install Helm
uses: azure/setup-helm@v4

- name: Update Chart.yaml version and appVersion
run: |
VERSION="${{ steps.version.outputs.version }}"
CHART_VERSION="$VERSION"
IMAGE_TAG="stable"
if [ "${{ github.ref }}" = "refs/heads/dev" ]; then
CHART_VERSION="${VERSION}-dev"
IMAGE_TAG="dev"
fi
sed -i "s/^version:.*/version: ${CHART_VERSION}/" helm/Chart.yaml
sed -i "s/^appVersion:.*/appVersion: \"${VERSION}\"/" helm/Chart.yaml
# ensure the packaged chart defaults to the correct docker image tag
sed -i "s/^ tag:.*/ tag: \"${IMAGE_TAG}\"/" helm/values.yaml
echo "Chart version: $CHART_VERSION"
echo "App version: $VERSION"
echo "Image tag: $IMAGE_TAG"
cat helm/Chart.yaml

- name: Add Helm repositories
run: helm repo add bitnami https://charts.bitnami.com/bitnami

- name: Build Helm dependencies
run: helm dependency build helm/

- name: Package Helm chart
run: helm package helm/

- name: Login to Docker Hub OCI registry
run: echo "${{ secrets.DOCKER_TOKEN }}" | helm registry login registry-1.docker.io -u blacklanternsecurity --password-stdin

- name: Push Helm chart to Docker Hub
run: helm push bbot-server-*.tgz oci://registry-1.docker.io/blacklanternsecurity
97 changes: 0 additions & 97 deletions .github/workflows/helm-tests.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,45 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./cov.xml
verbose: true

publish_pypi:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/stable'
continue-on-error: true
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Get version
id: calc_version
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Build PyPI package
run: uv build
- name: Publish PyPI package
uses: pypa/gh-action-pypi-publish@release/v1.13
with:
password: ${{ secrets.PYPI_API_TOKEN }}
outputs:
VERSION: ${{ steps.calc_version.outputs.VERSION }}

tag_commit:
needs: publish_pypi
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/stable'
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Configure git
run: |
git config --local user.email "info@blacklanternsecurity.com"
git config --local user.name "GitHub Actions"
- name: Tag commit
run: |
VERSION="v${{ needs.publish_pypi.outputs.VERSION }}"
git tag -a "$VERSION" -m "Stable Release $VERSION"
git push origin "$VERSION"
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-install-project
COPY . .
RUN cp bbot_server/defaults_docker.yml bbot_server/defaults.yml
RUN uv sync --frozen
RUN useradd -u 1000 -m bbot && chown -R bbot:bbot /app
USER bbot
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,46 @@ BBOT Server is a database and multiplayer hub for all your [BBOT](https://github
## Installation

```bash
# clone the repo and cd into it
git clone git@github.com:blacklanternsecurity/bbot-server.git && cd bbot-server
# install with uv (recommended)
uv tool install bbot-server

# or with pipx
pipx install bbot-server
```

To install `uv`, see the [uv installation docs](https://docs.astral.sh/uv/getting-started/installation/).

### From source (for development)

# Install dependencies and create virtual environment
```bash
git clone git@github.com:blacklanternsecurity/bbot-server.git && cd bbot-server
uv sync
```

Note: to update to the latest version, run `git pull && uv sync` in the `bbot-server` directory.

To install `uv`, see the [uv installation docs](https://docs.astral.sh/uv/getting-started/installation/).

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`.
When installed from source, 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`.

## Start the server

Note: this requires Docker and Docker Compose to be installed.

```bash
# Start BBOT server using Docker Compose
# Start BBOT server using Docker Compose (pulls from Docker Hub)
bbctl server start
```

### Development mode

When working on the bbot-server source code, use `--dev` to build from source and mount your code for live reload:

```bash
# From the bbot-server repo root
bbctl server --dev start
```

The `--dev` flag works with all server subcommands (`start`, `stop`, `down`, `logs`, `status`, `compose`).

## Deploy with Helm (Kubernetes)

BBOT Server can be deployed to Kubernetes using its official Helm chart. The chart deploys the API server, worker, MongoDB, and Redis.
Expand Down
43 changes: 43 additions & 0 deletions bbot_server/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
x-bbot-server-base: &bbot-server-base
image: blacklanternsecurity/bbot-server:stable
restart: unless-stopped
volumes:
- "${BBOT_SERVER_CONFIG:-~/.config/bbot_server/config.yml}:/home/bbot/.config/bbot_server/config.yml"

services:
server:
<<: *bbot-server-base
ports:
- "${BBOT_LISTEN_ADDRESS:-127.0.0.1}:${BBOT_PORT:-8807}:8807"
command: ["bbctl", "server", "start", "--api-only", "--listen", "0.0.0.0"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8807/v1/docs"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
environment:
- BBOT_SERVER_AUTH_ENABLED=${BBOT_SERVER_AUTH_ENABLED:-true}
depends_on:
- mongodb
- redis

worker:
<<: *bbot-server-base
command: ["bbctl", "server", "start", "--worker-only"]
depends_on:
server:
condition: service_healthy

mongodb:
image: mongo:latest
restart: unless-stopped
volumes:
- bbot-mongodb:/data/db

redis:
image: redis:latest
restart: unless-stopped

volumes:
bbot-mongodb:
18 changes: 15 additions & 3 deletions bbot_server/modules/server/server_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import typer
import asyncio
import subprocess
from pathlib import Path
from subprocess import run
from contextlib import suppress

from bbot_server.config import BBOT_SERVER_CONFIG as bbcfg
from bbot_server.config import BBOT_SERVER_CONFIG as bbcfg, BBOT_SERVER_DIR
from bbot_server.cli.base import BaseBBCTL, subcommand, Option, Annotated


Expand All @@ -17,11 +16,24 @@ class ServerCTL(BaseBBCTL):
short_help = "Start/stop BBOT server and manage API keys"
attach_to = "bbctl"

_invoke_without_command = True
_no_args_is_help = True

def setup(self):
self._docker_command = None
self.docker_compose_dir = Path(__file__).parent.parent
self.docker_compose_dir = BBOT_SERVER_DIR
self.docker_compose_file = self.docker_compose_dir / "compose.yml"

def main(
self,
dev: Annotated[
bool, Option("--dev", "-d", help="Use dev compose file (builds from source, mounts code for live reload)")
] = False,
):
if dev:
self.docker_compose_dir = BBOT_SERVER_DIR.parent
self.docker_compose_file = self.docker_compose_dir / "compose.yml"

@subcommand(help="Start BBOT server")
def start(
self,
Expand Down
Loading