Skip to content

Commit

Permalink
Create a dockerfile for running the model code locally or in azure (#107
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
gvegayon authored May 10, 2024
1 parent 55c8468 commit c408250
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/container_image.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions model/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
45 changes: 44 additions & 1 deletion model/Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c408250

Please sign in to comment.