Skip to content

Commit

Permalink
explicit docker tag based on spatialdata-xx versions
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaMarconato committed Jan 22, 2025
1 parent 0ed3822 commit da9ed65
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
36 changes: 22 additions & 14 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Build Docker image
# adapted from https://github.com/scverse/scvi-tools/blob/main/.github/workflows/build_image_latest.yaml

on:
workflow_run:
Expand Down Expand Up @@ -36,7 +35,23 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- uses: docker/setup-buildx-action@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install pip-tools
run: pip install pip

- name: Get latest versions
id: get_versions
run: |
SPATIALDATA_VERSION=$(pip index versions spatialdata | grep "Available versions" | sed 's/Available versions: //' | awk -F', ' '{print $1}')
SPATIALDATA_IO_VERSION=$(pip index versions spatialdata-io | grep "Available versions" | sed 's/Available versions: //' | awk -F', ' '{print $1}')
SPATIALDATA_PLOT_VERSION=$(pip index versions spatialdata-plot | grep "Available versions" | sed 's/Available versions: //' | awk -F', ' '{print $1}')
echo "SPATIALDATA_VERSION=${SPATIALDATA_VERSION}" >> $GITHUB_ENV
echo "SPATIALDATA_IO_VERSION=${SPATIALDATA_IO_VERSION}" >> $GITHUB_ENV
echo "SPATIALDATA_PLOT_VERSION=${SPATIALDATA_PLOT_VERSION}" >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -45,22 +60,15 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set build inputs
id: build
run: |
INPUT_REF=${{ github.ref_name }}
if [[ $INPUT_REF == "main" ]]; then
VERSION="latest"
else
VERSION=${INPUT_REF}
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
cache-from: type=registry,ref=${{ env.REGISTRY }}/scverse/spatialdata:buildcache
cache-to: type=inline,ref=${{ env.REGISTRY }}/scverse/spatialdata:buildcache
tags: ${{ env.REGISTRY }}/scverse/spatialdata:${{ steps.build.outputs.version }}
build-args: |
SPATIALDATA_VERSION=${{ env.SPATIALDATA_VERSION }}
SPATIALDATA_IO_VERSION=${{ env.SPATIALDATA_IO_VERSION }}
SPATIALDATA_PLOT_VERSION=${{ env.SPATIALDATA_PLOT_VERSION }}
tags: ${{ env.REGISTRY }}/scverse/spatialdata:spatialdata${{ env.SPATIALDATA_VERSION }}_spatialdata-io${{ env.SPATIALDATA_IO_VERSION }}_spatialdata-plot${{ env.SPATIALDATA_PLOT_VERSION }}
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ARG TARGETPLATFORM=linux/amd64

ARG SPATIALDATA_VERSION
ARG SPATIALDATA_IO_VERSION
ARG SPATIALDATA_PLOT_VERSION

# Use the specified platform to pull the correct base image.
# Override TARGETPLATFORM during build for different architectures, such as linux/arm64 for Apple Silicon.
# For example, to build for ARM64 architecture (e.g., Apple Silicon),
Expand Down Expand Up @@ -28,7 +32,13 @@ RUN apt-get update && \
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --upgrade pip wheel

# Install the libraries with specific versions
RUN pip install --no-cache-dir \
spatialdata[torch] \
spatialdata-io \
spatialdata-plot
spatialdata[torch]==${SPATIALDATA_VERSION} \
spatialdata-io==${SPATIALDATA_IO_VERSION} \
spatialdata-plot==${SPATIALDATA_PLOT_VERSION}

LABEL spatialdata_version="${SPATIALDATA_VERSION}" \
spatialdata_io_version="${SPATIALDATA_IO_VERSION}" \
spatialdata_plot_version="${SPATIALDATA_PLOT_VERSION}"

0 comments on commit da9ed65

Please sign in to comment.