Skip to content

Commit 62db131

Browse files
authored
Merge pull request #5 from Genentech/docker
docker ci
2 parents 85acae6 + d17d0b5 commit 62db131

3 files changed

Lines changed: 71 additions & 56 deletions

File tree

.github/workflows/docker.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI/CD - Build and Push Docker Image to GHCR
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
tags:
7+
- '*' # Matches any tag name
8+
# Optional: Allows manual triggering of the workflow from the GitHub Actions tab
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write # Grant write permission to the GITHUB_TOKEN for packages
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v6
21+
22+
- name: Log in to the GitHub Container Registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: ghcr.io/${{ github.repository }}
34+
tags: |
35+
type=schedule,pattern=nightly
36+
type=ref,event=branch
37+
type=ref,event=tag
38+
type=ref,event=pr
39+
type=semver,pattern={{version}}
40+
type=semver,pattern={{major}}.{{minor}}
41+
type=semver,pattern={{major}}
42+
type=sha,format=long
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
push: true
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Python package
1+
name: Python tests
22

33
on:
44
push:

Dockerfile

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,18 @@
1-
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
2-
SHELL ["/bin/bash", "-c"]
1+
FROM python:3.12-slim
32

4-
# Configure environment
5-
ENV UV_COMPILE_BYTECODE=1 \
6-
UV_LINK_MODE=copy \
7-
PYTHONUNBUFFERED=1 \
8-
VIRTUAL_ENV=/opt/venv \
9-
PATH="/opt/venv/bin:$PATH" \
10-
AWS_RETRY_MODE=adaptive \
11-
AWS_MAX_ATTEMPTS=10 \
12-
DEBIAN_FRONTEND=noninteractive
13-
14-
WORKDIR /software/scallops
15-
16-
# --- DEPENDENCY LAYER ---
17-
COPY pyproject.toml setup.py requirements.txt requirements.cellpose.txt requirements.ufish.txt ./
18-
19-
ARG TF_PKG="tensorflow==2.19.0"
20-
21-
RUN --mount=type=cache,target=/root/.cache/uv \
22-
--mount=type=cache,target=/var/cache/apt \
23-
--mount=type=cache,target=/var/lib/apt \
24-
set -eux; \
25-
# Install system dependencies
26-
apt-get update && \
27-
apt-get install --no-install-recommends -y \
3+
ENV AWS_RETRY_MODE=adaptive \
4+
AWS_MAX_ATTEMPTS=10
5+
RUN apt-get update -qq && \
6+
apt-get install -qq --no-install-recommends -y \
287
build-essential \
298
git \
30-
ca-certificates && \
31-
# Create virtual environment
32-
uv venv /opt/venv && \
33-
# Filter out tensorflow from requirements
34-
grep -vE '^tensorflow(==|>=|<=|~=|!=)' requirements.txt > /tmp/requirements.no-tf.txt && \
35-
# Install Python dependencies
36-
uv pip install --no-cache-dir \
37-
-r /tmp/requirements.no-tf.txt \
38-
-r requirements.cellpose.txt \
39-
-r requirements.ufish.txt \
40-
"${TF_PKG}" && \
41-
# Cleanup
42-
apt-get remove -y build-essential git && \
43-
apt-get autoremove -y && \
44-
apt-get clean && \
45-
rm -rf /tmp/* /var/tmp/*
46-
47-
# --- APPLICATION LAYER ---
48-
COPY scallops scallops/
49-
50-
# Install the application itself
51-
RUN --mount=type=bind,source=.git,target=.git \
52-
apt-get update && \
53-
apt-get install --no-install-recommends -y build-essential git && \
54-
# Install app in editable mode into the venv
55-
uv pip install -e . && \
56-
apt-get remove -y build-essential git && \
57-
apt-get autoremove -y && \
58-
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
9+
ca-certificates
10+
WORKDIR /app
11+
COPY requirements.txt requirements.ufish.txt ./
12+
RUN pip install -q --no-cache-dir --upgrade pip && pip install -q --no-cache-dir -r requirements.txt
13+
RUN pip install -q --no-cache-dir -r requirements.ufish.txt
14+
COPY . ./
15+
RUN pip install .
16+
RUN apt-get remove -qq -y build-essential git && \
17+
apt-get autoremove -qq -y && apt-get clean -qq && \
18+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /app/

0 commit comments

Comments
 (0)