Repository navigation
BED-10186: Publish OpenHound GitHub containers to GHCR #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jaredcatkinson
merged 2 commits into
main
from
feature/BED-10186-publish-container-to-ghcr
Oct 21, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Only application inputs belong in the build context. | ||
| ** | ||
| !Dockerfile | ||
| !.dockerignore | ||
| !pyproject.toml | ||
| !uv.lock | ||
| !README.md | ||
| !LICENSE.md | ||
| !src/ | ||
| !src/** | ||
| **/__pycache__/ | ||
| **/*.pyc | ||
| **/.dlt/ | ||
| **/*.pem | ||
| **/*.key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| name: Build and publish container | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| tag: | ||
| description: Existing release tag to build | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| concurrency: | ||
| group: container-${{ inputs.tag }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| publish: | ||
| if: >- | ||
| github.repository == 'SpecterOps/openhound-github' && | ||
| github.event_name == 'pull_request' && | ||
| github.event.action == 'closed' && | ||
| github.event.pull_request.merged == true && | ||
| github.event.pull_request.base.ref == 'main' | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| target: [cli, enterprise] | ||
| steps: | ||
| - name: Validate release tag | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| run: | | ||
| [[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { | ||
| echo "Expected a release tag such as v0.20.0" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| - name: Checkout release | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: refs/tags/${{ inputs.tag }} | ||
|
|
||
| - name: Set image metadata | ||
| id: image | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| REPOSITORY: ${{ github.repository }} | ||
| TARGET: ${{ matrix.target }} | ||
| run: | | ||
| VERSION=${RELEASE_TAG#v} | ||
| IMAGE="ghcr.io/${REPOSITORY,,}" | ||
| SUFFIX="" | ||
| if [[ "$TARGET" == cli ]]; then SUFFIX="-cli"; fi | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "tag=$IMAGE:$VERSION$SUFFIX" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - name: Build smoke-test image | ||
| uses: docker/build-push-action@v7 | ||
| with: | ||
| context: . | ||
| target: ${{ matrix.target }} | ||
| platforms: linux/amd64 | ||
| load: true | ||
| tags: openhound-github:smoke | ||
| build-args: | | ||
| COLLECTOR_VERSION=${{ steps.image.outputs.version }} | ||
| cache-from: type=gha,scope=${{ matrix.target }} | ||
|
|
||
| - name: Verify runtime and installed collector | ||
| env: | ||
| EXPECTED_VERSION: ${{ steps.image.outputs.version }} | ||
| run: | | ||
| docker run --rm --entrypoint python -e EXPECTED_VERSION openhound-github:smoke -c ' | ||
| import importlib.metadata as metadata | ||
| import os | ||
| import runpy | ||
| from unittest.mock import patch | ||
| import openhound_github.main | ||
| assert os.getuid() != 0 | ||
| assert metadata.version("openhound-github") == os.environ["EXPECTED_VERSION"] | ||
| entries = metadata.entry_points(group="openhound.sources") | ||
| assert any(entry.name == "github" and entry.load() for entry in entries) | ||
| with patch.dict(os.environ, { | ||
| "DESTINATION__BLOODHOUNDENTERPRISE__URL": "https://example.invalid", | ||
| "DESTINATION__BLOODHOUNDENTERPRISE__TOKEN_ID": "smoke-test-id", | ||
| "DESTINATION__BLOODHOUNDENTERPRISE__TOKEN_KEY": "smoke-test-key", | ||
| }), patch("openhound.scheduler.service.Service", autospec=True) as service: | ||
| runpy.run_path("/app/src/scheduler.py", run_name="__main__") | ||
| assert service.call_args.kwargs["collector_name"] == "github" | ||
| service.return_value.start.assert_called_once_with() | ||
| ' | ||
|
|
||
| - name: Verify CLI | ||
| if: matrix.target == 'cli' | ||
| run: docker run --rm openhound-github:smoke --help | ||
|
|
||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and push multi-architecture image | ||
| uses: docker/build-push-action@v7 | ||
| with: | ||
| context: . | ||
| target: ${{ matrix.target }} | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| sbom: true | ||
| tags: ${{ steps.image.outputs.tag }} | ||
| labels: | | ||
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | ||
| org.opencontainers.image.version=${{ steps.image.outputs.version }} | ||
| build-args: | | ||
| COLLECTOR_VERSION=${{ steps.image.outputs.version }} | ||
| cache-from: type=gha,scope=${{ matrix.target }} | ||
| cache-to: type=gha,mode=max,scope=${{ matrix.target }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # syntax=docker/dockerfile:1 | ||
| FROM ghcr.io/astral-sh/uv:python3.13-trixie-slim AS builder | ||
|
|
||
| ENV UV_COMPILE_BYTECODE=1 \ | ||
| UV_LINK_MODE=copy \ | ||
| UV_PYTHON_DOWNLOADS=0 | ||
|
|
||
| ARG COLLECTOR_VERSION | ||
| ENV SETUPTOOLS_SCM_PRETEND_VERSION=${COLLECTOR_VERSION} | ||
|
|
||
| WORKDIR /app | ||
| COPY pyproject.toml uv.lock README.md LICENSE.md ./ | ||
| COPY src ./src | ||
| RUN test -n "$COLLECTOR_VERSION" | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --no-dev --group container --frozen --no-editable | ||
|
|
||
| FROM gcr.io/distroless/python3-debian13:nonroot AS base | ||
|
|
||
| ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
| PYTHONUNBUFFERED=1 \ | ||
| PYTHONPATH=/app/.venv/lib/python3.13/site-packages \ | ||
| LOG_CONTAINER=true \ | ||
| RUNTIME__LOG_PATH=/app/logs \ | ||
| DESTINATION__BLOODHOUNDENTERPRISE__COLLECTOR_NAME=github | ||
|
|
||
| COPY --from=builder --chown=nonroot:nonroot /app /app | ||
| WORKDIR /app | ||
|
|
||
| FROM base AS cli | ||
| ENTRYPOINT ["python", "-m", "openhound"] | ||
| CMD ["--help"] | ||
|
|
||
| FROM base AS enterprise | ||
| ENTRYPOINT ["python", "src/scheduler.py"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Start the BloodHound Enterprise scheduler for the configured collector.""" | ||
|
|
||
| import logging | ||
|
|
||
| import dlt | ||
|
|
||
| from openhound.scheduler.service import Service | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def start() -> None: | ||
| collector_name = dlt.config["destination.bloodhoundenterprise.collector_name"] | ||
| logger.info("Initializing service for collector '%s'.", collector_name) | ||
| service = Service( | ||
| bhe_uri=dlt.secrets["destination.bloodhoundenterprise.url"], | ||
| token_key=dlt.secrets["destination.bloodhoundenterprise.token_key"], | ||
| token_id=dlt.secrets["destination.bloodhoundenterprise.token_id"], | ||
| collector_name=collector_name, | ||
| ) | ||
| service.start() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| start() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.