Skip to content

Commit 0bc1476

Browse files
authored
Merge pull request #11 from MatDagommer/dockerfile
feat(docker)🐳: Add Dockerfile template for project deployment using pixi and Ubuntu
2 parents 1005703 + f60600e commit 0bc1476

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM ghcr.io/prefix-dev/pixi:0.41.4 AS build
2+
3+
# copy source code, pixi.toml and pixi.lock to the container
4+
WORKDIR /app
5+
COPY . .
6+
# install dependencies to `/app/.pixi/envs/api`
7+
# use `--locked` to ensure the lockfile is up to date with pixi.toml
8+
RUN pixi install --locked -e api
9+
# create the shell-hook bash script to activate the environment
10+
RUN pixi shell-hook -e api -s bash > /shell-hook
11+
RUN echo "#!/bin/bash" > /app/entrypoint.sh
12+
RUN cat /shell-hook >> /app/entrypoint.sh
13+
# extend the shell-hook script to run the command passed to the container
14+
RUN echo 'exec "$@"' >> /app/entrypoint.sh
15+
16+
FROM ubuntu:24.04 AS production
17+
WORKDIR /app
18+
# only copy the production environment into prod container
19+
# please note that the "prefix" (path) needs to stay the same as in the build container
20+
COPY --from=build /app/.pixi/envs/api /app/.pixi/envs/api
21+
COPY --from=build --chmod=0755 /app/entrypoint.sh /app/entrypoint.sh
22+
# copy your project code into the container as well
23+
COPY ./{{ cookiecutter.__package_name }} /app/{{ cookiecutter.__package_name }}
24+
25+
EXPOSE 8000
26+
ENTRYPOINT [ "/app/entrypoint.sh" ]
27+
# run your app inside the pixi environment
28+
CMD [ "uvicorn", "{{ cookiecutter.__package_name }}.scripts.app:app", "--host", "0.0.0.0" ]

pyml_cli/templates/project/{{ cookiecutter.__repo_name }}/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,4 @@ default = { features = ["tests", "devtools", "notebook", "setup"] }
162162
docs = { features = ["docs"] }
163163
tests = { features = ["tests", "setup"] }
164164
cuda = { features = ["tests", "devtools", "notebook", "setup", "cuda"] }
165+
api = { features = ["api"] }

0 commit comments

Comments
 (0)