Skip to content

Commit 017577e

Browse files
Merge pull request #33 from Sonnet-Scripts/mf-simplify-linux-python-build
Mf simplify linux python build
2 parents 3b134a3 + 777e6b1 commit 017577e

9 files changed

Lines changed: 65 additions & 132 deletions

File tree

.devcontainer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
"name": "Sonnet Scripts Dev Container",
33
"dockerComposeFile": "docker-compose.yml",
44
"service": "pythonbase",
5+
"workspaceFolder": "/sonnet-scripts",
56
"initializeCommand": [
6-
"/bin/sh", "-c", "docker compose build linuxbase && docker compose build pythonbase"
7+
"/bin/sh", "-c", "docker compose build pythonbase"
78
],
8-
"workspaceFolder": "/workspaces/sonnet-scripts",
9-
"mounts": [
10-
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
11-
],
12-
"features": {
13-
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
9+
"features": {
10+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
11+
"moby": false
12+
},
13+
"ghcr.io/devcontainers/features/git:1": {},
14+
"ghcr.io/devcontainers/features/common-utils:2": {}
1415
},
1516
"customizations": {
1617
"vscode": {
@@ -19,4 +20,4 @@
1920
]
2021
}
2122
}
22-
}
23+
}

.github/workflows/ci_pipeline.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727

2828
- name: Build Docker Images
2929
run: |
30-
docker build -t linuxbase linuxbase
3130
docker build -t pythonbase pythonbase
3231
3332
- name: Start Docker Compose

Makefile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# Set up the project with Docker Compose
22
setup:
3-
@docker compose build linuxbase
4-
@docker compose build pythonbase
5-
@docker compose build pipelinebase
6-
@docker compose build dbtbase
7-
@docker compose build
3+
@docker compose ps pythonbase --format json | grep -q pythonbase || docker compose build pythonbase
4+
@docker compose build $$(docker compose config --services | grep -v pythonbase)
85
@docker compose up -d
96

107
# Install the sonnet CLI tool
@@ -21,7 +18,6 @@ rebuild:
2118
# Completely clean up Docker environment and rebuild containers from scratch
2219
rebuild-clean:
2320
@docker compose down -v --remove-orphans --rmi all
24-
@docker compose build --no-cache linuxbase
2521
@docker compose build --no-cache pythonbase
2622
@docker compose build --no-cache pipelinebase
2723
@docker compose build --no-cache dbtbase
@@ -66,10 +62,6 @@ else
6662
xdg-open "http://localhost:8978"
6763
endif
6864

69-
# Execute a shell inside the linuxbase container
70-
exec-linuxbase:
71-
@docker compose exec linuxbase bash
72-
7365
# Load data into PostgreSQL
7466
load-db:
7567
@docker compose exec -e PYTHONPATH=/apps pipelinebase /venv/bin/python -m ingest_claims.load_claims_to_db

dbtbase/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM pythonbase:latest
1+
FROM pythonbase
22

33
# Set the Working Directory
44
WORKDIR /apps

docker-compose.yml

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@ services:
55
context: ./pythonbase
66
container_name: pythonbase
77
image: pythonbase
8-
depends_on:
9-
linuxbase:
10-
condition: service_completed_successfully
8+
stdin_open: true
9+
tty: true
1110
ports:
1211
- "4213:4213"
13-
12+
volumes:
13+
- .:/sonnet-scripts
14+
- /var/run/docker.sock:/var/run/docker.sock
15+
working_dir: /sonnet-scripts
16+
healthcheck:
17+
test: ["CMD", "python", "--version"]
18+
interval: 30s
19+
timeout: 10s
20+
retries: 3
21+
start_period: 15s
22+
1423
jupyterbase:
1524
build:
1625
context: ./jupyterbase
1726
container_name: jupyterbase
1827
image: jupyterbase
1928
depends_on:
2029
pythonbase:
21-
condition: service_started
30+
condition: service_healthy
2231
pgduckdb:
2332
condition: service_healthy
2433
ports:
@@ -31,7 +40,7 @@ services:
3140
image: pipelinebase
3241
depends_on:
3342
pythonbase:
34-
condition: service_started
43+
condition: service_healthy
3544
pgduckdb:
3645
condition: service_healthy
3746
minio:
@@ -44,7 +53,7 @@ services:
4453
image: dbtbase
4554
depends_on:
4655
pythonbase:
47-
condition: service_started
56+
condition: service_healthy
4857
pgduckdb:
4958
condition: service_healthy
5059
environment:
@@ -56,12 +65,6 @@ services:
5665
volumes:
5766
- dbt_data:/apps/data
5867

59-
linuxbase:
60-
build:
61-
context: ./linuxbase
62-
container_name: linuxbase
63-
image: linuxbase
64-
6568
pgduckdb:
6669
image: pgduckdb/pgduckdb:17-v0.1.0
6770
container_name: pgduckdb
@@ -76,6 +79,8 @@ services:
7679
healthcheck:
7780
test: ["CMD", "pg_isready", "-U", "postgres"]
7881
retries: 5
82+
interval: 10s
83+
timeout: 5s
7984

8085
pgadmin:
8186
image: dpage/pgadmin4:9.3.0
@@ -121,24 +126,10 @@ services:
121126
- 9000:9000
122127
command: ["server", "/data", "--console-address", ":9001"]
123128

