Skip to content

Commit b506230

Browse files
committed
docker options added
1 parent 808c190 commit b506230

File tree

4 files changed

+292
-1
lines changed

4 files changed

+292
-1
lines changed

.dockerignore

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# Virtual environments
30+
.env
31+
.venv
32+
env/
33+
venv/
34+
ENV/
35+
env.bak/
36+
venv.bak/
37+
38+
# Testing
39+
.tox/
40+
.nox/
41+
.coverage
42+
.pytest_cache/
43+
cover/
44+
htmlcov/
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
52+
# IDE
53+
.idea/
54+
.vscode/
55+
*.swp
56+
*.swo
57+
*~
58+
59+
# OS
60+
.DS_Store
61+
.DS_Store?
62+
._*
63+
.Spotlight-V100
64+
.Trashes
65+
ehthumbs.db
66+
Thumbs.db
67+
68+
# Documentation
69+
docs/
70+
*.md
71+
!README.md
72+
73+
# CI/CD
74+
.github/
75+
.gitlab-ci.yml
76+
.travis.yml
77+
.circleci/
78+
79+
# Other
80+
*.log
81+
.mypy_cache/
82+
.dmypy.json
83+
dmypy.json
84+
.ruff_cache/
85+
.bandit

.github/workflows/docker.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*.*.*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to Container Registry
32+
if: github.event_name != 'pull_request'
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Extract metadata
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44+
tags: |
45+
type=ref,event=branch
46+
type=ref,event=pr
47+
type=semver,pattern={{version}}
48+
type=semver,pattern={{major}}.{{minor}}
49+
type=semver,pattern={{major}}
50+
type=raw,value=latest,enable={{is_default_branch}}
51+
52+
- name: Build and push Docker image
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
platforms: linux/amd64,linux/arm64
57+
push: ${{ github.event_name != 'pull_request' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max
62+
63+
- name: Verify image
64+
if: github.event_name != 'pull_request'
65+
run: |
66+
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest python -c "import symbiont; print(f'Symbiont SDK v{symbiont.__version__} ready')"

Dockerfile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Multi-stage build for smaller final image
2+
FROM python:3.11-slim AS builder
3+
4+
# Set build environment variables
5+
ENV PYTHONUNBUFFERED=1 \
6+
PYTHONDONTWRITEBYTECODE=1 \
7+
PIP_NO_CACHE_DIR=1 \
8+
PIP_DISABLE_PIP_VERSION_CHECK=1
9+
10+
# Install build dependencies
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
build-essential \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Create and use non-root user
16+
RUN groupadd --gid 1001 symbiont && \
17+
useradd --uid 1001 --gid symbiont --shell /bin/bash --create-home symbiont
18+
19+
# Set working directory
20+
WORKDIR /app
21+
22+
# Copy requirements and install dependencies
23+
COPY requirements.txt requirements-dev.txt ./
24+
RUN pip install --user --no-cache-dir -r requirements.txt
25+
26+
# Copy source code
27+
COPY . .
28+
29+
# Install the package
30+
RUN pip install --user .
31+
32+
# Production stage
33+
FROM python:3.11-slim
34+
35+
# Set runtime environment variables
36+
ENV PYTHONUNBUFFERED=1 \
37+
PYTHONDONTWRITEBYTECODE=1 \
38+
PATH="/home/symbiont/.local/bin:$PATH"
39+
40+
# Install runtime dependencies
41+
RUN apt-get update && apt-get install -y --no-install-recommends \
42+
ca-certificates \
43+
&& rm -rf /var/lib/apt/lists/*
44+
45+
# Create non-root user
46+
RUN groupadd --gid 1001 symbiont && \
47+
useradd --uid 1001 --gid symbiont --shell /bin/bash --create-home symbiont
48+
49+
# Copy installed packages from builder
50+
COPY --from=builder --chown=symbiont:symbiont /root/.local /home/symbiont/.local
51+
52+
# Copy source code
53+
WORKDIR /app
54+
COPY --chown=symbiont:symbiont . .
55+
56+
# Switch to non-root user
57+
USER symbiont
58+
59+
# Verify installation
60+
RUN python -c "import symbiont; print(f'Symbiont SDK v{symbiont.__version__} installed successfully')"
61+
62+
# Default command - Python REPL with SDK available
63+
CMD ["python", "-c", "import symbiont; print('Symbiont SDK ready. Use: from symbiont import SymbiontClient'); exec(open('/dev/stdin').read()) if not __import__('sys').stdin.isatty() else __import__('code').interact(local=globals())"]
64+
65+
# Health check
66+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
67+
CMD python -c "import symbiont; print('OK')" || exit 1
68+
69+
# Labels for metadata
70+
LABEL org.opencontainers.image.title="Symbiont Python SDK" \
71+
org.opencontainers.image.description="Python SDK for Symbiont platform with Tool Review and Runtime APIs" \
72+
org.opencontainers.image.url="https://github.com/thirdkeyai/symbiont-sdk-python" \
73+
org.opencontainers.image.source="https://github.com/thirdkeyai/symbiont-sdk-python" \
74+
org.opencontainers.image.vendor="ThirdKey.ai" \
75+
org.opencontainers.image.licenses="MIT"

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,57 @@ cd symbiont-sdk-python
2424
pip install -e .
2525
```
2626

27+
### Docker
28+
29+
The SDK is also available as a Docker image from GitHub Container Registry:
30+
31+
```bash
32+
# Pull the latest image
33+
docker pull ghcr.io/thirdkeyai/symbiont-sdk-python:latest
34+
35+
# Or pull a specific version
36+
docker pull ghcr.io/thirdkeyai/symbiont-sdk-python:v0.2.0
37+
```
38+
39+
#### Running with Docker
40+
41+
```bash
42+
# Run interactively with Python REPL
43+
docker run -it --rm ghcr.io/thirdkeyai/symbiont-sdk-python:latest
44+
45+
# Run with environment variables
46+
docker run -it --rm \
47+
-e SYMBIONT_API_KEY=your_api_key \
48+
-e SYMBIONT_BASE_URL=http://host.docker.internal:8080/api/v1 \
49+
ghcr.io/thirdkeyai/symbiont-sdk-python:latest
50+
51+
# Run a Python script from host
52+
docker run --rm \
53+
-v $(pwd):/workspace \
54+
-w /workspace \
55+
-e SYMBIONT_API_KEY=your_api_key \
56+
ghcr.io/thirdkeyai/symbiont-sdk-python:latest \
57+
python your_script.py
58+
59+
# Execute one-liner
60+
docker run --rm \
61+
-e SYMBIONT_API_KEY=your_api_key \
62+
ghcr.io/thirdkeyai/symbiont-sdk-python:latest \
63+
python -c "from symbiont import Client; print(Client().health_check())"
64+
```
65+
66+
#### Building Docker Image Locally
67+
68+
```bash
69+
# Build from source
70+
git clone https://github.com/thirdkeyai/symbiont-sdk-python.git
71+
cd symbiont-sdk-python
72+
docker build -t symbiont-sdk:local .
73+
74+
# Run locally built image
75+
docker run -it --rm symbiont-sdk:local
76+
```
77+
2778
## Configuration
2879

2980
The SDK can be configured using environment variables in a `.env` file. Copy the provided `.env.example` file to get started:
@@ -488,4 +539,18 @@ To create a PyPI API token:
488539
2. Create new token with scope for this project
489540
3. Add to GitHub repository secrets as `PYPI_API_TOKEN`
490541

491-
The release workflow will automatically publish to PyPI when a new tag is pushed.
542+
#### Container Registry Publishing
543+
544+
The Docker workflow automatically publishes container images to GitHub Container Registry:
545+
546+
- **Latest image**: Published on every push to main branch (`ghcr.io/thirdkeyai/symbiont-sdk-python:latest`)
547+
- **Version tags**: Published on release tags (`ghcr.io/thirdkeyai/symbiont-sdk-python:v0.2.0`)
548+
- **Branch tags**: Published for feature branches during development
549+
550+
Images are built for multiple architectures (linux/amd64, linux/arm64) and include:
551+
- Multi-stage optimized builds for smaller image size
552+
- Non-root user execution for security
553+
- Health checks for container monitoring
554+
- Full SDK functionality with all dependencies
555+
556+
Both the release workflow (PyPI) and Docker workflow (container registry) will automatically run when a new tag is pushed.

0 commit comments

Comments
 (0)