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

Update Devcontainer configuration to use pixi #276

Merged
merged 2 commits into from
Nov 12, 2024
Merged

Conversation

flferretti
Copy link
Collaborator

@flferretti flferretti commented Oct 29, 2024

This pull request updates the Devcontainer configuration by using pixi as the base image and installing additional extensions. The Dockerfile has been modified to pull the pixi.lock from LFS, create the environment and then use a shell-hook script to activate it. Moreover, the devcontainer.json file has been updated to set the default Python interpreter path and add some useful extensions to the VSCode environment.


📚 Documentation preview 📚: https://jaxsim--276.org.readthedocs.build//276/

@flferretti flferretti self-assigned this Oct 29, 2024
Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, approving regardless.

@flferretti flferretti force-pushed the fix_devcontainer branch 2 times, most recently from 954c261 to fcb9816 Compare November 5, 2024 15:53
@CarlottaSartore
Copy link
Contributor

@flferretti can you please finalize this PR?

@flferretti flferretti force-pushed the fix_devcontainer branch 2 times, most recently from ae6d9a9 to d817f0c Compare November 7, 2024 15:13
@xela-95
Copy link
Member

xela-95 commented Nov 8, 2024

Hi @flferretti, thanks for the PR!
I'm trying to use the devcontainer you provided, but I get the following error:

Docker build log

[82 ms] Dev Containers 0.388.0 in VS Code 1.95.1 (65edc4939843c90c34d61f4ce11704f09d3e5cb6).
[81 ms] Start: Resolving Remote
[97 ms] Setting up container for folder or workspace: /home/acroci/repos/jaxsim
[118 ms] Start: Check Docker is running
[119 ms] Start: Run: docker version
[135 ms] Client: Docker Engine - Community
 Version:           27.2.0
 API version:       1.47
 Go version:        go1.21.13
 Git commit:        3ab4256
 Built:             Tue Aug 27 14:15:13 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
[135 ms]  Engine:
  Version:          27.2.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.21.13
  Git commit:       3ab5c7d
  Built:            Tue Aug 27 14:15:13 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.21
  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[138 ms] Start: Run: docker volume ls -q
