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
31 changes: 19 additions & 12 deletions .github/workflows/docker-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
docker-publish:
runs-on: ubuntu-latest
needs: docker-test
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/stable' }}
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/stable' || github.ref == 'refs/heads/dev') }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -61,39 +61,46 @@ jobs:
images: blacklanternsecurity/bbot-server
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=sha-
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=v${{ steps.version.outputs.major }}
type=raw,value=v${{ steps.version.outputs.minor }}
type=raw,value=v${{ steps.version.outputs.version }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/stable' }}
type=raw,value=v${{ steps.version.outputs.major }},enable=${{ github.ref == 'refs/heads/stable' }}
type=raw,value=v${{ steps.version.outputs.minor }},enable=${{ github.ref == 'refs/heads/stable' }}
type=raw,value=v${{ steps.version.outputs.version }},enable=${{ github.ref == 'refs/heads/stable' }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Clean up old Docker Hub tags (up to 50 most recent tags plus 'latest')
- name: Clean up old Docker Hub tags (keep 50 most recent plus protected tags)
run: |
# Install jq for JSON processing
sudo apt-get update && sudo apt-get install -y jq

echo "Cleaning up bbot-server tags..."

# Protected tags that should never be deleted
PROTECTED="latest stable dev v${{ steps.version.outputs.major }} v${{ steps.version.outputs.minor }} v${{ steps.version.outputs.version }}"

tags_response=$(curl -s -H "Authorization: Bearer ${{ secrets.DOCKER_TOKEN }}" \
"https://hub.docker.com/v2/repositories/bbot-server}/tags/?page_size=100")
"https://hub.docker.com/v2/repositories/blacklanternsecurity/bbot-server/tags/?page_size=100")

tags_to_delete=$(echo "$tags_response" | jq -r '.results[] | select(.name != "latest") | [.last_updated, .name] | @tsv' | \
sort -r | tail -n +51 | cut -f2)
tags_to_delete=$(echo "$tags_response" | jq -r '.results[].name' | sort -r | tail -n +51)

for tag in $tags_to_delete; do
# Skip protected tags
if echo "$PROTECTED" | grep -qw "$tag"; then
echo "Skipping protected tag: $tag"
continue
fi
echo "Deleting bbot-server tag: $tag"
curl -X DELETE -H "Authorization: Bearer ${{ secrets.DOCKER_TOKEN }}" \
"https://hub.docker.com/v2/repositories/bbot-server/tags/$tag/"
"https://hub.docker.com/v2/repositories/blacklanternsecurity/bbot-server/tags/$tag/"
done

echo "Cleanup completed for bbot-server. Kept 50 most recent tags plus 'latest'."
echo "Cleanup completed for bbot-server."
94 changes: 94 additions & 0 deletions .github/workflows/helm-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: helm tests
on:
push:
branches:
- stable
- dev
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
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 test_helm_deployment.py

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

helm-publish:
runs-on: ubuntu-latest
needs: helm-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: 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
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM ghcr.io/astral-sh/uv:python3.11-trixie
RUN apt-get -y update && apt-get -y install curl jq
COPY . /app
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-install-project
COPY . .
RUN uv sync --frozen
RUN useradd -u 1000 -m bbot && chown -R bbot:bbot /app
USER bbot
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8807
CMD ["uv", "run", "bbctl", "server", "start", "--api-only"]
5 changes: 4 additions & 1 deletion bbot_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
if not BBOT_SERVER_CONFIG_PATH.exists():
try:
BBOT_SERVER_CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
BBOT_SERVER_CONFIG_PATH.touch(mode=0o600)
# 644 permissions are necessary because we cannot predict the UID of the user running `bbctl`.
# since the config is mapped into the Docker container, BBOT server must have permissions to read it
# the alternative is running the BBOT server container as root
BBOT_SERVER_CONFIG_PATH.touch(mode=0o644)
# fill with commented defaults
with open(BBOT_SERVER_CONFIG_PATH, "w") as f:
with open(BBOT_SERVER_DEFAULTS_PATH, "r") as defaults_file:
Expand Down
10 changes: 1 addition & 9 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ x-bbot-server-base: &bbot-server-base
context: .
restart: unless-stopped
volumes:
- "${BBOT_SERVER_CONFIG:-~/.config/bbot_server/config.yml}:/root/.config/bbot_server/config.yml"
- "${BBOT_SERVER_CONFIG:-~/.config/bbot_server/config.yml}:/home/bbot/.config/bbot_server/config.yml"
- ./bbot_server:/app/bbot_server
- ./bbot_server/defaults_docker.yml:/app/bbot_server/defaults.yml

Expand Down Expand Up @@ -32,14 +32,6 @@ services:
server:
condition: service_healthy

agent:
<<: *bbot-server-base
command: ["bbctl", "agent", "start"]
entrypoint: ["bash", "/app/bbot_server/default_agent.sh"]
depends_on:
server:
condition: service_healthy

mongodb:
image: mongo:latest
restart: unless-stopped
Expand Down
9 changes: 9 additions & 0 deletions helm/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: mongodb
repository: https://charts.bitnami.com/bitnami
version: 18.6.1
- name: redis
repository: https://charts.bitnami.com/bitnami
version: 23.2.12
digest: sha256:b7c9095489913f065ee0cca4ec6aee1b320e07fd089f693360d42501a1220615
generated: "2026-02-25T16:20:43.56532327-05:00"
13 changes: 13 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v2
name: bbot-server
description: Helm chart for BBOT Server (API + Watchdog)
type: application
version: 0.1.0
appVersion: "0.1.0"
dependencies:
- name: mongodb
version: "18.x.x"
repository: "https://charts.bitnami.com/bitnami"
- name: redis
version: "23.x.x"
repository: "https://charts.bitnami.com/bitnami"
42 changes: 42 additions & 0 deletions helm/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Release.Name }}-ingress
labels:
app: bbot-server
app.kubernetes.io/instance: {{ .Release.Name | quote }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.className }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ $.Release.Name }}-server
port:
number: {{ $.Values.server.service.port }}
{{- end }}
{{- end }}
{{- end }}
20 changes: 20 additions & 0 deletions helm/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# BBOT Server API key (auto-generated on first install, preserved on upgrade)
{{- $apiKeySecretName := .Values.secrets.existingApiKeySecret | default (printf "%s-api-key" .Release.Name) -}}
{{- if not (lookup "v1" "Secret" .Release.Namespace $apiKeySecretName) }}
apiVersion: v1
kind: Secret
metadata:
name: {{ $apiKeySecretName }}
labels:
app.kubernetes.io/managed-by: "Helm"
app.kubernetes.io/instance: {{ .Release.Name | quote }}
annotations:
helm.sh/resource-policy: keep
type: Opaque
data:
{{- if .Values.secrets.apiKey }}
api-key: {{ .Values.secrets.apiKey | b64enc }}
{{- else }}
api-key: {{ uuidv4 | b64enc }}
{{- end }}
{{- end }}
Loading