From 06d68e4b94cdfbdaf3986860b32cfd65ebd98ec2 Mon Sep 17 00:00:00 2001 From: John Bradley Date: Tue, 20 Aug 2024 10:10:04 -0400 Subject: [PATCH 1/2] Adds Dockerfile to build a container Command to build the container for pybioclip: ``` docker build --platform=linux/amd64 --build-arg="PYBIOCLIP_VERSION=1.0.0" -t pybioclip . ``` Adds GitHub action config to build the docker container and apptainer container on release. --- .github/workflows/deploy-image.yml | 58 ++++++++++++++++++++++++++++++ Dockerfile | 7 ++++ 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/deploy-image.yml create mode 100644 Dockerfile diff --git a/.github/workflows/deploy-image.yml b/.github/workflows/deploy-image.yml new file mode 100644 index 0000000..098602e --- /dev/null +++ b/.github/workflows/deploy-image.yml @@ -0,0 +1,58 @@ +name: Create and publish a Docker image + +on: + release: + types: [published] +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + # Step below from https://github.com/orgs/community/discussions/25678#discussioncomment-5242449 + - name: Delete unnecessary tools folder to avoid running out of space + run: rm -rf /opt/hostedtoolcache + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{major}}.{{minor}}.{{patch}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - 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 }} + build-args: "PYBIOCLIP_VERSION=${{ steps.meta.outputs.version }}" + - uses: eWaterCycle/setup-apptainer@v2 + with: + apptainer-version: 1.3.3 + - name: print stuff + run: echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" + - name: pull an apptainer container + run: apptainer pull apptainer.sif docker://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} + - name: push the apptainer container + run: apptainer push apptainer.sif oras://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..892a764 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM condaforge/miniforge3:24.3.0-0 + +ARG PYBIOCLIP_VERSION + +# Install pybioclip from the release archive because pypi can take a while to start working. +RUN pip install "https://github.com/Imageomics/pybioclip/archive/refs/tags/${PYBIOCLIP_VERSION}.tar.gz" && \ + pip cache purge From 7e7ada106ce6c5f23002a6aa795d38c0d4f48e90 Mon Sep 17 00:00:00 2001 From: John Bradley Date: Tue, 27 Aug 2024 15:02:29 -0400 Subject: [PATCH 2/2] Fix sif container name --- .github/workflows/deploy-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-image.yml b/.github/workflows/deploy-image.yml index 098602e..51b2d81 100644 --- a/.github/workflows/deploy-image.yml +++ b/.github/workflows/deploy-image.yml @@ -55,4 +55,4 @@ jobs: - name: pull an apptainer container run: apptainer pull apptainer.sif docker://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} - name: push the apptainer container - run: apptainer push apptainer.sif oras://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} + run: apptainer push apptainer.sif oras://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-sif:${{ steps.meta.outputs.version }}