Skip to content

Add dev container #6962

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

Merged
merged 14 commits into from
Aug 23, 2024
Merged

Add dev container #6962

merged 14 commits into from
Aug 23, 2024

Conversation

nojaf
Copy link
Collaborator

@nojaf nojaf commented Aug 19, 2024

Fixes #6851

@cristianoc what VS Code extensions do you use to develop in this codebase? These should be included in the devcontainer as well.

I noticed that running opam init in the Dockerfile does not initialize opam in the postCreate.sh file. I'm not sure why this is. All the opam commands are very heavy and make my pc go into overdrive, is this normal? I'm also not sure whether this lines should be in the Dockerfile or postCreate.sh.

image

Are all these steps in the postCreate.sh necessary you think? If we could have a trimmed down version of this, that be great as well.

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

@cristianoc what VS Code extensions do you use to develop in this codebase? These should be included in the devcontainer as well.

See https://github.com/rescript-lang/rescript-compiler/blob/master/.vscode/extensions.json

I noticed that running opam init in the Dockerfile does not initialize opam in the postCreate.sh file. I'm not sure why this is.

Not sure what you mean exactly. The opam stuff goes into ~/.opam. Is the devcontainer run with a different user than root? Then that would be an explanation for why it is not found.

All the opam commands are very heavy and make my pc go into overdrive, is this normal?

I would say yes, it builds the OCaml compiler and all dependencies from source, this is a rather heavy operation.

I'm also not sure whether this lines should be in the Dockerfile or postCreate.sh.

I think it makes sense to do the opam init etc. in postCreate.sh and not in the Dockerfile (especially if this is run with a user other than root).

@nojaf
Copy link
Collaborator Author

nojaf commented Aug 20, 2024

extensions

Do I not need something like https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform to connect to the lps-server? Right now I don't get any highlighting for any .ml files.

Not sure what you mean exactly. The opam stuff goes into ~/.opam. Is the devcontainer run with a different user than root? Then that would be an explanation for why it is not found.

Yes, this is the case, I've learned how to deal with this. But moving all that to postCreate.sh also solves this.

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

Do I not need something like https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform to connect to the lps-server? Right now I don't get any highlighting for any .ml files.

Ah, yes, you are right, ocamllabs.ocaml-platform is missing in https://github.com/rescript-lang/rescript-compiler/blob/master/.vscode/extensions.json, too.

@nojaf nojaf marked this pull request as ready for review August 20, 2024 10:05
@nojaf
Copy link
Collaborator Author

nojaf commented Aug 20, 2024

ocamllabs.ocaml-platform is missing

Yep, that worked. Thanks, I think this is good to go.

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

Just noticed that the extension rust-lang.rust-analyzer is also missing (for working on rewatch which is written in Rust).

Could you also add the missing extensions to https://github.com/rescript-lang/rescript-compiler/blob/master/.vscode/extensions.json, please?

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

I tried to work with the dev container, but got the following error:

