-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improved dockerfile * added info on building architecture dockerfile * added workflow for docker * modify run conditions for docker workflow * add push event to run workflow at least once * fix * test docker workflow * fix docker build action * explicit docker tag based on spatialdata-xx versions * fix Dockerfile * fix typo dockerfile * checking for existing docker tags * fix workflow * typo * fix problem image tag check * fix * removed on push docker workflow trigger * update docs on docker and conda * small rewrite
- Loading branch information
1 parent
69040ae
commit f927685
Showing
3 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
name: Build Docker image | ||
|
||
on: | ||
workflow_dispatch: | ||
# schedule: | ||
# - cron: '0 0 * * *' # run daily at midnight UTC | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
shell: bash -e {0} # -e to fail on error | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.x" | ||
|
||
- name: Upgrade pip | ||
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: Check if image tag exists | ||
id: check_tag | ||
env: | ||
IMAGE_TAG_SUFFIX: spatialdata${{ env.SPATIALDATA_VERSION }}_spatialdata-io${{ env.SPATIALDATA_IO_VERSION }}_spatialdata-plot${{ env.SPATIALDATA_PLOT_VERSION }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Define the API URL | ||
API_URL="https://api.github.com/orgs/scverse/packages/container/spatialdata/versions" | ||
# Fetch all existing versions | ||
existing_tags=$(curl -s -H "Authorization: token $GITHUB_TOKEN" $API_URL | jq -r '.[].metadata.container.tags[]') | ||
# Debug: Output all existing tags | ||
echo "Existing tags:" | ||
echo "$existing_tags" | ||
# Check if the constructed tag exists | ||
if echo "$existing_tags" | grep -q "$IMAGE_TAG_SUFFIX"; then | ||
echo "Image tag $IMAGE_TAG_SUFFIX already exists. Skipping build." | ||
echo "skip_build=true" >> $GITHUB_ENV | ||
else | ||
echo "Image tag $IMAGE_TAG_SUFFIX does not exist. Proceeding with build." | ||
echo "skip_build=false" >> $GITHUB_ENV | ||
echo "IMAGE_TAG_SUFFIX=${IMAGE_TAG_SUFFIX}" >> $GITHUB_ENV | ||
fi | ||
- name: Login to GitHub Container Registry | ||
if: ${{ env.skip_build == 'false' }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: docker/build-push-action@v5 | ||
if: ${{ env.skip_build == 'false' }} | ||
env: | ||
IMAGE_TAG: ${{ env.REGISTRY }}/scverse/spatialdata:${{ env.IMAGE_TAG_SUFFIX }} | ||
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 | ||
build-args: | | ||
SPATIALDATA_VERSION=${{ env.SPATIALDATA_VERSION }} | ||
SPATIALDATA_IO_VERSION=${{ env.SPATIALDATA_IO_VERSION }} | ||
SPATIALDATA_PLOT_VERSION=${{ env.SPATIALDATA_PLOT_VERSION }} | ||
tags: ${{ env.IMAGE_TAG }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,51 @@ | ||
FROM condaforge/mambaforge | ||
ARG TARGETPLATFORM=linux/amd64 | ||
|
||
RUN mamba install python=3.10 | ||
# 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), | ||
# use the following command on the command line: | ||
# | ||
# docker build --build-arg TARGETPLATFORM=linux/arm64 -t my-arm-image . | ||
# | ||
# Similarly, to build for the default x86_64 architecture, you can use: | ||
# | ||
# docker build --build-arg TARGETPLATFORM=linux/amd64 -t my-amd64-image . | ||
# | ||
FROM --platform=$TARGETPLATFORM ubuntu:latest | ||
LABEL authors="Luca Marconato" | ||
|
||
# complex dependencies that needs to be solved with conda | ||
RUN mamba install -c conda-forge gcc libgdal gxx imagecodecs -y | ||
ENV PYTHONUNBUFFERED=1 | ||
|
||
# satellite spatialdata projects | ||
ARG SPATIALDATA_VERSION | ||
ARG SPATIALDATA_IO_VERSION | ||
ARG SPATIALDATA_PLOT_VERSION | ||
|
||
# debugging | ||
RUN echo "Target Platform: ${TARGETPLATFORM}" && \ | ||
echo "spatialdata version: ${SPATIALDATA_VERSION}" && \ | ||
echo "spatialdata-io version: ${SPATIALDATA_IO_VERSION}" && \ | ||
echo "spatialdata-plot version: ${SPATIALDATA_PLOT_VERSION}" | ||
|
||
# Update and install system dependencies. | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
python3-venv \ | ||
python3-dev \ | ||
git \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# setup python virtual environment | ||
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 \ | ||
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters