Skip to content

Commit 9733ae3

Browse files
committed
Added Docker container.
1 parent e821d7d commit 9733ae3

File tree

5 files changed

+301
-0
lines changed

5 files changed

+301
-0
lines changed

.dockerignore

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
.venv/
31+
.env/
32+
venv/
33+
env/
34+
35+
# IDE
36+
.vscode/
37+
.idea/
38+
*.swp
39+
*.swo
40+
*~
41+
42+
# OS
43+
.DS_Store
44+
.DS_Store?
45+
._*
46+
.Spotlight-V100
47+
.Trashes
48+
ehthumbs.db
49+
Thumbs.db
50+
51+
# Testing and Coverage
52+
.pytest_cache/
53+
.coverage
54+
htmlcov/
55+
.tox/
56+
.nox/
57+
coverage.xml
58+
*.cover
59+
*.py,cover
60+
.hypothesis/
61+
62+
# Linting and Type Checking
63+
.mypy_cache/
64+
.ruff_cache/
65+
.dmypy.json
66+
dmypy.json
67+
68+
# Development
69+
.pre-commit-config.yaml
70+
.github/
71+
examples/
72+
tests/
73+
74+
# Docker
75+
Dockerfile
76+
.dockerignore
77+
docker-compose.yml
78+
docker-compose.*.yml
79+
80+
# Documentation
81+
*.md
82+
!README.md
83+
84+
# Environment files
85+
.env
86+
.env.local
87+
.env.*.local
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Docker Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
build-and-push:
13+
name: Build and Push Docker Image
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v5
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to Container Registry
27+
uses: docker/login-action@v4
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Extract metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
tags: |
39+
type=ref,event=tag
40+
type=raw,value=latest,enable={{is_default_branch}}
41+
42+
- name: Build and push Docker image
43+
id: build
44+
uses: docker/build-push-action@v6
45+
with:
46+
context: .
47+
platforms: linux/amd64,linux/arm64
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}
51+
cache-from: type=gha
52+
cache-to: type=gha,mode=max
53+
54+
- name: Generate artifact attestation
55+
uses: actions/attest-build-provenance@v2
56+
with:
57+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
58+
subject-digest: ${{ steps.build.outputs.digest }}
59+
push-to-registry: true

.github/workflows/docker-test.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Docker Build Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
paths:
8+
- 'Dockerfile'
9+
- '.dockerignore'
10+
- 'pyproject.toml'
11+
- 'uv.lock'
12+
- 'eoapi_notifier/**'
13+
- '.github/workflows/docker-*.yml'
14+
15+
env:
16+
IMAGE_NAME: eoapi-notifier
17+
18+
jobs:
19+
docker-build-test:
20+
name: Test Docker Build
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v5
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Build Docker image
31+
uses: docker/build-push-action@v6
32+
with:
33+
context: .
34+
push: false
35+
tags: ${{ env.IMAGE_NAME }}:test
36+
cache-from: type=gha
37+
cache-to: type=gha,mode=max
38+
39+
- name: Test Docker image
40+
run: |
41+
echo "🐳 Testing Docker image functionality..."
42+
43+
# Test help command
44+
docker run --rm ${{ env.IMAGE_NAME }}:test --help
45+
46+
# Test version command
47+
docker run --rm ${{ env.IMAGE_NAME }}:test --version
48+
49+
# Test with invalid config (should show error)
50+
echo "Testing error handling..."
51+
docker run --rm ${{ env.IMAGE_NAME }}:test /nonexistent/config.yaml || \
52+
echo "✅ Expected error handled correctly"
53+
54+
echo "✅ All Docker tests passed!"
55+
56+
- name: Check image size
57+
run: |
58+
echo "📊 Docker image information:"
59+
docker images ${{ env.IMAGE_NAME }}:test
60+
61+
# Get image size in MB
62+
SIZE=$(docker images ${{ env.IMAGE_NAME }}:test --format "{{.Size}}" | head -n1)
63+
echo "Image size: $SIZE"
64+
65+
# Optional: Warn if image is getting too large (>500MB)
66+
SIZE_BYTES=$(docker inspect ${{ env.IMAGE_NAME }}:test --format='{{.Size}}')
67+
SIZE_MB=$((SIZE_BYTES / 1024 / 1024))
68+
echo "Image size: ${SIZE_MB}MB"
69+
70+
if [ $SIZE_MB -gt 500 ]; then
71+
echo "⚠️ Warning: Image size (${SIZE_MB}MB) is quite large. Consider optimization."
72+
else
73+
echo "✅ Image size looks reasonable: ${SIZE_MB}MB"
74+
fi

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM python:3.12-slim
2+
3+
# Set environment variables
4+
ENV PYTHONUNBUFFERED=1 \
5+
PYTHONDONTWRITEBYTECODE=1 \
6+
PIP_NO_CACHE_DIR=1 \
7+
PIP_DISABLE_PIP_VERSION_CHECK=1
8+
9+
# Install system dependencies
10+
RUN apt-get update && apt-get install -y \
11+
curl \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Install uv
15+
RUN pip install uv
16+
17+
# Set work directory
18+
WORKDIR /app
19+
20+
# Copy all necessary files for the build
21+
COPY pyproject.toml uv.lock README.md LICENSE ./
22+
COPY eoapi_notifier/ ./eoapi_notifier/
23+
24+
# Install dependencies and the package
25+
RUN uv sync --frozen --no-dev --no-cache
26+
27+
# Create a non-root user
28+
RUN useradd --create-home --shell /bin/bash app && chown -R app:app /app
29+
USER app
30+
31+
# Set the entry point
32+
ENTRYPOINT ["uv", "run", "eoapi-notifier"]
33+
CMD ["--help"]

docs/docker.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Docker
2+
3+
The application is available as a Docker image hosted on GitHub Container Registry (GHCR). Docker images are automatically built and published when new releases are created.
4+
5+
### Pull the Image
6+
7+
```bash
8+
# Pull the latest version
9+
docker pull ghcr.io/developmentseed/eoapi-notifier:latest
10+
11+
# Pull a specific version (replace v1.0.0 with desired version)
12+
docker pull ghcr.io/developmentseed/eoapi-notifier:v1.0.0
13+
```
14+
15+
### Running with Docker
16+
17+
**Show help:**
18+
```bash
19+
docker run --rm ghcr.io/developmentseed/eoapi-notifier:latest
20+
```
21+
22+
**Show version:**
23+
```bash
24+
docker run --rm ghcr.io/developmentseed/eoapi-notifier:latest --version
25+
```
26+
27+
**Run with a configuration file:**
28+
```bash
29+
docker run --rm -v /path/to/your/config.yaml:/app/config.yaml \
30+
ghcr.io/developmentseed/eoapi-notifier:latest config.yaml
31+
```
32+
33+
**Run with custom log level:**
34+
```bash
35+
docker run --rm -v /path/to/your/config.yaml:/app/config.yaml \
36+
ghcr.io/developmentseed/eoapi-notifier:latest --log-level DEBUG config.yaml
37+
```
38+
39+
### Building Locally
40+
41+
If you prefer to build the Docker image locally:
42+
43+
```bash
44+
docker build -t eoapi-notifier .
45+
docker run --rm eoapi-notifier --help
46+
```
47+
48+
The Docker image is based on `python:3.12-slim` and includes all necessary dependencies. The image runs as a non-root user for security.

0 commit comments

Comments
 (0)