Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ README.md
__pycache__/*
lib/
.python-version
*.yaml
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PR Name

## Changes

Please provide a brief description of the major and minor changes made in this pull request.
116 changes: 116 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Publish Docker image

on:
push:
branches:
- main
paths:
- pyproject.toml
workflow_dispatch:
inputs:
version:
description: 'Version to publish'
required: false
default: 'latest'
type: string

jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read # required for actions/checkout
packages: write # required for pushing to ghcr.io
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'poetry'

- name: Install dependencies
run: poetry install

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.7.17"

- name: Download dependencies
run: |
uv sync

- name: Run ruff
run: |
uvx ruff check --fix --config ruff.toml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract all those targets into a makefile so it's easier to maintain and execute locally.

  • make lint
  • make test
    ...


- name: Run Unit Tests
run: |
uv run pytest --capture=tee-sys --junitxml=pytest.xml

- name: Run Test Coverage
run: |
uv run pytest --cov=. --cov-report=xml

- name: Extract version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's split this into a different job that depends on the previous. This way we can execute the previous one locally with act.

id: extract_version
run: |
VERSION=$(grep 'version =' pyproject.toml | sed -e 's/version = "\(.*\)"/\1/')-$(echo $GITHUB_SHA | cut -c1-7)
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/sysdiglabs/sysdig-mcp-server:latest
ghcr.io/sysdiglabs/sysdig-mcp-server:v${{ steps.extract_version.outputs.VERSION }}

- name: "Check test reports exists"
if: always()
id: check-test-results-exists
uses: andstor/file-existence-action@v3
with:
files: "pytest.xml, coverage.xml"

- name: Create pack-wise pytest report
run: poetry run python .github/github_workflow_scripts/parse_junit_per_pack.py
if: |
always() &&
steps.check-test-results-exists.outputs.files_exists == 'true' &&
github.event.pull_request.head.repo.fork == false

- name: Upload junit & pack-wise pytest report
uses: PaloAltoNetworks/[email protected]
if: |
always() &&
steps.check-test-results-exists.outputs.files_exists == 'true' &&
github.event.pull_request.head.repo.fork == false
with:
name: pytest
path: |
coverage.xml
if-no-files-found: error

- name: Pytest coverage comment
if: |
always() &&
steps.check-test-results-exists.outputs.files_exists == 'true' &&
steps.check-test-results-exists.outputs.files_exists == 'true' &&
! github.event.pull_request.head.repo.fork
uses: MishaKav/[email protected]
continue-on-error: true # may fail on output > 65k chars
with:
pytest-xml-coverage-path: coverage.xml
junitxml-path: coverage.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
pytest.xml
*,cover
.hypothesis/
venv/
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: local
hooks:
- id: ruff-format
name: Ruff Format
description: Format code with ruff.
entry: bash -c 'uvx ruff format --config ruff.toml'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In here we could use the previous mentioned make fmt

language: system
stages: ["commit", "push"]
- id: ruff-check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here make lint

name: Ruff Check
description: Check code style with ruff.
entry: bash -c 'uvx ruff check --config ruff.toml'
language: system
stages: ["commit", "push"]
5 changes: 5 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @S3B4SZ17 @alecron and @sysdiglabs/sysdig-training will be requested for
# review when someone opens a pull request.
* @S3B4SZ17 @alecron @sysdiglabs/sysdig-training
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to specify the single contributors and just leave the team. It's easier to maintain if there are movements in the org.

27 changes: 16 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@ ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy

WORKDIR /app
COPY . /app
RUN apt update && apt install -y git
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 --locked --no-install-project --no-editable
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --locked --no-install-project --no-editable --no-dev
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-editable
uv sync --locked --no-editable --no-dev

# Dinal image without uv
RUN uv build
RUN mv ./dist/sysdig_mcp_server-*-py3-none-any.whl /tmp/sysdig_mcp_server-1.0.0-py3-none-any.whl

# Final image without uv
FROM python:3.12-slim
# It is important to use the image that matches the builder, as the path to the
# Python executable must be the same

# Copy the application from the builder
COPY --from=builder --chown=app:app /app /app

WORKDIR /app

# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"
RUN apt update && apt install -y git
# Copy the application from the builder
COPY --from=builder --chown=app:app /tmp/sysdig_mcp_server-1.0.0-py3-none-any.whl /app
COPY --from=builder --chown=app:app /app/app_config.yaml /app

RUN pip install /app/sysdig_mcp_server-1.0.0-py3-none-any.whl

ENTRYPOINT ["/bin/sh", "entrypoint.sh"]
ENTRYPOINT ["sysdig-mcp-server"]
Loading