Skip to content

Commit

Permalink
[WIP] Use official instruction from pixi-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
flferretti committed Nov 12, 2024
1 parent acb78c7 commit 52bb311
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
44 changes: 13 additions & 31 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
# syntax=docker/dockerfile:1.4
ARG PROJECT_NAME=jaxsim
ARG PIXI_ENVIRONMENT=test-cpu
FROM mcr.microsoft.com/devcontainers/base:jammy

# Create the pixi environment using the official pixi image.
# We will copy the resulting `.pixi` folder to an official devcontainer image.
FROM ghcr.io/prefix-dev/pixi:latest AS build
ARG PROJECT_NAME
ARG PIXI_ENVIRONMENT
ARG PROJECT_NAME=jaxsim
ARG PIXI_VERSION=v0.35.0

# Add Git LFS package repository and install.
RUN apt-get update &&\
apt-get install -y --no-install-recommends git-lfs &&\
rm -rf /var/lib/apt/lists/*
RUN curl -o /usr/local/bin/pixi -SL https://github.com/prefix-dev/pixi/releases/download/${PIXI_VERSION}/pixi-$(uname -m)-unknown-linux-musl \
&& chmod +x /usr/local/bin/pixi \
&& pixi info

# Create the pixi environment.
COPY . /workspaces/$PROJECT_NAME
RUN cd /workspaces/$PROJECT_NAME &&\
git lfs pull &&\
pixi install --environment $PIXI_ENVIRONMENT &&\
pixi shell-hook --environment $PIXI_ENVIRONMENT >> /shell-hook.sh &&\
echo 'exec "$@"' >> /shell-hook.sh &&\
chmod +x /shell-hook.sh
# Add LFS repository and install.
RUN apt-get update && apt-get install -y curl \
&& curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash \
&& apt install -y git-lfs

# Pixi is no longer needed in the final devcontainer.
# Users can easily download it in their home, if needed.
FROM mcr.microsoft.com/devcontainers/base:ubuntu AS production
ARG PROJECT_NAME
ARG PIXI_ENVIRONMENT
USER vscode
WORKDIR /home/vscode

# Copy the environment created in the build image.
# It will be symlinked to the workspace folder by the entrypoint script.
WORKDIR /workspaces/$PROJECT_NAME
COPY --from=build /workspaces/$PROJECT_NAME/.pixi/envs/$PIXI_ENVIRONMENT /pixi/envs/$PIXI_ENVIRONMENT
COPY --from=build /shell-hook.sh /shell-hook.sh
RUN echo 'eval "$(pixi completion -s bash)"' >> /home/vscode/.bashrc

# Set the shell-hook script as the entrypoint.
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"]
14 changes: 10 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},

// Put `.pixi` folder in a mounted volume of a case-insensitive filesystem.
"mounts": ["source=${localWorkspaceFolderBasename}-pixi,target=${containerWorkspaceFolder}/.pixi,type=volume"],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "ln -s /pixi /workspaces/jaxsim/.pixi",
"postCreateCommand": "sudo chown vscode .pixi && git lfs pull --include='pixi.lock' && pixi install --environment=test-cpu",

// Configure tool-specific properties.
// "customizations": {},
Expand All @@ -27,7 +32,7 @@
"customizations": {
"vscode": {
"settings": {
"python.pythonPath": "/workspaces/jaxsim/.pixi/envs/test-cpu/bin/python",
"python.pythonPath": "/workspaces/jaxsim/.pixi/envs/test-cpu/bin/python",
"python.defaultInterpreterPath": "/workspaces/jaxsim/.pixi/envs/test-cpu/bin/python",
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": true
Expand All @@ -37,8 +42,9 @@
"donjayamanne.python-extension-pack",
"ms-toolsai.jupyter",
"GitHub.codespaces",
"GitHub.copilot",
"ms-azuretools.vscode-docker",
"charliermarsh.ruff"
"charliermarsh.ruff"
]
}
}
Expand Down

0 comments on commit 52bb311

Please sign in to comment.