Skip to content

Commit 79b53b8

Browse files
committed
docker: Build image and push to package registry
1 parent 18a83b8 commit 79b53b8

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'src/**'
9+
- 'apps/**'
10+
- 'data/**'
11+
- 'Dockerfile'
12+
- 'pyproject.toml'
13+
- '.github/workflows/docker-publish.yml'
14+
pull_request:
15+
branches:
16+
- main
17+
workflow_dispatch: # Allow manual trigger
18+
inputs:
19+
tag:
20+
description: 'Docker image tag (default: latest)'
21+
required: false
22+
default: 'latest'
23+
24+
env:
25+
REGISTRY: ghcr.io
26+
IMAGE_NAME: ${{ github.repository }}
27+
28+
jobs:
29+
build-and-push:
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
packages: write
34+
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Log in to GitHub Container Registry
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ${{ env.REGISTRY }}
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Extract metadata for Docker
50+
id: meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54+
tags: |
55+
type=ref,event=branch
56+
type=ref,event=pr
57+
type=semver,pattern={{version}}
58+
type=semver,pattern={{major}}.{{minor}}
59+
type=sha,prefix=sha-
60+
type=raw,value=latest,enable={{is_default_branch}}
61+
62+
- name: Build and push Docker image
63+
uses: docker/build-push-action@v5
64+
with:
65+
context: .
66+
file: ./Dockerfile
67+
push: true
68+
tags: ${{ steps.meta.outputs.tags }}
69+
labels: ${{ steps.meta.outputs.labels }}
70+
cache-from: type=gha
71+
cache-to: type=gha,mode=max
72+
platforms: linux/amd64
73+
74+
- name: Image digest
75+
run: echo ${{ steps.meta.outputs.digest }}

Dockerfile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Multi-stage build for optimized image size
2+
# Stage 1: Build dependencies
3+
FROM python:3.12-slim AS builder
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
build-essential \
8+
curl \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Install UV for fast dependency management
12+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
13+
14+
# Set working directory
15+
WORKDIR /app
16+
17+
# Copy dependency files
18+
COPY pyproject.toml README.md ./
19+
20+
# Install dependencies using UV (much faster than pip)
21+
# Install just the dependencies, not the package itself yet
22+
RUN uv pip install --system --no-cache \
23+
pandas>=2.3.1 \
24+
pyarrow>=20.0.0 \
25+
typer>=0.15.2 \
26+
adbc-driver-manager>=1.5.0 \
27+
adbc-driver-postgresql>=1.5.0 \
28+
protobuf>=4.21.0 \
29+
base58>=2.1.1 \
30+
eth-hash[pysha3]>=0.7.1 \
31+
eth-utils>=5.2.0 \
32+
google-cloud-bigquery>=3.30.0 \
33+
google-cloud-storage>=3.1.0 \
34+
arro3-core>=0.5.1 \
35+
arro3-compute>=0.5.1 \
36+
snowflake-connector-python>=4.0.0 \
37+
snowpipe-streaming>=1.0.0
38+
39+
# Stage 2: Runtime image
40+
FROM python:3.12-slim
41+
42+
# Install runtime dependencies only
43+
RUN apt-get update && apt-get install -y --no-install-recommends \
44+
libpq5 \
45+
&& rm -rf /var/lib/apt/lists/*
46+
47+
# Create non-root user for security
48+
RUN useradd -m -u 1000 amp && \
49+
mkdir -p /app /data && \
50+
chown -R amp:amp /app /data
51+
52+
# Set working directory
53+
WORKDIR /app
54+
55+
# Copy Python packages from builder
56+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
57+
58+
# Copy application code
59+
COPY --chown=amp:amp src/ ./src/
60+
COPY --chown=amp:amp apps/ ./apps/
61+
COPY --chown=amp:amp data/ ./data/
62+
COPY --chown=amp:amp pyproject.toml ./
63+
64+
# Switch to non-root user
65+
USER amp
66+
67+
# Set Python path
68+
ENV PYTHONPATH=/app
69+
ENV PYTHONUNBUFFERED=1
70+
71+
# Health check
72+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
73+
CMD python -c "import sys; sys.exit(0)"
74+
75+
# Default command - run ERC20 loader
76+
# Can be overridden with docker run arguments
77+
ENTRYPOINT ["python", "apps/test_erc20_labeled_parallel.py"]
78+
CMD ["--blocks", "100000", "--workers", "8", "--flush-interval", "0.5"]

0 commit comments

Comments
 (0)