From 595ce24dfe64dd5492d24ffa0938dd8d2013a5c1 Mon Sep 17 00:00:00 2001 From: MatDagommer Date: Tue, 30 Dec 2025 22:32:05 +0100 Subject: [PATCH 1/2] =?UTF-8?q?feat(docker)=F0=9F=90=B3:=20Add=20Dockerfil?= =?UTF-8?q?e=20template=20for=20project=20deployment=20using=20pixi=20and?= =?UTF-8?q?=20Ubuntu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduce a multi-stage Dockerfile for building and running the project with pixi-managed environments. - Ensure dependencies are installed and locked using pixi in the build stage. - Set up an entrypoint script to activate the pixi environment and execute container commands. - Copy only the necessary environment and project files into the production image for efficiency. - Expose port 8000 and set default command to run the app with uvicorn. --- .../{{ cookiecutter.__repo_name }}/Dockerfile | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/Dockerfile diff --git a/pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/Dockerfile b/pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/Dockerfile new file mode 100644 index 0000000..02ac950 --- /dev/null +++ b/pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/Dockerfile @@ -0,0 +1,28 @@ +FROM ghcr.io/prefix-dev/pixi:0.41.4 AS build + +# copy source code, pixi.toml and pixi.lock to the container +WORKDIR /app +COPY . . +# install dependencies to `/app/.pixi/envs/api` +# use `--locked` to ensure the lockfile is up to date with pixi.toml +RUN pixi install --locked -e api +# create the shell-hook bash script to activate the environment +RUN pixi shell-hook -e api -s bash > /shell-hook +RUN echo "#!/bin/bash" > /app/entrypoint.sh +RUN cat /shell-hook >> /app/entrypoint.sh +# extend the shell-hook script to run the command passed to the container +RUN echo 'exec "$@"' >> /app/entrypoint.sh + +FROM ubuntu:24.04 AS production +WORKDIR /app +# only copy the production environment into prod container +# please note that the "prefix" (path) needs to stay the same as in the build container +COPY --from=build /app/.pixi/envs/api /app/.pixi/envs/api +COPY --from=build --chmod=0755 /app/entrypoint.sh /app/entrypoint.sh +# copy your project code into the container as well +COPY ./{{ cookiecutter.__package_name }} /app/{{ cookiecutter.__package_name }} + +EXPOSE 8000 +ENTRYPOINT [ "/app/entrypoint.sh" ] +# run your app inside the pixi environment +CMD [ "uvicorn", "{{ cookiecutter.__package_name }}.scripts.app:app", "--host", "0.0.0.0" ] From f60600eb0c7c3c0bfacaddaa3950f3fd2e967842 Mon Sep 17 00:00:00 2001 From: MatDagommer Date: Tue, 30 Dec 2025 22:33:32 +0100 Subject: [PATCH 2/2] =?UTF-8?q?feat(template)=E2=9C=A8:=20add=20'api'=20op?= =?UTF-8?q?tional=20dependency=20group=20to=20pyproject.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduces a new 'api' group in the optional dependencies with the 'api' feature. - Allows users to install API-related dependencies via the 'api' group. --- .../project/{{ cookiecutter.__repo_name }}/pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/pyproject.toml b/pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/pyproject.toml index 5adb6a1..33863fa 100644 --- a/pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/pyproject.toml +++ b/pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/pyproject.toml @@ -162,3 +162,4 @@ default = { features = ["tests", "devtools", "notebook", "setup"] } docs = { features = ["docs"] } tests = { features = ["tests", "setup"] } cuda = { features = ["tests", "devtools", "notebook", "setup", "cuda"] } +api = { features = ["api"] }