[151 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/home/acroci/repos/jaxsim --filter label=vsch.quality=stable
[164 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/acroci/repos/jaxsim --filter label=devcontainer.config_file=/home/acroci/repos/jaxsim/.devcontainer/devcontainer.json
[176 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/acroci/repos/jaxsim
[188 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/acroci/repos/jaxsim
[201 ms] Running Dev Containers CLI:   up --user-data-folder /home/acroci/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-bbeda1d9-8194-43ff-9cef-2391d48148751731057884671 --workspace-folder /home/acroci/repos/jaxsim --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/home/acroci/repos/jaxsim --id-label devcontainer.config_file=/home/acroci/repos/jaxsim/.devcontainer/devcontainer.json --log-level debug --log-format json --config /home/acroci/repos/jaxsim/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=/run/user/1000/wayland-0,target=/tmp/vscode-wayland-b8194886-e522-4e0b-9055-baa955321e5d.sock --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[202 ms] Start: Run: /snap/code/174/usr/share/code/code /home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/acroci/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-bbeda1d9-8194-43ff-9cef-2391d48148751731057884671 --workspace-folder /home/acroci/repos/jaxsim --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/home/acroci/repos/jaxsim --id-label devcontainer.config_file=/home/acroci/repos/jaxsim/.devcontainer/devcontainer.json --log-level debug --log-format json --config /home/acroci/repos/jaxsim/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=/run/user/1000/wayland-0,target=/tmp/vscode-wayland-b8194886-e522-4e0b-9055-baa955321e5d.sock --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[395 ms] @devcontainers/cli 0.71.0. Node.js v20.18.0. linux 6.8.0-48-generic x64.
[394 ms] Start: Run: docker buildx version
[435 ms] github.com/docker/buildx v0.16.2 99dea6d
[435 ms] 
[435 ms] Start: Run: docker -v
[446 ms] Start: Resolving Remote
[448 ms] Start: Run: git rev-parse --show-cdup
[454 ms] Loading 146 extra certificates from /etc/ssl/certs/ca-certificates.crt.
[1541 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/acroci/repos/jaxsim --filter label=devcontainer.config_file=/home/acroci/repos/jaxsim/.devcontainer/devcontainer.json
[1556 ms] Start: Run: docker inspect --type image ghcr.io/prefix-dev/pixi:latest
[1925 ms] Start: Run: docker-credential-secret get
[4296 ms] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-acroci/container-features/0.71.0-1731057889682/Dockerfile-with-features -t vsc-jaxsim-aaed2071f8eebd964e1a968507aecfd3be674c8be1318f56b3276c7bca98ebd4 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label /home/acroci/repos/jaxsim
[+] Building 139.9s (9/10)                                       docker:default
 => [internal] load build definition from Dockerfile-with-features         0.0s
 => => transferring dockerfile: 1.43kB                                     0.0s
 => [internal] load metadata for ghcr.io/prefix-dev/pixi:latest            0.6s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load build context                                          5.5s
 => => transferring context: 31.55MB                                       5.3s
 => CACHED [dev_container_auto_added_stage_label 1/6] FROM ghcr.io/prefix  0.0s
 => [dev_container_auto_added_stage_label 2/6] COPY . /workspace/jaxsim   36.8s
 => [dev_container_auto_added_stage_label 3/6] WORKDIR /workspace/jaxsim   0.0s
 => [dev_container_auto_added_stage_label 4/6] RUN apt-get update &&      96.8s
 => ERROR [dev_container_auto_added_stage_label 5/6] RUN git lfs install   0.1s 
------                                                                          
 > [dev_container_auto_added_stage_label 5/6] RUN git lfs install &&    git-lfs pull --include="pixi.lock":
0.132 Hook already exists: pre-push                                             
0.132                                                                           
0.132   #!/bin/sh                                                               
0.132   command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
0.132   git lfs pre-push "$@"
0.132 
0.132 To resolve this, either:
0.132   1: run `git lfs update --manual` for instructions on how to merge hooks.
0.132   2: run `git lfs update --force` to overwrite your hook.
------
Dockerfile-with-features:13
--------------------
  12 |     # Initialize Git LFS
  13 | >>> RUN git lfs install &&\
  14 | >>>     git-lfs pull --include="pixi.lock"
  15 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c git lfs install &&    git-lfs pull --include=\"pixi.lock\"" did not complete successfully: exit code: 2
[144336 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-acroci/container-features/0.71.0-1731057889682/Dockerfile-with-features -t vsc-jaxsim-aaed2071f8eebd964e1a968507aecfd3be674c8be1318f56b3276c7bca98ebd4 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label /home/acroci/repos/jaxsim
[144336 ms]     at RtA (/home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:466:1933)
[144336 ms]     at async _m (/home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:465:1896)
[144337 ms]     at async bH (/home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:465:610)
[144337 ms]     at async TtA (/home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:482:3848)
[144337 ms]     at async iB (/home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:482:4963)
[144337 ms]     at async wrA (/home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:663:203)
[144337 ms]     at async DrA (/home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:662:14830)
[144337 ms]     at async /home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js:482:1190
[144341 ms] Exit code 1
[144350 ms] Command failed: /snap/code/174/usr/share/code/code /home/acroci/.vscode/extensions/ms-vscode-remote.remote-containers-0.388.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/acroci/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-bbeda1d9-8194-43ff-9cef-2391d48148751731057884671 --workspace-folder /home/acroci/repos/jaxsim --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/home/acroci/repos/jaxsim --id-label devcontainer.config_file=/home/acroci/repos/jaxsim/.devcontainer/devcontainer.json --log-level debug --log-format json --config /home/acroci/repos/jaxsim/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=/run/user/1000/wayland-0,target=/tmp/vscode-wayland-b8194886-e522-4e0b-9055-baa955321e5d.sock --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[144350 ms] Exit code 1

Have you ever had this? I'm suspecting this could be due to my weak internet connection while pulling the pixi.lock file. I will investigate this further.

@xela-95
Copy link
Member

xela-95 commented Nov 8, 2024

Hi @flferretti, thanks for the PR!
I'm trying to use the devcontainer you provided, but I get the following error:

Actually, looking at this part of the error log, I think it is some problem on the installation of git-lfs:

 => ERROR [dev_container_auto_added_stage_label 5/6] RUN git lfs install   0.1s 
------                                                                          
 > [dev_container_auto_added_stage_label 5/6] RUN git lfs install &&    git-lfs pull --include="pixi.lock":
0.132 Hook already exists: pre-push                                             
0.132                                                                           
0.132   #!/bin/sh                                                               
0.132   command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
0.132   git lfs pre-push "$@"
0.132 
0.132 To resolve this, either:
0.132   1: run `git lfs update --manual` for instructions on how to merge hooks.
0.132   2: run `git lfs update --force` to overwrite your hook.

@diegoferigo
Copy link
Member

I'm about to propose a new approach, wait for it.

@diegoferigo
Copy link
Member

diegoferigo commented Nov 8, 2024

Can you please try with the following?

  • Requires using buildkit (that is the new default backend)
  • Uses multi-stage builds
  • Uses the pixi image for building the environment and the official ubuntu image for running the devcontainer
# syntax=docker/dockerfile:1.4
ARG PROJECT_NAME=jaxsim
ARG PIXI_ENVIRONMENT=test-cpu

# 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

# 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/*

# Create the pixi environment.
COPY . /$PROJECT_NAME
WORKDIR /$PROJECT_NAME
RUN cd /$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

# 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

# Copy the environment in the /jaxsim folder.
WORKDIR /$PROJECT_NAME
COPY --from=build /$PROJECT_NAME/.pixi/envs/$PIXI_ENVIRONMENT /$PROJECT_NAME/.pixi/envs/$PIXI_ENVIRONMENT
COPY --from=build /shell-hook.sh /shell-hook.sh

# Set the shell-hook script as the entrypoint.
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"]

I can push it in this branch if you like the approach.

@flferretti
Copy link
Collaborator Author

Can you please try with the following?

* Requires using buildkit (that is the new default backend)

* Uses multi-stage builds

* Uses the pixi image for building the environment and the official ubuntu image for running the devcontainer
# syntax=docker/dockerfile:1.4
ARG PROJECT_NAME=jaxsim
ARG PIXI_ENVIRONMENT=test-cpu

# 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 PIXI_ENVIRONMENT

# 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/*

# Create the pixi environment.
COPY . /$PROJECT_NAME
WORKDIR /$PROJECT_NAME
RUN cd /$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

# 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 PIXI_ENVIRONMENT

# Copy the environment in the /jaxsim folder.
WORKDIR /$PROJECT_NAME
COPY --from=build /$PROJECT_NAME/.pixi/envs/$PIXI_ENVIRONMENT /$PROJECT_NAME/.pixi/envs/$PIXI_ENVIRONMENT
COPY --from=build /shell-hook.sh /shell-hook.sh

# Set the shell-hook script as the entrypoint.
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"]

I can push it in this branch if you like the approach.

Thanks Diego! Feel free to push it to this branch, so it can be tested with devcontainer. In the worst case, we can drop the commit via rebase

@flferretti
Copy link
Collaborator Author

Hi @flferretti, thanks for the PR!
I'm trying to use the devcontainer you provided, but I get the following error:

Actually, looking at this part of the error log, I think it is some problem on the installation of git-lfs:

 => ERROR [dev_container_auto_added_stage_label 5/6] RUN git lfs install   0.1s 
------                                                                          
 > [dev_container_auto_added_stage_label 5/6] RUN git lfs install &&    git-lfs pull --include="pixi.lock":
0.132 Hook already exists: pre-push                                             
0.132                                                                           
0.132   #!/bin/sh                                                               
0.132   command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
0.132   git lfs pre-push "$@"
0.132 
0.132 To resolve this, either:
0.132   1: run `git lfs update --manual` for instructions on how to merge hooks.
0.132   2: run `git lfs update --force` to overwrite your hook.

I'm not encountering this error when building the devcontainer from this PR. How are you testing it?

@xela-95
Copy link
Member

xela-95 commented Nov 8, 2024

Can you please try with the following?

  • Requires using buildkit (that is the new default backend)
  • Uses multi-stage builds
  • Uses the pixi image for building the environment and the official ubuntu image for running the devcontainer

Thanks @diegoferigo I will try it!

Meanwhile, I discovered it was sufficient to update the command git lfs install with git lfs install --force to make it work.

@xela-95
Copy link
Member

xela-95 commented Nov 8, 2024

I'm not encountering this error when building the devcontainer from this PR. How are you testing it?

I'm using the devcontainer extension of vscode and just clicking on the devocontainer button
image
and executing Reopen in Container.

@flferretti
Copy link
Collaborator Author

flferretti commented Nov 8, 2024

I'm not encountering this error when building the devcontainer from this PR. How are you testing it?

I'm using the devcontainer extension of vscode and just clicking on the devocontainer button image and executing Reopen in Container.

Now I remember why the curl passage was necessary, let me try to restore it. Probably when installing git-lfs from the default repositories, an obsolete version gets installed. The script should add the most recent repo to apt

@diegoferigo
Copy link
Member

Thanks Diego! Feel free to push it to this branch, so it can be tested with devcontainer. In the worst case, we can drop the commit via rebase

Done in ffc8a55.

Copy link
Contributor

@traversaro traversaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big expert of devcontainer, so anything is ok for me. I just wanted to make sure that you checked https://pixi.sh/latest/ide_integration/devcontainer/ . For what regarding the gpu part, I guess enabling it in the devcontainer is tricky, right?

@diegoferigo
Copy link
Member

diegoferigo commented Nov 8, 2024

Not a big expert of devcontainer, so anything is ok for me. I just wanted to make sure that you checked https://pixi.sh/latest/ide_integration/devcontainer/ .

That's great, thanks for linking the documentation. I was not aware of it. I don't like that they operate on .bashrc since power users have their own devcontainer-compatible dotfiles repository, but there are alternative options.

For what regarding the gpu part, I guess enabling it in the devcontainer is tricky, right?

For this, likely a local setup is recommended. And people can use our pixi's feature.gpu.

@flferretti
Copy link
Collaborator Author

Done in ffc8a55.

Thanks for your contribution Diego! Nevertheless, I believe a multistage build is way too complex for a tool that is supposed to be light, easy to use and maintain. Do you mind if we just come back to the last working commit (d817f0c)?

For this, likely a local setup is recommended. And people can use our pixi's feature.gpu.

I totally agree on this! This is just meant to be an easy way to review PR or perform some quick tests

@diegoferigo
Copy link
Member

diegoferigo commented Nov 8, 2024

This is also the approach used here: https://github.com/prefix-dev/pixi-docker/blob/main/example/Dockerfile. It seems to me a good option (the only one that I can think of) that allows to build an environment using the official pixi image and run the devcontainer using the official ms image. This is to me much more robust on the long term since both ms/pixi can update their core images following their development cycle and we don't have to care. Of course, on our side, we need to pay the price of a slightly more complicated build stage (I could link to you really complex images and this is definitely not one of them 😄).

@diegoferigo
Copy link
Member

diegoferigo commented Nov 8, 2024

Note also that I'm not really sure how your previous solution worked, because when you mount a volume (the repository of a PR) over an existing folder (the empty repository stored in the image with just the .pixi folder), the previous folder is erased (more technically, the previous folder is overlayed).

Before this PR, things were working fine because the image was using a regular conda environment. Now, with pixi the situations got entangled because the .pixi folder needs to be located in the repository folder.

@traversaro
Copy link
Contributor

Before this PR, things were working fine because the image was using a regular conda environment. Now, with pixi the situations got entangled because the .pixi folder needs to be located in the repository folder.

Note that you can change this with https://pixi.sh/latest/reference/pixi_configuration/#detached-environments, but I am not sure how handy is to do that in this case. Anyhow, I do not know enough about devcontainers to get everything you are discussing here, but if you have any specific point you want to discuss with pixi devs, feel free to open a discussion in https://github.com/prefix-dev/pixi/discussions or prefix's discord, in my experience they are quite receptive to user's feedback from advanced use cases.

@xela-95
Copy link
Member

xela-95 commented Nov 8, 2024

This is also the approach used here: https://github.com/prefix-dev/pixi-docker/blob/main/example/Dockerfile. It seems to me a good option (the only one that I can think of) that allows to build an environment using the official pixi image and run the devcontainer using the official ms image. This is to me much more robust on the long term since both ms/pixi can update their core images following their development cycle and we don't have to care. Of course, on our side, we need to pay the price of a slightly more complicated build stage (I could link to you really complex images and this is definitely not one of them 😄).

I agree with this approach for two reasons: it follows the pixi guidelines on how to build a devcontainer image and secondly it should be easy to maintain. I am trying this now, if I am able to run a simple script there for me is good to go.

@diegoferigo
Copy link
Member

I'm not sure why, but if I create a codespace from the fix_devcontainer branch, I get the following error:

image

@xela-95
Copy link
Member

xela-95 commented Nov 8, 2024

I am trying this now, if I am able to run a simple script there for me is good to go.

I tried it locally, it started but during the build it gave me an error:

[737098 ms] Start: Run in container: /bin/sh -c bash -c 'source /shell-hook.sh'
ln: failed to create symbolic link '/jaxsim/.pixi': Permission denied
/shell-hook.sh: line 14: /jaxsim/.pixi/envs/test-cpu/etc/conda/activate.d/libglib_activate.sh: No such file or directory
/shell-hook.sh: line 15: /jaxsim/.pixi/envs/test-cpu/etc/conda/activate.d/libxml2_activate.sh: No such file or directory
/shell-hook.sh: line 16: /jaxsim/.pixi/envs/test-cpu/etc/conda/activate.d/ruby_activate.sh: No such file or directory

I don't know if it is related to this but then from the devcontainer terminal I cannot run the pixi environment python or use it as kernel to run example notebooks.

@xela-95
Copy link
Member

xela-95 commented Nov 8, 2024

I'm not sure why, but if I create a codespace from the fix_devcontainer branch, I get the following error:

I'm able to launch the devcontainer from codespaces (not getting your error), but also in this case there are issues and the codespace launches a recovery container:

#16 [build 5/5] RUN cd /jaxsim &&    git lfs pull &&    pixi install --environment test-cpu &&    echo "ln -s /pixi /jaxsim/.pixi" >> /shell-hook.sh &&    pixi shell-hook --environment test-cpu >> /shell-hook.sh &&    echo 'exec "$@"' >> /shell-hook.sh &&    chmod +x /shell-hook.sh
#16 0.674 batch response: Post "********/********.git/info/lfs/objects/batch": x509: certificate signed by unknown authority
#16 0.674 error: failed to fetch some objects from '********/********.git/info/lfs'
#16 ERROR: process "/bin/sh -c cd /$PROJECT_NAME &&    git lfs pull &&    pixi install --environment $PIXI_ENVIRONMENT &&    echo \"ln -s /pixi /$PROJECT_NAME/.pixi\" >> /shell-hook.sh &&    pixi shell-hook --environment $PIXI_ENVIRONMENT >> /shell-hook.sh &&    echo 'exec \"$@\"' >> /shell-hook.sh &&    chmod +x /shell-hook.sh" did not complete successfully: exit code: 2
------
 > [build 5/5] RUN cd /jaxsim &&    git lfs pull &&    pixi install --environment test-cpu &&    echo "ln -s /pixi /jaxsim/.pixi" >> /shell-hook.sh &&    pixi shell-hook --environment test-cpu >> /shell-hook.sh &&    echo 'exec "$@"' >> /shell-hook.sh &&    chmod +x /shell-hook.sh:
0.674 batch response: Post "********/********.git/info/lfs/objects/batch": x509: certificate signed by unknown authority
0.674 error: failed to fetch some objects from '********/********.git/info/lfs'
------
Dockerfile-with-features:20
--------------------
  19 |     WORKDIR /$PROJECT_NAME
  20 | >>> RUN cd /$PROJECT_NAME &&\
  21 | >>>     git lfs pull &&\
  22 | >>>     pixi install --environment $PIXI_ENVIRONMENT &&\
  23 | >>>     echo "ln -s /pixi /$PROJECT_NAME/.pixi" >> /shell-hook.sh &&\
  24 | >>>     pixi shell-hook --environment $PIXI_ENVIRONMENT >> /shell-hook.sh &&\
  25 | >>>     echo 'exec "$@"' >> /shell-hook.sh &&\
  26 | >>>     chmod +x /shell-hook.sh
  27 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c cd /$PROJECT_NAME &&    git lfs pull &&    pixi install --environment $PIXI_ENVIRONMENT &&    echo \"ln -s /pixi /$PROJECT_NAME/.pixi\" >> /shell-hook.sh &&    pixi shell-hook --environment $PIXI_ENVIRONMENT >> /shell-hook.sh &&    echo 'exec \"$@\"' >> /shell-hook.sh &&    chmod +x /shell-hook.sh" did not complete successfully: exit code: 2
[41110 ms] Stop: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.68.0-1731073904807/Dockerfile-with-features -t vsc-jaxsim-6e00638a1d817797e8792c8fe180ce1433b291d973b1cdeb038fafd3e72b5844 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=production /var/lib/docker/codespacemount/workspace/jaxsim
Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.68.0-1731073904807/Dockerfile-with-features -t vsc-jaxsim-6e00638a1d817797e8792c8fe180ce1433b291d973b1cdeb038fafd3e72b5844 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=production /var/lib/docker/codespacemount/workspace/jaxsim
    at FtA (/.codespaces/agent/bin/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:466:1933)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Pm (/.codespaces/agent/bin/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:465:1896)
    at async NH (/.codespaces/agent/bin/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:465:610)
    at async YtA (/.codespaces/agent/bin/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:482:3771)
    at async eB (/.codespaces/agent/bin/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:482:4886)
    at async prA (/.codespaces/agent/bin/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:663:200)
    at async drA (/.codespaces/agent/bin/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:662:14706)
{"outcome":"error","message":"Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.68.0-1731073904807/Dockerfile-with-features -t vsc-jaxsim-6e00638a1d817797e8792c8fe180ce1433b291d973b1cdeb038fafd3e72b5844 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=production /var/lib/docker/codespacemount/workspace/jaxsim","description":"An error occurred building the image."}
devcontainer process exited with exit code 1
Failed to create container.
Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.68.0-1731073904807/Dockerfile-with-features -t vsc-jaxsim-6e00638a1d817797e8792c8fe180ce1433b291d973b1cdeb038fafd3e72b5844 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=production /var/lib/docker/codespacemount/workspace/jaxsim
Error code: 1302 (UnifiedContainersErrorFatalCreatingContainer)
Container creation failed.

@diegoferigo
Copy link
Member

On my setup, I was able to build the container locally. I can try from VSCode, I still haven't. It seems a permission error probably due to the default usage of non-root user, I'm not that familiar with devcontainers.

@diegoferigo
Copy link
Member

Locally in VSCode now it seems building and loading correctly, but it still doesn't pick up the python interpreter from the pixi environment.

@flferretti
Copy link
Collaborator Author

flferretti commented Nov 12, 2024

In 52bb311 I modified the Dockerfile and the devcontainer.json as per https://pixi.sh/v0.35.0/ide_integration/devcontainer/ and I tested that it worked in GitHub Codespaces, correctly picking up the python interpreter both in terminal and in the workspace. If you agree, I'll clean the commit history and merge

Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it works for me, thanks! Your changes moved the creation of the pixi environment from the image to the container creation, and this means that every time you open a new devcontainer also locally is vscode, pixi needs to download many GB of data. It's not relevant for me, as this functionality is mainly useful in CodeSpaces.

FROM mcr.microsoft.com/devcontainers/base:ubuntu
COPY environment.yml /opt/environment.yml
# syntax=docker/dockerfile:1.4
FROM mcr.microsoft.com/devcontainers/base:jammy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work also on a newer ubuntu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm not aware of any OS-specific issue

@xela-95
Copy link
Member

xela-95 commented Nov 12, 2024

It works also for me now! Thanks @flferretti !

@flferretti flferretti merged commit 53d6ec5 into main Nov 12, 2024
24 checks passed
@flferretti flferretti deleted the fix_devcontainer branch November 12, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants