Skip to content

Commit 8bc640a

Browse files
authored
feat(engine): Dockerise Tracecat CLI (TracecatHQ#225)
* Add Dockerfile for CLI * build push cli image * missing pyyaml * build: Missing cli deps * fix path to version in cli * Set versions to 0.1.4-dev * remove prefix echo version * Update CLI install docs with just docker option * fix alias instructions
1 parent 8b82c45 commit 8bc640a

File tree

7 files changed

+94
-66
lines changed

7 files changed

+94
-66
lines changed

.github/workflows/build-push-images.yml

+48-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,54 @@ jobs:
108108
NODE_ENV=$NODE_ENV
109109
push: ${{ github.event_name != 'pull_request' }}
110110
platforms: linux/amd64,linux/arm64
111+
tags: ${{ steps.meta.outputs.tags }}
112+
${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && 'ghcr.io/tracecathq/tracecat-ui:latest' || '' }}
113+
labels: ${{ steps.meta.outputs.labels }}
114+
115+
push-cli-to-ghcr:
116+
runs-on: ubuntu-latest
117+
steps:
118+
- name: Checkout repository
119+
uses: actions/checkout@v4
120+
121+
- name: Set up QEMU
122+
uses: docker/setup-qemu-action@v3
123+
124+
- name: Set up Docker Buildx
125+
uses: docker/setup-buildx-action@v3
126+
127+
- name: Log in to the Container registry
128+
uses: docker/login-action@v3
129+
with:
130+
registry: ghcr.io
131+
username: ${{ github.actor }}
132+
password: ${{ secrets.GITHUB_TOKEN }}
133+
134+
- name: Extract Docker metadata
135+
id: meta
136+
uses: docker/metadata-action@v5
137+
with:
138+
images: |
139+
ghcr.io/tracecathq/tracecat-cli
140+
tags: |
141+
type=ref,event=branch
142+
type=ref,event=pr
143+
type=semver,pattern={{version}}
144+
type=semver,pattern={{major}}.{{minor}}
145+
146+
- name: Build and push Docker image
147+
uses: docker/build-push-action@v6
148+
with:
149+
context: .
150+
file: Dockerfile.cli
151+
push: ${{ github.event_name != 'pull_request' }}
152+
platforms: linux/amd64,linux/arm64
111153
tags: |
112154
${{ steps.meta.outputs.tags }}
113-
${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && 'ghcr.io/tracecathq/tracecat-ui:latest' || '' }}
155+
${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && 'ghcr.io/tracecathq/tracecat-cli:latest' || '' }}
114156
labels: ${{ steps.meta.outputs.labels }}
157+
158+
- name: Verify Docker CLI commands
159+
run: |
160+
docker run --rm ghcr.io/tracecathq/tracecat-cli
161+
docker run --rm ghcr.io/tracecathq/tracecat-cli --version

