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

docs: Add docker example #846

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 0 additions & 41 deletions examples/docker-build/Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions examples/docker-build/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions examples/docker-build/pixi.lock

This file was deleted.

13 changes: 0 additions & 13 deletions examples/docker-build/pixi.toml

This file was deleted.

1 change: 1 addition & 0 deletions examples/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.pixi/
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# pixi environments
.pixi

__pycache__/
*.pyc
17 changes: 17 additions & 0 deletions examples/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ghcr.io/prefix-dev/pixi:0.14.0 AS build

COPY . /app
WORKDIR /app
RUN pixi run build-wheel
RUN pixi run postinstall-production
RUN pixi shell-hook -e prod > /shell-hook
RUN echo "gunicorn -w 4 docker_project:app --bind :8000" >> /shell-hook

FROM ubuntu:22.04 AS production

# only copy the production environment into prod container
COPY --from=build /app/.pixi/envs/prod /app/.pixi/envs/prod
COPY --from=build /shell-hook /shell-hook
WORKDIR /app
EXPOSE 8000
CMD ["/bin/bash", "/shell-hook"]
16 changes: 16 additions & 0 deletions examples/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# docker

This example is using docker in combination with [solve-groups](https://pixi.sh/latest/configuration/#the-environments-table).
The solve-groups ensure that the `default` environment (where the tests are run) is using *exactly* the same versions of the dependencies as the `prod` environment.

In the docker container, we only copy the `prod` environment into the final layer, so the `default` environment and all its dependencies are not included in the final image.
Also, `pixi` itself is not included in the final image and we activate the environment using `pixi -e prod shell-hook`.
pavelzw marked this conversation as resolved.
Show resolved Hide resolved

## Usage
To build and run the docker container you require [`docker`](https://docs.docker.com/engine/install/)
When you have `docker` use the following commands:

```shell
docker build -t pixi-docker .
docker run -p 8000:8000 pixi-docker
```
8 changes: 8 additions & 0 deletions examples/docker/docker_project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask

app = Flask(__name__)


@app.route("/")
def hello():
return "Hello, Pixi server!"
Loading
Loading