From c408250b50ea0f31e06945adb82b8848b1facd61 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 10 May 2024 10:29:15 -0600 Subject: [PATCH] Create a dockerfile for running the model code locally or in azure (#107) * Adding image-build * Adding docker file * Dockerfile builds pyrenew correctly * Adding action to build image * Adding triggers for the container image * Pushing to the ghcr * Update container-image.yml * Tagging and adding read access [skip ci] * Adding login action via redhat-actions [skip ci] * Hardcoding image_registry [skip ci] * Direct login without the action [skip ci] * Direct login without the action [skip ci] 3 * Cleaning up before undrafting PR * Correcting the instructions to install pyrenew * Wrong address to image --- .github/workflows/container_image.yml | 35 +++++++++++++++++++++ model/Dockerfile | 32 +++++++++++++++++++ model/Makefile | 45 ++++++++++++++++++++++++++- model/README.md | 10 +++++- 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/container_image.yml create mode 100644 model/Dockerfile diff --git a/.github/workflows/container_image.yml b/.github/workflows/container_image.yml new file mode 100644 index 00000000..3003c910 --- /dev/null +++ b/.github/workflows/container_image.yml @@ -0,0 +1,35 @@ +name: Build container image + +on: + workflow_dispatch: + release: + types: [published] + +permissions: + packages: write + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Installs podman + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends podman + + - name: Log in to ghcr.io + run: | + podman login \ + -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} \ + ghcr.io/cdcgov + + - name: Build container image + run: | + make image-build + podman tag pyrenew:latest ghcr.io/cdcgov/pyrenew:latest + podman push ghcr.io/cdcgov/pyrenew:latest + working-directory: model diff --git a/model/Dockerfile b/model/Dockerfile new file mode 100644 index 00000000..827c061f --- /dev/null +++ b/model/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:24.04 + +LABEL org.opencontainers.image.description="Image of PyRenew python package" +LABEL org.opencontainers.image.source="https://github.com/CDCgov/multisignal-epi-inference" +LABEL org.opencontainers.image.authors="CDC's Center for Forecasting Analytics" +LABEL org.opencontainers.image.license="Apache-2.0" + +# Installing python3-11.0 +RUN apt-get update && apt install -y python3.12 + +# Adding the alias python3 for python3.12 +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 + +# Installing poetry +RUN apt install -y pipx && \ + pipx install poetry + +RUN echo "export PATH=$PATH:/root/.local/bin" >> ~/.bashrc + +ENV PATH="${PATH}:/root/.local/bin" + +# Copying the project files +COPY src/ poetry.lock pyproject.toml Makefile LICENSE README.md /pyrenew/ + +# Setting the working directory +WORKDIR /pyrenew + +# Installing the dependencies +RUN poetry install + +CMD ["bash"] diff --git a/model/Makefile b/model/Makefile index 89dd88b6..c80166ab 100644 --- a/model/Makefile +++ b/model/Makefile @@ -1,3 +1,24 @@ +CONTAINER=podman +# Pass as environment variables +# CONTAINER_REGISTRY= +# CONTAINER_URL= + + +# Help target listing the available targets +help: + @echo "Available targets" + @echo "=================" + @echo " help : Show this help message" + @echo " install : Install the project dependencies" + @echo " test : Run the tests" + @echo " docs : Render the documentation" + @echo " clean : Clean the generated files" + @echo " docs/notebooks : Convert the Quarto files to Jupyter notebooks" + @echo " test_images : Generate reference images for tests" + @echo " image-build : Build the podman/Docker image" + @echo " image-run : Run the podman/Docker image" + @echo " image-push : Push the podman/Docker image to the registry" + install: poetry install @@ -39,4 +60,26 @@ clean: rm -f docs/example-with-datasets.$$i; \ done -.PHONY: install test docs clean docs/notebooks docs/py test_images +image-build: Dockerfile + $(CONTAINER) build -t pyrenew:latest . + +image-run: + $(CONTAINER) run -it --rm -v $(PWD):/mnt pyrenew:latest + +image-az-login: + if [ -z $(CONTAINER_REGISTRY) ]; then \ + echo "Please set the CONTAINER_REGISTRY environment variable"; \ + exit 1; \ + fi + az login + az acr login --name $(CONTAINER_REGISTRY) + +image-push: + if [ -z $(CONTAINER_URL) ]; then \ + echo "Please set the CONTAINER_URL environment variable"; \ + exit 1; \ + fi + $(CONTAINER) push pyrenew:latest $(CONTAINER_URL)/pyrenew:latest + +.PHONY: install test docs clean docs/notebooks docs/py test_images image-build \ + image-run diff --git a/model/README.md b/model/README.md index d1f1e698..a5013c14 100755 --- a/model/README.md +++ b/model/README.md @@ -7,7 +7,15 @@ Install via pip with ```bash -pip install git+https://github.com/cdcent/cfa-pyrenew.git +pip install git+https://github.com/CDCgov/multisignal-epi-inference@main#subdirectory=model +``` + +## Container image + +A container image is available at `ghcr.io/CDCgov/pyrenew:latest`. You can pull it with + +```bash +docker pull ghcr.io/CDCgov/pyrenew:latest ``` ## Demo