Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(docker): add Dockerfile and container image build tests #362

Merged
merged 6 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,52 @@ jobs:
path: dist/*.tar.gz
if-no-files-found: error
retention-days: 90
docker-image-test:
runs-on: ubuntu-latest
# set a dependency sequence to occur after build job completion
needs: build
steps:
d33bs marked this conversation as resolved.
Show resolved Hide resolved
# checks out selected files for docker image build testing
- name: Checkout selected files
uses: actions/checkout@v4
with:
sparse-checkout: |
build/docker/Dockerfile
tests
sparse-checkout-cone-mode: false
- name: Download sdist artifact
uses: actions/download-artifact@v4
with:
name: sdist
# gather the sdist tar.gz name (which varies)
- name: Get sdist tar.gz
id: get_sdist_tar_gz
run: |
echo "filename=$(ls ./*.tar.gz)" >> "$GITHUB_OUTPUT"
d33bs marked this conversation as resolved.
Show resolved Hide resolved
# unzips the sdist
- name: Extract sdist
run: |
tar -xzvf "${{ steps.get_sdist_tar_gz.outputs.filename }}"
d33bs marked this conversation as resolved.
Show resolved Hide resolved
# note: roughly follows Docker documentation on GitHub Actions usage
# found on the following https://github.com/docker/build-push-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# attempts to build a test image for observing test behavior
# and modeling a production image build. Version label
# assumes pwd of, for example: pycytominer-1.0.1.post37.dev0+55690e4,
# where we attempt to use 1.0.1.post37.dev0+55690e4 as a version label.
- name: Build docker image for testing
run: |
cd "$(echo "${{ steps.get_sdist_tar_gz.outputs.filename }}" | sed 's/\.tar\.gz$//')" && \
cp -r ../tests . && \
docker build -f ../build/docker/Dockerfile \
-t pycytominer:testing \
--label version="$(basename "$(pwd)" | sed 's/pycytominer-//')" \
--target testing \
.
# runs pytest for pycytominer within a docker container based on the image above
- name: Run tests through docker image
run: |
docker run pycytominer:testing pytest
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ repos:
rev: v1.6.26
hooks:
- id: actionlint
- repo: https://github.com/hadolint/hadolint
rev: v2.12.1-beta
hooks:
- id: hadolint-docker
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ help:
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# note: presumes the existence of docker daemon to receive docker commands
test_docker_build:
docker build -f build/docker/Dockerfile -t pycytominer:latest . && \
docker run pycytominer:latest poetry run pytest
37 changes: 37 additions & 0 deletions build/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM python:3.11 as base

# set various metadata, loosely following biocontainers standards from:
# https://biocontainers-edu.readthedocs.io/en/latest/what_is_biocontainers.html
LABEL base_image="python:3.11"
LABEL software="pycytominer"
LABEL about.summary="Python package for processing image-based profiling data"
LABEL about.home="https://github.com/cytomining/pycytominer"
LABEL about.documentation="https://pycytominer.readthedocs.io/en/stable/"
LABEL about.license_file="https://github.com/cytomining/pycytominer/blob/main/LICENSE.md"
LABEL about.license="SPDX:BSD-3-Clause"

# set the workdir to /app
WORKDIR /app

# configures poetry to install dependencies without virtualenvs
# see: https://python-poetry.org/docs/configuration/#virtualenvscreate
ENV POETRY_VIRTUALENVS_CREATE=false

# install poetry and poetry dynamic versioning
# hadolint ignore=DL3013
RUN pip install --no-cache-dir poetry

# create stage for production build (no dev or non-essential deps)
FROM base as production

# copy the pycytominer source into image
COPY . .

# install pycytominer using poetry root dependencies and all extras
RUN poetry install --only-root --all-extras -v --no-interaction
d33bs marked this conversation as resolved.
Show resolved Hide resolved

# create stage for production build (no dev or non-essential deps)
FROM production as testing

# install pycytominer from poetry with group deps and all extras for testing
RUN poetry install --with dev --all-extras -v --no-interaction
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ license = "BSD-3-Clause"
readme = "README.md"
homepage = "https://pycytominer.readthedocs.io/"
repository = "https://github.com/cytomining/pycytominer"
include = [{ path = "poetry.lock", format = "sdist" }]

[tool.poetry.dependencies]
python = ">=3.8,<4.0"
Expand Down
Loading