Dockerfile.cli

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM python:3.12-slim-bookworm
2+
3+
ENV PYTHONUNBUFFERED=1 \
4+
PYTHONDONTWRITEBYTECODE=1
5+
6+
RUN groupadd --gid 1000 appuser && \
7+
useradd --uid 1000 --gid 1000 --shell /bin/bash --create-home appuser
8+
9+
WORKDIR /app
10+
11+
COPY cli/pyproject.toml /app/
12+
COPY cli/tracecat_cli /app/tracecat_cli
13+
COPY LICENSE cli/README.md /app/
14+
15+
RUN apt-get update && rm -rf /var/lib/apt/lists/*
16+
RUN chown -R appuser:appuser /app
17+
18+
USER appuser
19+
20+
RUN pip install --upgrade pip
21+
RUN pip install .
22+
23+
# Add the directory where pip installs executables to the PATH
24+
ENV PATH="/home/appuser/.local/bin:$PATH"
25+
26+
ENTRYPOINT ["tracecat"]

cli/pyproject.toml

+8-12
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,21 @@ classifiers = [
2121
"Topic :: System :: Monitoring",
2222
"Topic :: System :: Systems Administration",
2323
]
24-
dependencies = ["typer==0.12.3", "python-dotenv==1.0.1", "orjson==3.10.3"]
24+
dependencies = [
25+
"orjson==3.10.3",
26+
"python-dotenv==1.0.1",
27+
"pydantic==2.6.1",
28+
"PyYAML==6.0.1",
29+
"httpx==0.27.0",
30+
"typer==0.12.3",
31+
]
2532
dynamic = ["version"]
2633

2734
[project.urls]
2835
Homepage = "https://tracecat.com"
2936
Documentation = "https://docs.tracecat.com/"
3037
Repository = "https://github.com/TracecatHQ/tracecat"
3138

32-
[project.optional-dependencies]
33-
dev = [
34-
"respx",
35-
"pytest",
36-
"pytest-asyncio",
37-
"pytest-mock==3.14.0",
38-
"minio",
39-
"mypy",
40-
"pre-commit",
41-
]
42-
4339
[project.scripts]
4440
tracecat = "tracecat_cli.__main__:main"
4541

cli/tracecat_cli/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.0"
1+
__version__ = "0.1.4-dev"

cli/tracecat_cli/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
def version_callback(value: bool):
1111
if value:
12-
from tracecat import __version__
12+
from tracecat_cli import __version__
1313

14-
typer.echo(f"Tracecat version: {__version__}")
14+
typer.echo(__version__)
1515
raise typer.Exit()
1616

1717

docs/using-the-cli.mdx

+8-49
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,18 @@ It's the fastest way to interact with Tracecat and is perfect for automating tas
77

88
## Installation
99

10-
To install the Tracecat CLI, you will need Python 3.12 installed.
11-
We recommend using `micromamba` to help with managing multiple Python environments.
12-
13-
<Note>
14-
We are working on making our CLI tool more portable so you don't have to use
15-
`micromamba` in the future.
16-
</Note>
17-
18-
### Setup a Micromamba environment
19-
20-
Micromamba is a standalone, pure C++ implementation of the mamba package manager, designed as a smaller and faster alternative to conda.
21-
It is distributed as a single, statically linked executable file that does not require a base environment or a default Python installation.
22-
23-
Full installation instructions [here](https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html#operating-system-package-managers)
24-
25-
<CodeGroup>
26-
27-
```bash MacOS
28-
brew install micromamba
29-
```
30-
31-
```bash Linux + WSL
32-
"${SHELL}" <(curl -L micro.mamba.pm/install.sh)
33-
# You might have to add the binary to your PATH, then follow on-screen instructions
34-
# to restart and initialize your shell to complete the installation
35-
```
36-
37-
</CodeGroup>
38-
39-
With `micromamba` installed, you can now install the Tracecat CLI.
40-
We create a virtual environment for Tracecat to avoid conflicts with other Python packages.
41-
42-
```bash
43-
micromamba env create -n tracecat python=3.12
44-
micromamba activate tracecat
45-
```
46-
47-
If the environment is activated correctly, you should see something like this in your shell:
10+
To install and run the Tracecat CLI, you will need `docker`.
4811

4912
```bash
50-
(tracecat) ~/tracecat $
51-
```
52-
53-
Now from the root of the Tracecat repository, you can install the CLI using `pip`:
13+
# Pull the latest image
14+
docker pull ghcr.io/tracecathq/tracecat-cli
5415

55-
```bash /path/to/tracecat
56-
pip install ".[cli]"
57-
```
16+
# Create an alias to run the CLI in a container
17+
alias tracecat='docker run --rm ghcr.io/tracecathq/tracecat-cli "$@"'
5818

59-
If installed correctly, you should be able to run the `tracecat` command and see the help output:
60-
61-
```bash
62-
tracecat
19+
# Finally source your shell profile
20+
# NOTE: can be ~/.bashrc, ~/.zshrc, etc.
21+
source ~/.bashrc
6322
```
6423

6524
## Workflow Management

tracecat/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Tracecat is the open source Tines alternative."""
22

3-
__version__ = "0.1.1"
3+
__version__ = "0.1.4-dev"

0 commit comments

Comments
 (0)