Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI/CD - Build and Push Docker Image to GHCR

on:
push:
branches: [ "main" ]
tags:
- '*' # Matches any tag name
# Optional: Allows manual triggering of the workflow from the GitHub Actions tab
workflow_dispatch:

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # Grant write permission to the GITHUB_TOKEN for packages

steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule,pattern=nightly
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,format=long

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python package
name: Python tests

on:
push:
Expand Down
70 changes: 15 additions & 55 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,18 @@
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
SHELL ["/bin/bash", "-c"]
FROM python:3.12-slim

# Configure environment
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=/opt/venv \
PATH="/opt/venv/bin:$PATH" \
AWS_RETRY_MODE=adaptive \
AWS_MAX_ATTEMPTS=10 \
DEBIAN_FRONTEND=noninteractive

WORKDIR /software/scallops

# --- DEPENDENCY LAYER ---
COPY pyproject.toml setup.py requirements.txt requirements.cellpose.txt requirements.ufish.txt ./

ARG TF_PKG="tensorflow==2.19.0"

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
set -eux; \
# Install system dependencies
apt-get update && \
apt-get install --no-install-recommends -y \
ENV AWS_RETRY_MODE=adaptive \
AWS_MAX_ATTEMPTS=10
RUN apt-get update -qq && \
apt-get install -qq --no-install-recommends -y \
build-essential \
git \
ca-certificates && \
# Create virtual environment
uv venv /opt/venv && \
# Filter out tensorflow from requirements
grep -vE '^tensorflow(==|>=|<=|~=|!=)' requirements.txt > /tmp/requirements.no-tf.txt && \
# Install Python dependencies
uv pip install --no-cache-dir \
-r /tmp/requirements.no-tf.txt \
-r requirements.cellpose.txt \
-r requirements.ufish.txt \
"${TF_PKG}" && \
# Cleanup
apt-get remove -y build-essential git && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /tmp/* /var/tmp/*

# --- APPLICATION LAYER ---
COPY scallops scallops/

# Install the application itself
RUN --mount=type=bind,source=.git,target=.git \
apt-get update && \
apt-get install --no-install-recommends -y build-essential git && \
# Install app in editable mode into the venv
uv pip install -e . && \
apt-get remove -y build-essential git && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ca-certificates
WORKDIR /app
COPY requirements.txt requirements.ufish.txt ./
RUN pip install -q --no-cache-dir --upgrade pip && pip install -q --no-cache-dir -r requirements.txt
RUN pip install -q --no-cache-dir -r requirements.ufish.txt
COPY . ./
RUN pip install .
RUN apt-get remove -qq -y build-essential git && \
apt-get autoremove -qq -y && apt-get clean -qq && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /app/