-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,768 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.pixi/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# GitHub syntax highlighting | ||
pixi.lock linguist-language=YAML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# pixi environments | ||
.pixi | ||
|
||
__pycache__/ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM ghcr.io/prefix-dev/pixi:0.18.0 AS build | ||
|
||
# copy source code, pixi.toml and pixi.lock to the container | ||
COPY . /app | ||
WORKDIR /app | ||
|
||
# run some compilation / build task (if needed) | ||
RUN pixi run build-wheel | ||
RUN pixi run postinstall-production | ||
|
||
# Create the shell-hook bash script to activate the environment | ||
RUN pixi shell-hook -e prod > /shell-hook.sh | ||
|
||
# extend the shell-hook script to run the command passed to the container | ||
RUN echo 'exec "$@"' >> /shell-hook.sh | ||
|
||
FROM ubuntu:22.04 AS production | ||
|
||
# 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/prod /app/.pixi/envs/prod | ||
COPY --from=build /shell-hook.sh /shell-hook.sh | ||
WORKDIR /app | ||
EXPOSE 8000 | ||
|
||
# set the entrypoint to the shell-hook script (activate the environment and run the command) | ||
# no more pixi needed in the prod container | ||
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"] | ||
|
||
CMD ["gunicorn", "-w", "4", "docker_project:app", "--bind", ":8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Docker example | ||
|
||
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`. | ||
|
||
## 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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
Oops, something went wrong.