[14 ms] Dev Containers 0.380.0 in VS Code 1.92.2 (fee1edb8d6d72a0ddff41e5f71a671c23ed924b9).
[13 ms] Start: Resolving Remote
[20 ms] Setting up container for folder or workspace: /Users/christoph/projects/cca/rescript-compiler
[21 ms] Context: desktop-linux
[22 ms] Start: Check Docker is running
[22 ms] Start: Run: docker version
[66 ms] Client:
 Version:           27.1.1
 API version:       1.46
 Go version:        go1.21.12
 Git commit:        6312585
 Built:             Tue Jul 23 19:54:12 2024
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.33.0 (160616)
 Engine:
  Version:          27.1.1
  API version:      1.46 (minimum version 1.24)
  Go version:       go1.21.12
  Git commit:       cc13f95
  Built:            Tue Jul 23 19:57:14 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.19
  GitCommit:        2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
 runc:
  Version:          1.7.19
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[71 ms] Start: Run: docker volume ls -q
[102 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/Users/christoph/projects/cca/rescript-compiler --filter label=vsch.quality=stable
[119 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/christoph/projects/cca/rescript-compiler --filter label=devcontainer.config_file=/Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json
[143 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/christoph/projects/cca/rescript-compiler
[166 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/christoph/projects/cca/rescript-compiler
[186 ms] Running Dev Containers CLI:   up --user-data-folder /Users/christoph/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-fb8280f4-f068-4348-b823-86a4fedd5e011724156603466 --workspace-folder /Users/christoph/projects/cca/rescript-compiler --workspace-mount-consistency cached --id-label devcontainer.local_folder=/Users/christoph/projects/cca/rescript-compiler --id-label devcontainer.config_file=/Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[217 ms] ProxyResolver#loadSystemCertificates count
[220 ms] ProxyResolver#loadSystemCertificates count filtered
[224 ms] Start: Run: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users/christoph/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-fb8280f4-f068-4348-b823-86a4fedd5e011724156603466 --workspace-folder /Users/christoph/projects/cca/rescript-compiler --workspace-mount-consistency cached --id-label devcontainer.local_folder=/Users/christoph/projects/cca/rescript-compiler --id-label devcontainer.config_file=/Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[461 ms] @devcontainers/cli 0.65.0. Node.js v20.14.0. darwin 23.6.0 arm64.
[461 ms] Start: Run: docker buildx version
[526 ms] github.com/docker/buildx v0.16.1-desktop.1 8931f42a456e446f75f96d06902bbac8f1c1d3bd
[526 ms] 
[526 ms] Start: Run: docker -v
[540 ms] Start: Resolving Remote
[542 ms] Start: Run: git rev-parse --show-cdup
[559 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/christoph/projects/cca/rescript-compiler --filter label=devcontainer.config_file=/Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json
[620 ms] Start: Run: docker inspect --type image mcr.microsoft.com/devcontainers/rust:1-1-bookworm
[694 ms] Resolving Feature dependencies for 'ghcr.io/devcontainers/features/github-cli:1'...
[694 ms] * Processing feature: ghcr.io/devcontainers/features/github-cli:1
[697 ms] Loading 50 extra certificates from /var/folders/l3/d1wj17dj2z321tjq9s9fnlsh0000gn/T/vsch/certificates-a8c83f6baefdbe211b7838898a488e39f6b64331bf833a2da8e152eabe054a0b.pem.
[908 ms] Start: Run: docker-credential-desktop get
[1379 ms] * Processing feature: ghcr.io/devcontainers/features/common-utils
[1608 ms] * Processing feature: ghcr.io/devcontainers/features/git
[1818 ms] Resolving Feature dependencies for 'ghcr.io/devcontainers/features/node:1'...
[1818 ms] * Processing feature: ghcr.io/devcontainers/features/node:1
[2058 ms] * Processing feature: ghcr.io/devcontainers/features/common-utils
[2262 ms] Soft-dependency 'ghcr.io/devcontainers/features/git' is not required.  Removing from installation order...
[2262 ms] Soft-dependency 'ghcr.io/devcontainers/features/common-utils' is not required.  Removing from installation order...
[2262 ms] Soft-dependency 'ghcr.io/devcontainers/features/common-utils' is not required.  Removing from installation order...
[2263 ms] * Fetching feature: github-cli_0_oci
[2519 ms] * Fetched feature: github-cli_0_oci version 1.0.13
[2519 ms] * Fetching feature: node_1_oci
[2777 ms] * Fetched feature: node_1_oci version 1.5.0
[2780 ms] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/l3/d1wj17dj2z321tjq9s9fnlsh0000gn/T/devcontainercli/container-features/0.65.0-1724156604612/Dockerfile-with-features -t vsc-rescript-compiler-59ab0e0547d6f1c00bbb03bf16e507660d5b8764443c1496d168920108824039 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/var/folders/l3/d1wj17dj2z321tjq9s9fnlsh0000gn/T/devcontainercli/container-features/0.65.0-1724156604612 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /Users/christoph/projects/cca/rescript-compiler/.devcontainer
[+] Building 0.9s (8/16)                                   docker:desktop-linux
 => [internal] load build definition from Dockerfile-with-features         0.0s
[+] Building 1.0s (9/16)                                   docker:desktop-linux
 => [internal] load build definition from Dockerfile-with-features         0.0s
 => => transferring dockerfile: 3.48kB                                     0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1  0.5s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for mcr.microsoft.com/devcontainers/rust:1-1  0.0s
 => [context dev_containers_feature_content_source] load .dockerignore     0.0s
 => => transferring dev_containers_feature_content_source: 2B              0.0s
 => CACHED [dev_container_auto_added_stage_label 1/2] FROM mcr.microsoft.  0.0s
 => [context dev_containers_feature_content_source] load from client       0.0s
 => => transferring dev_containers_feature_content_source: 33.75kB         0.0s
 => ERROR [dev_container_auto_added_stage_label 2/2] RUN apt-get update &  0.3s
------                                                                          
 > [dev_container_auto_added_stage_label 2/2] RUN apt-get update && export DEBIAN_FRONTEND=noninteractive     && apt-get -y install --no-install-recommends     opam     musl-tools     python-is-python3     && rm -rf /var/lib/apt/lists/*:
0.222 Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]            
0.279 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]   
0.292 Err:1 http://deb.debian.org/debian bookworm InRelease                     
0.292   At least one invalid signature was encountered.
0.300 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
0.311 Err:2 http://deb.debian.org/debian bookworm-updates InRelease
0.311   At least one invalid signature was encountered.
0.327 Err:3 http://deb.debian.org/debian-security bookworm-security InRelease
0.327   At least one invalid signature was encountered.
0.329 Reading package lists...
0.334 W: GPG error: http://deb.debian.org/debian bookworm InRelease: At least one invalid signature was encountered.
0.334 E: The repository 'http://deb.debian.org/debian bookworm InRelease' is not signed.
0.334 W: GPG error: http://deb.debian.org/debian bookworm-updates InRelease: At least one invalid signature was encountered.
0.334 E: The repository 'http://deb.debian.org/debian bookworm-updates InRelease' is not signed.
0.334 W: GPG error: http://deb.debian.org/debian-security bookworm-security InRelease: At least one invalid signature was encountered.
0.334 E: The repository 'http://deb.debian.org/debian-security bookworm-security InRelease' is not signed.
------
Dockerfile-with-features:7
--------------------
   6 |     
   7 | >>> RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
   8 | >>>     && apt-get -y install --no-install-recommends \
   9 | >>>     opam \
  10 | >>>     musl-tools \
  11 | >>>     python-is-python3 \
  12 | >>>     && rm -rf /var/lib/apt/lists/*
  13 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && export DEBIAN_FRONTEND=noninteractive     && apt-get -y install --no-install-recommends     opam     musl-tools     python-is-python3     && rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100
[3953 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/l3/d1wj17dj2z321tjq9s9fnlsh0000gn/T/devcontainercli/container-features/0.65.0-1724156604612/Dockerfile-with-features -t vsc-rescript-compiler-59ab0e0547d6f1c00bbb03bf16e507660d5b8764443c1496d168920108824039 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/var/folders/l3/d1wj17dj2z321tjq9s9fnlsh0000gn/T/devcontainercli/container-features/0.65.0-1724156604612 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /Users/christoph/projects/cca/rescript-compiler/.devcontainer
[3953 ms]     at mtA (/Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js:466:1933)
[3953 ms]     at async Pm (/Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js:465:1856)
[3953 ms]     at async NH (/Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js:465:610)
[3953 ms]     at async KtA (/Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js:482:3771)
[3953 ms]     at async eB (/Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js:482:4886)
[3953 ms]     at async hrA (/Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js:663:200)
[3953 ms]     at async lrA (/Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js:662:13452)
[3957 ms] Exit code 1
[3959 ms] Command failed: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/christoph/.vscode/extensions/ms-vscode-remote.remote-containers-0.380.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users/christoph/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-fb8280f4-f068-4348-b823-86a4fedd5e011724156603466 --workspace-folder /Users/christoph/projects/cca/rescript-compiler --workspace-mount-consistency cached --id-label devcontainer.local_folder=/Users/christoph/projects/cca/rescript-compiler --id-label devcontainer.config_file=/Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/christoph/projects/cca/rescript-compiler/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[3959 ms] Exit code 1

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

I tried to work with the dev container, but got the following error:

After a docker image prune -a it is building now. Will test some more later.

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

Could you also add a CHANGELOG entry?

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

Ok so now my Devcontainer was created successfully.
And when I open a terminal in VS Code, I am now in a Linux shell in the container.

The opam stuff is not in the path there, I need to execute eval $(opam env).
If I do that and run dune build, the build fails, because the dependencies (ounit2, cppo) are missing.
Is this the same for you?

@nojaf
Copy link
Collaborator Author

nojaf commented Aug 20, 2024

The opam stuff is not in the path there, I need to execute eval $(opam env).

I have this in bash, please try zsh instead. There dune build works for me.

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

The opam stuff is not in the path there, I need to execute eval $(opam env).

I have this in bash, please try zsh instead. There dune build works for me.

I have the exact same issue in zsh (opam env not set, and after I set it dune build does not work).

@nojaf
Copy link
Collaborator Author

nojaf commented Aug 20, 2024

Are you sure that postCreate.sh runs correctly till the end?

After that I can do:

image

image

@cknitt
Copy link
Member

cknitt commented Aug 21, 2024

Yes, postCreate.sh runs till the end, but it still doesn't work for me.
@fhammerschmidt could you also test this on your machine?

@fhammerschmidt
Copy link
Member

fhammerschmidt commented Aug 21, 2024

Works for me after the setup process in a built-in zsh
My steps:

  • check out rescript-compiler repo in a pristine state
  • check out this pr
  • had vscode already open, selected command "Reopen in dev container"
  • waited a bit until setup was done
  • open integrated zsh
  • make && make test

@fhammerschmidt
Copy link
Member

fhammerschmidt commented Aug 21, 2024

Can you also adapt the installation section in CONTRIBUTING.md? In a way that makes it clear what parts of the manual setup are covered.

@cknitt
Copy link
Member

cknitt commented Aug 21, 2024

Works for me after the setup process in a built-in zsh

Ok, then something is broken on my machine. Will give it another try later.

@nojaf
Copy link
Collaborator Author

nojaf commented Aug 21, 2024

Can you also adapt the installation section in CONTRIBUTING.md? In a way that makes it clear what parts of the manual setup are covered.

Sure, do you mean adding a section on how the devcontainer works? Or updating some of the existing text?

@cknitt
Copy link
Member

cknitt commented Aug 21, 2024

Sure, do you mean adding a section on how the devcontainer works? Or updating some of the existing text?

Maybe add a new section "Devcontainer Setup" below the existing "Setup" section?

@fhammerschmidt
Copy link
Member

Hmmm, I think
Install OCaml compiler + dependencies
and
npm install
need to be subsections of a general Installation section

maybe something like

Installation

A. Manual Installation

Install OCaml compiler + dependencies

npm install

B. Installation via devcontainer

@cknitt
Copy link
Member

cknitt commented Aug 21, 2024

Retried and it still didn't work for me.

Something else: In the log output from the post create script, I found the following:

[WARNING] Shell not updated in non-interactive mode: use --shell-setup

So it seems the shell setup can be performed automatically if --shell-setup is specified on opam init, maybe we should try that?

@nojaf
Copy link
Collaborator Author

nojaf commented Aug 21, 2024

--shell-setup adds this to the ~/.profile file:

# opam configuration
test -r /home/vscode/.opam/opam-init/init.sh && . /home/vscode/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

but this file doesn't get sourced by bash or zsh it seems.

@cknitt
Copy link
Member

cknitt commented Aug 22, 2024

but this file doesn't get sourced by bash or zsh it seems.

Ok, never mind then.

Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

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

Great work! Thanks a lot!

@fhammerschmidt
Copy link
Member

Hell yeah! Thanks for this!

@cknitt cknitt merged commit 897cc22 into rescript-lang:master Aug 23, 2024
20 checks passed
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.

Add dev container
3 participants