124-
cloudbeaver:
125-
image: dbeaver/cloudbeaver:25.0.3
126-
container_name: cloudbeaver
127-
ports:
128-
- "8978:8978"
129-
volumes:
130-
- cloudbeaver-data:/opt/cloudbeaver/workspace
131-
- ./cloudbeaver/conf/.cloudbeaver.auto.conf:/opt/cloudbeaver/conf/.cloudbeaver.auto.conf
132-
- ./cloudbeaver/conf/.cloudbeaver.runtime.conf:/opt/cloudbeaver/workspace/.data/.cloudbeaver.runtime.conf
133-
depends_on:
134-
- pgduckdb
135-
136129
volumes:
137130
pgduckdb_data:
138131
driver: local
139132
data:
140133
driver: local
141-
cloudbeaver-data:
142-
driver: local
143134
dbt_data:
144135
driver: local

jupyterbase/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM pythonbase:latest
1+
FROM pythonbase
22

33
# Set the Working Directory
44
WORKDIR /apps

linuxbase/Dockerfile

Lines changed: 0 additions & 43 deletions
This file was deleted.

pipelinebase/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM pythonbase:latest
1+
FROM pythonbase
22

33
# Set the Working Directory
44
WORKDIR /apps

pythonbase/Dockerfile

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,60 @@
1-
FROM linuxbase AS pythonbase
1+
FROM python:3.12
2+
3+
# Set environment variables for localization and timezone settings
4+
ENV LANG=en_US.UTF-8 \
5+
LANGUAGE=en_US:en \
6+
LC_ALL=en_US.UTF-8 \
7+
TZ="America/Chicago" \
8+
DEBIAN_FRONTEND=noninteractive
29

310
RUN mkdir /apps
411

512
# Set build arguments for cross-compilation
613
ARG TARGETARCH
14+
ARG DUCKDB_VERSION="v1.2.2"
715

816
# Set environment variables
9-
ENV PATH=/venv/bin:$PATH \
10-
PATH=/root/.cargo/bin:$PATH \
11-
PATH="/root/.local/bin/:$PATH"
17+
ENV PATH=/root/.local/bin:/venv/bin:$PATH
1218

13-
# Install uv, curl, and the PostgreSQL client (`psql`)
14-
RUN apt-get update && apt-get install -y ca-certificates curl postgresql-client unzip
19+
# Install system dependencies
20+
RUN apt-get update && apt-get install -y --no-install-recommends \
21+
postgresql-client gzip curl && \
22+
rm -rf /var/lib/apt/lists/*
1523

16-
# Download UV and MinIO Client (mc) based on architecture
24+
# Install UV (Python package manager)
25+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
26+
27+
# Install MinIO client (architecture-specific)
1728
RUN if [ "$TARGETARCH" = "amd64" ]; then \
18-
curl -LsSf https://astral.sh/uv/install.sh | sh \
19-
&& curl -O https://dl.min.io/client/mc/release/linux-amd64/mc \
20-
&& chmod +x mc \
21-
&& mv mc /usr/local/bin/; \
29+
curl -O https://dl.min.io/client/mc/release/linux-amd64/mc; \
2230
elif [ "$TARGETARCH" = "arm64" ]; then \
23-
curl -LsSf https://astral.sh/uv/install.sh | sh \
24-
&& curl -O https://dl.min.io/client/mc/release/linux-arm64/mc \
25-
&& chmod +x mc \
26-
&& mv mc /usr/local/bin/; \
31+
curl -O https://dl.min.io/client/mc/release/linux-arm64/mc; \
2732
else \
2833
echo "Unsupported architecture: $TARGETARCH" && exit 1; \
29-
fi
30-
31-
# Install DuckDB
32-
ARG DUCKDB_VERSION="v1.2.2"
34+
fi && \
35+
chmod +x mc && \
36+
mv mc /usr/local/bin/mc
3337

34-
RUN set -eux; \
35-
apt-get update && apt-get install -y --no-install-recommends \
36-
curl ca-certificates gzip && \
37-
rm -rf /var/lib/apt/lists/* && \
38-
# pick the correct pre‑built binary for the platform
39-
if [ "$TARGETARCH" = "amd64" ]; then \
38+
# Install DuckDB CLI (architecture-specific)
39+
RUN if [ "$TARGETARCH" = "amd64" ]; then \
4040
DUCKDB_DIST="linux-amd64"; \
4141
elif [ "$TARGETARCH" = "arm64" ]; then \
4242
DUCKDB_DIST="linux-arm64"; \
4343
else \
4444
echo "Unsupported architecture: $TARGETARCH" && exit 1; \
4545
fi && \
4646
curl -fsSL "https://github.com/duckdb/duckdb/releases/download/${DUCKDB_VERSION}/duckdb_cli-${DUCKDB_DIST}.gz" \
47-
| gunzip -c > /usr/local/bin/duckdb && \
47+
| gunzip -c > /usr/local/bin/duckdb && \
4848
chmod +x /usr/local/bin/duckdb && \
49-
duckdb --version # quick sanity check
49+
duckdb --version
5050

51-
# Set up a virtual env to use for whatever app is destined for this container.
51+
# Create Python virtual environment
5252
RUN uv venv --python 3.12.6 /venv && \
53-
echo "\nsource /venv/bin/activate\n" >> /root/.zshrc && \
54-
uv --version
55-
56-
# Copy application-specific files
57-
COPY requirements.txt /apps/requirements.txt
53+
/venv/bin/python --version
5854

5955
# Run install of requirements
60-
RUN . /venv/bin/activate && \
61-
uv pip install --upgrade -r /apps/requirements.txt && \
62-
uv pip install --upgrade granian[pname]
63-
64-
RUN echo "We're good:" && \
65-
/venv/bin/python --version
56+
COPY requirements.txt /apps/requirements.txt
57+
RUN uv pip install --upgrade -r /apps/requirements.txt
6658

67-
CMD ["tail", "-f", "/dev/null"]
59+
# Keep container running for interactive use
60+
CMD ["tail", "-f", "/dev/null"]

0 commit comments

Comments
 (0)