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 0537207
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 97 deletions.
86 changes: 86 additions & 0 deletions .github/actions/build-docker-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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: "python:3.11-slim"

flavor:
required: false
default: "default"

runs:
using: "composite"
steps:
# This makes some assumptions about `base-docker-image` name format so be sure to test this out if
# things change. For `python:3.11-slim` this should result in `PY_VER_ABBRV=py3.11` beings saved to $GITHUB_ENV
# See: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Get python version shorthand
run: echo "PY_VER_ABBRV=py$(echo ${{ matrix.base-docker-image }} | cut -d ":" -f 2 | cut -d "-" -f 1)" >> $GITHUB_ENV
# 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 }}-${{ inputs.python-version }}" >> $GITHUB_ENV

- 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
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: ${{ secrets.dockerhub_username }}
password: ${{ secrets.dockerhub_token }}

# 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.

17 changes: 8 additions & 9 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on: [push, pull_request]
jobs:
build-and-test:
runs-on: ubuntu-latest
outputs:
VERSION_NUMBER: ${{ steps.get-version.outputs.VERSION_NUMBER }}
steps:
- name: Checkout code
uses: nschloe/action-cached-lfs-checkout@v1
Expand Down Expand Up @@ -43,6 +41,12 @@ jobs:
echo $VERSION_NUMBER
echo "VERSION=$VERSION_NUMBER" >> $GITHUB_ENV
- name: Build docker image
uses: ./.github/actions/build-docker-image
with:
snapatac2-version: ${{ steps.get-version.outputs.VERSION_NUMBER }}
python-version: 3.11

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3

Expand All @@ -52,14 +56,9 @@ jobs:
name: wheel-files
path: ./wheel_files/snapatac2*.whl


build-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
with:
version: ${{ needs.build-and-test.outputs.VERSION_NUMBER }}
wheel: 'true'

0 comments on commit 0537207

Please sign in to comment.