diff --git a/.github/actions/build-docker-image/action.yml b/.github/actions/build-docker-image/action.yml new file mode 100644 index 000000000..0e640be89 --- /dev/null +++ b/.github/actions/build-docker-image/action.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index b824a6ff2..000000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,88 +0,0 @@ -# From https://docs.github.com/en/actions/publishing-packages/publishing-docker-images -name: Build Docker images - -on: - workflow_call: - inputs: - version: - required: true - type: string - -jobs: - matrixed-docker-build-test-publish: - runs-on: ubuntu-latest - strategy: - matrix: - base-docker-image: ["python:3.11-slim"] - snap-atac-flavor: ["default", "recommend-interactive"] - 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.version }}-${{ matrix.snap-atac-flavor }}-${PY_VER_ABBRV}" >> $GITHUB_ENV - # Check environment variables were set properly - - name: Check ENV variables - run: | - echo "SNAP_ATAC_VERSION: ${{ inputs.version }}" - echo "PY_VER_ABBRV: ${{ env.PY_VER_ABBRV }}" - echo "IMAGE_TAG: ${{ env.IMAGE_TAG }}" - # https://github.com/actions/checkout - - name: Checkout repository - uses: actions/checkout@v4 - with: - lfs: true - # https://github.com/docker/setup-buildx-action - - 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/${{ matrix.snap-atac-flavor }} - platforms: linux/amd64 - build-args: | - BASE_PYTHON_IMAGE=${{ matrix.base-docker-image }} - SNAP_ATAC_VERSION=${{ inputs.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" - # https://github.com/docker/login-action - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.dockerhub_username }} - password: ${{ secrets.dockerhub_token }} - # https://github.com/docker/build-push-action - # Uses cached result from first build - - name: Push to Docker Hub - uses: docker/build-push-action@v5 - with: - context: docker/${{ matrix.snap-atac-flavor }} - platforms: linux/amd64 - build-args: | - BASE_PYTHON_IMAGE=${{ matrix.base-docker-image }} - SNAP_ATAC_VERSION=${{ inputs.version }} - push: true - tags: snapatac2:${{ env.IMAGE_TAG }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml index 0398dadf4..717d4687e 100644 --- a/.github/workflows/test_python.yml +++ b/.github/workflows/test_python.yml @@ -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 @@ -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 @@ -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 }} \ No newline at end of file + snapatac2-version: ${{ needs.build-and-test.outputs.VERSION }} + python-version: 3.11 + username: ${{ secrets.dockerhub_username }} + password: ${{ secrets.dockerhub_token }} +