Skip to content

Commit

Permalink
fix docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhang committed Apr 1, 2024
1 parent 1dcb583 commit 17537d6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 96 deletions.
85 changes: 85 additions & 0 deletions .github/actions/build-docker-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: 'Build Docker images'
description: 'Build Docker images'

inputs:
snapatac2-version:
description: 'SnapATAC2 version to be installed'
required: true
type: string
python-version:
required: false
default: "3.11"
flavor:
required: false
default: "default"
username:
required: true
password:
required: true

runs:
using: "composite"
steps:
# Should result in something like: `IMAGE_TAG=2.5.1-default-py3.11` or `IMAGE_TAG=2.5.1-recommend-interactive-py3.11`
- name: Create Docker image tag
run: echo "IMAGE_TAG=${{ inputs.snapatac2-version }}-${{ inputs.flavor }}-py${{ inputs.python-version }}" >> $GITHUB_ENV
shell: bash

- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true

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

# TODO: Has SnapATAC2 been tested for arm64? If it has and it works then uncomment the following
# section and also add `linux/arm64` to `platforms` in subsequent steps:
# # https://github.com/docker/setup-qemu-action
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# https://github.com/docker/build-push-action
# Uses github actions cache: https://docs.docker.com/build/cache/backends/gha/
- name: Build Dockerfile
uses: docker/build-push-action@v5
with:
context: docker/${{ inputs.flavor }}
platforms: linux/amd64
build-args: |
BASE_PYTHON_IMAGE=python:${{ inputs.python-version }}-slim
SNAP_ATAC_VERSION=${{ inputs.snapatac2-version }}
load: true
tags: snapatac2:TEST-${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Mount the Github Workspace (repository root) into our test container
# Then install test required packages and run SnapATAC2 Python tests
- name: Test Docker Image
shell: bash
run: |
docker run --rm -t \
--entrypoint /bin/bash \
--volume "${{ github.workspace }}":"/github/workspace" \
snapatac2:TEST-${{ env.IMAGE_TAG }} \
-c "python3 -m pip install pytest hypothesis && pytest /github/workspace/snapatac2-python/tests"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ inputs.username }}
password: ${{ inputs.password }}

# Uses cached result from first build
- name: Push to Docker Hub
uses: docker/build-push-action@v5
with:
context: docker/${{ inputs.flavor }}
platforms: linux/amd64
build-args: |
BASE_PYTHON_IMAGE=python:${{ inputs.python-version }}-slim
SNAP_ATAC_VERSION=${{ inputs.snapatac2-version }}
push: true
tags: snapatac2:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
88 changes: 0 additions & 88 deletions .github/workflows/docker.yml

This file was deleted.

21 changes: 13 additions & 8 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on: [push, pull_request]

jobs:
build-and-test:
runs-on: ubuntu-latest
outputs:
VERSION_NUMBER: ${{ steps.get-version.outputs.VERSION_NUMBER }}
VERSION: ${{ steps.get-version.outputs.VERSION }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: nschloe/action-cached-lfs-checkout@v1
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
run: |
VERSION_NUMBER=$(python -c "import snapatac2;print(snapatac2.__version__)")
echo $VERSION_NUMBER
echo "VERSION=$VERSION_NUMBER" >> $GITHUB_ENV
echo "VERSION=$VERSION_NUMBER" >> $GITHUB_OUTPUT
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
Expand All @@ -53,13 +53,18 @@ jobs:
path: ./wheel_files/snapatac2*.whl

build-wheel:
if: ${{ startsWith(github.ref, 'refs/tags/') || contains(github.event.head_commit.message, 'wheel') }}
if: ${{ startsWith(github.ref, 'refs/tags/') || contains(github.event.head_commit.message, '[wheel]') }}
uses: kaizhang/SnapATAC2/.github/workflows/wheels.yml@main
with:
wheel: 'true'

test_docker:
needs: build-and-test
uses: kaizhang/SnapATAC2/.github/workflows/docker.yml@main
build-docker:
needs: [build-and-test, build-wheel]
if: ${{ startsWith(github.ref, 'refs/tags/') || contains(github.event.head_commit.message, '[docker]') }}
uses: ./.github/actions/build-docker-image
with:
version: ${{ needs.build-and-test.outputs.VERSION_NUMBER }}
snapatac2-version: ${{ needs.build-and-test.outputs.VERSION }}
python-version: 3.11
username: ${{ secrets.dockerhub_username }}
password: ${{ secrets.dockerhub_token }}

0 comments on commit 17537d6

Please sign in to comment.