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

Misc/docker example #353

Merged
merged 6 commits into from
Sep 27, 2023
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
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/target
.idea
.vscode
.test-projects
__pycache__
**/**/.pixi
**/**/.build
.DS_store
2 changes: 2 additions & 0 deletions examples/docker-build/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML
2 changes: 2 additions & 0 deletions examples/docker-build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pixi environments
.pixi
38 changes: 38 additions & 0 deletions examples/docker-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM ubuntu:latest

# Install curl and tar for installing pixi binary
RUN apt-get update && \
apt-get install -y curl tar

# Environment variables
ENV PIXI_VERSION=latest
ENV INSTALL_DIR=/usr/local/bin
ENV REPO=prefix-dev/pixi
ENV PLATFORM=unknown-linux-musl
ENV PROJECT_NAME=pixi-in-docker

# Download and install pixi
RUN if [ "$PIXI_VERSION" = "latest" ]; then \
DOWNLOAD_URL="https://github.com/$REPO/releases/latest/download/pixi-$(uname -m)-$PLATFORM.tar.gz"; \
else \
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$PIXI_VERSION/pixi-$(uname -m)-$PLATFORM.tar.gz"; \
fi && \
curl -SL "$DOWNLOAD_URL" | tar -xz -C "$INSTALL_DIR"

# Make a project dir and make it the workdir for the docker image.
RUN mkdir -p /root/$PROJECT_NAME
WORKDIR /root/$PROJECT_NAME

# Copy the project file and lockfile to only reinstall environment if those are changed.
COPY ../../pixi.lock ../../pixi.toml ./

# Install the environment
# The mount is a docker specific cache location so the firstime it will be slow but the second time the cache will be reused.
# More info in their docs: https://docs.docker.com/build/guide/mounts/
RUN --mount=type=cache,target=/root/.cache/rattler pixi install

# Copy the rest of the project
COPY ../../. ./

# Build pixi a custom pixi version in a docker container by running pixi the latest pixi ;)
RUN pixi run build
21 changes: 21 additions & 0 deletions examples/docker-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build a docker image using pixi
This project shows how to build a docker image with pixi installed into it.

To show the strength of pixi in docker, we're going to use an installed pixi to build pixi in a docker image.
Steps of the docker build:
- Install the latest `pixi` from our prebuild binaries.
- Use `pixi` to install the build dependencies for the source project of `pixi`.
- Use `pixi` to run the cargo build of the source `pixi`.

NOTE: Please [install docker](https://docs.docker.com/engine/install/) manually as it is not available through conda.
To start the `docker build` use pixi:
```shell
pixi run start
```

To optimize build time of the docker image, we use a cache for the pixi environment.
The mount is a docker specific cache location, so the first it will be slow but the second time the cache will be reused.
More info in their docs: https://docs.docker.com/build/guide/mounts/
```dockerfile
RUN --mount=type=cache,target=/root/.cache/rattler pixi install
```
15 changes: 15 additions & 0 deletions examples/docker-build/pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions examples/docker-build/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "docker-build"
version = "0.1.0"
description = "Add a short description here"
authors = ["Ruben Arts <[email protected]>"]
channels = ["conda-forge"]
platforms = ["linux-64"]

[tasks]
test_docker_install = "docker -v || (echo No docker found, please install manually as it is not available on conda. && exit)"
build = {cmd = "docker build ../../. --no-cache -f Dockerfile --tag pixi", depends_on = ["test_docker_install"]}
start = {cmd = "docker run -it pixi", depends_on = ["build"]}
[dependencies]
Loading