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

Error when cloning repo in container volume using basecloj template #29

Open
alza-bitz opened this issue Jan 28, 2025 · 10 comments · May be fixed by #35
Open

Error when cloning repo in container volume using basecloj template #29

alza-bitz opened this issue Jan 28, 2025 · 10 comments · May be fixed by #35

Comments

@alza-bitz
Copy link
Contributor

Hi there, when I attempt to create a new dev container using the basecloj template in VSCode, it makes some progress but ultimately fails.

I didn't look too far into the cause but it seems like some $USERNAME script var is empty, so the groupadd command fails due to a missing argument.

I did see that ARG USERNAME=vscode is present in the Dockerfile so I don't understand how this is happening, but there you go:

[10460 ms] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.72.0-1738105208356/Dockerfile-with-features -t vsc-basecloj-93cbbf93d1175c8cf32f6dd538d1ea9f635fddfbd28782b12b9240f6d38e4c28 --target dev_containers_target_stage --build-arg BASE_IMAGE=temurin-21-tools-deps-jammy --build-arg USERNAME= --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.72.0-1738105208356 --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 /workspaces/basecloj/.devcontainer
[+] Building 1.3s (9/17)                                                                                           docker:default
 => [internal] load build definition from Dockerfile-with-features                                                           0.0s
 => => transferring dockerfile: 2.84kB                                                                                       0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 2B                                                                                              0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4                                                                 0.4s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef  0.0s
 => [context dev_containers_feature_content_source] load .dockerignore                                                       0.0s
 => => transferring dev_containers_feature_content_source: 2B                                                                0.0s
 => [internal] load metadata for docker.io/library/clojure:temurin-21-tools-deps-jammy                                       0.4s
 => CACHED [dev_container_auto_added_stage_label 1/4] FROM docker.io/library/clojure:temurin-21-tools-deps-jammy@sha256:ebe  0.0s
 => [context dev_containers_feature_content_source] load from client                                                         0.0s
 => => transferring dev_containers_feature_content_source: 22.88kB                                                           0.0s
 => ERROR [dev_container_auto_added_stage_label 2/4] RUN groupadd --gid 1000      && useradd --uid 1000 --gid 1000 -m        0.4s
------
 > [dev_container_auto_added_stage_label 2/4] RUN groupadd --gid 1000      && useradd --uid 1000 --gid 1000 -m      && apt-get update     && apt-get install -y sudo     && echo  ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/     && chmod 0440 /etc/sudoers.d/:
0.341 Usage: groupadd [options] GROUP
0.341 
0.341 Options:
0.341   -f, --force                   exit successfully if the group already exists,
0.341                                 and cancel -g if the GID is already used
0.341   -g, --gid GID                 use GID for the new group
0.341   -h, --help                    display this help message and exit
0.341   -K, --key KEY=VALUE           override /etc/login.defs defaults
0.341   -o, --non-unique              allow to create groups with duplicate
0.341                                 (non-unique) GID
0.341   -p, --password PASSWORD       use this encrypted password for the new group
0.341   -r, --system                  create a system account
0.341   -R, --root CHROOT_DIR         directory to chroot into
0.341   -P, --prefix PREFIX_DIR       directory prefix
0.341       --extrausers              Use the extra users database
0.341 
------
Dockerfile-with-features:11
--------------------
  10 |     # Create the user
  11 | >>> RUN groupadd --gid $USER_GID $USERNAME \
  12 | >>>     && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
  13 | >>>     #
  14 | >>>     # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
  15 | >>>     && apt-get update \
  16 | >>>     && apt-get install -y sudo \
  17 | >>>     && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
  18 | >>>     && chmod 0440 /etc/sudoers.d/$USERNAME
  19 |         
--------------------
ERROR: failed to solve: process "/bin/sh -c groupadd --gid $USER_GID $USERNAME     && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME     && apt-get update     && apt-get install -y sudo     && echo $USERNAME ALL=\\(root\\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME     && chmod 0440 /etc/sudoers.d/$USERNAME" did not complete successfully: exit code: 2
[12171 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.72.0-1738105208356/Dockerfile-with-features -t vsc-basecloj-93cbbf93d1175c8cf32f6dd538d1ea9f635fddfbd28782b12b9240f6d38e4c28 --target dev_containers_target_stage --build-arg BASE_IMAGE=temurin-21-tools-deps-jammy --build-arg USERNAME= --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.72.0-1738105208356 --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 /workspaces/basecloj/.devcontainer
@alza-bitz
Copy link
Contributor Author

Looking at the log again I can see

docker buildx build ... --build-arg USERNAME= ...

So the value of USERNAME is not being passed for some reason..

@behrica
Copy link
Member

behrica commented Jan 29, 2025

yes, I have seen that as well (sometimes)
I think it depens on the "docker host".

Most OS have environemnt variable 'USER' set an then it does work.

We had as well an other issue about the same thing:
#27

@behrica
Copy link
Member

behrica commented Jan 29, 2025

so this should fix it:

"args": {
"USERNAME": "${localEnv:USER:VSCODE}"
}

Can you try , please ?

@behrica
Copy link
Member

behrica commented Jan 29, 2025

I just noticed that we never "published" the fix done in #27.
I just did that know, so we have a template with version 1.0.2 now, which hopefully fixes the issue as well for you.

Could you maybe try the latest version of the template (1.0.2) ?

@alza-bitz
Copy link
Contributor Author

Hi there, thanks for picking this up. I tried again earlier today from the VSCode ui directly, and it now works. So I guess VSCode must be picking up newer template versions automatically. I didn't try with the other devcontainer cmdline method.

One other point of note, the other template scicloj didn't have this issue.. it's devcontainer.json is different, it doesn't even have the build args section. Also, I am clearly missing a trick in how things get bootstrapped because in both cases the Dockerfile has the USERNAME hard-coded to vscode 🤔

Anyway this can be closed now, thanks!

@alza-bitz
Copy link
Contributor Author

alza-bitz commented Feb 18, 2025

Hi @behrica,

I just tried dev containers: clone repo in dev container volume and at add dev container configuration files I selected the basecloj template, but unfortunately I hit what I think is the same error as before?

Note: dev containers: new dev container works fine with basecloj it's just dev containers: clone repo in dev container volume that is not working.

Is this a regression regarding USERNAME or a subtly different bug?

Thanks 🙏

 => ERROR [dev_container_auto_added_stage_label 2/4] RUN groupadd --gid 1  0.5s
------                                                                          
 > [dev_container_auto_added_stage_label 2/4] RUN groupadd --gid 1000      && useradd --uid 1000 --gid 1000 -m      && apt-get update     && apt-get install -y sudo     && echo  ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/     && chmod 0440 /etc/sudoers.d/:
0.443 Usage: groupadd [options] GROUP                                           
0.443                                                                           
0.443 Options:                                                                  
0.443   -f, --force                   exit successfully if the group already exists,
0.443                                 and cancel -g if the GID is already used
0.443   -g, --gid GID                 use GID for the new group
0.443   -h, --help                    display this help message and exit
0.443   -K, --key KEY=VALUE           override /etc/login.defs defaults
0.443   -o, --non-unique              allow to create groups with duplicate
0.443                                 (non-unique) GID
0.443   -p, --password PASSWORD       use this encrypted password for the new group
0.443   -r, --system                  create a system account
0.443   -R, --root CHROOT_DIR         directory to chroot into
0.443   -P, --prefix PREFIX_DIR       directory prefix
0.443       --extrausers              Use the extra users database
0.443 
------
ERROR: failed to solve: process "/bin/sh -c groupadd --gid $USER_GID $USERNAME     && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME     && apt-get update     && apt-get install -y sudo     && echo $USERNAME ALL=\\(root\\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME     && chmod 0440 /etc/sudoers.d/$USERNAME" did not complete successfully: exit code: 2
[52563 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.73.0-1739890576087/Dockerfile-with-features -t vsc-geni-a507cd5ed9f045f4c1272018e0f0f99543c284019eaf86d4c47025c60b4a1974 --target dev_containers_target_stage --build-arg BASE_IMAGE=temurin-17-tools-deps-jammy --build-arg USERNAME= --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.73.0-1739890576087 --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 /workspaces/geni/.devcontainer
[52564 ms]     at RtA (/root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:469:1933)
[52564 ms]     at async jm (/root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:468:1896)
[52564 ms]     at async bH (/root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:468:610)
[52564 ms]     at async TtA (/root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:485:3848)
[52564 ms]     at async iB (/root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:485:4963)
[52564 ms]     at async wrA (/root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:666:203)
[52564 ms]     at async DrA (/root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:665:14830)
[52564 ms]     at async /root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js:485:1190
[52693 ms] Exit code 1
[52693 ms] Start: Run: docker rm -f 38d620b8cd69b42425a23b358f6dd80bf92feaeaa66c8ae1182abd3b528c82b4
[52695 ms] Command failed: node /root/.vscode-remote-containers/dist/dev-containers-cli-0.397.0/dist/spec-node/devContainersSpecCLI.js up --container-session-data-folder /tmp/devcontainers-82b57eee-5d7f-4c4d-af7c-97199463c94a1739890526791 --workspace-folder /workspaces/geni --workspace-mount-consistency cached --gpu-availability detect --id-label vsch.local.repository=https://github.com/zero-one-group/geni.git/tree/develop --id-label vsch.local.repository.volume=geni-develop-b09af604bb8d58ccd477f2fcfb17463cf9c703b2dc03d6096f76eb4c311d2d14 --id-label vsch.local.repository.folder=geni --id-label devcontainer.config_file=/workspaces/geni/.devcontainer/devcontainer.json --log-level debug --log-format json --config /workspaces/geni/.devcontainer/devcontainer.json --override-config /tmp/devcontainer-306c289a-15b3-48a8-8dcc-0a82443059a2.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=geni-develop-b09af604bb8d58ccd477f2fcfb17463cf9c703b2dc03d6096f76eb4c311d2d14,target=/workspaces,external=true --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=\\wsl.localhost\Debian\mnt\wslg\runtime-dir\wayland-0,target=/tmp/vscode-wayland-e7fc3f63-362c-426c-9fd4-4925b2889b6f.sock --skip-post-create --update-remote-user-uid-default off --mount-workspace-git-root --include-configuration --include-merged-configuration

@behrica
Copy link
Member

behrica commented Feb 18, 2025

Looking at this:

docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.73.0-1739890576087/Dockerfile-with-features -t vsc-geni-a507cd5ed9f045f4c1272018e0f0f99543c284019eaf86d4c47025c60b4a1974 --target dev_containers_target_stage --build-arg BASE_IMAGE=temurin-17-tools-deps-jammy --build-arg USERNAME= --build-context

seems to set the username explicitely to empty string.
So it overwrites what we have in the Dockerfile:

ARG USERNAME=vscode

Maybe this happens only when using 'clone repo in dev container volume' (which I never used...)

@behrica
Copy link
Member

behrica commented Feb 18, 2025

@alza-bitz
Could you try to replace

ARG USERNAME=vscode

with

ENV USERNAME=vscode

@behrica
Copy link
Member

behrica commented Feb 18, 2025

Does you devcontainer.json has this line ?

"USERNAME": "${localEnv:USER:vscode}"

There we set the default to "vscode"

@alza-bitz
Copy link
Contributor Author

alza-bitz commented Feb 19, 2025

Could you try to replace

ARG USERNAME=vscode

with

ENV USERNAME=vscode

Ok @behrica I edited the Dockerfile as suggested using edit devcontainer.json in recovery container and then rebuilt.

Result: no error, it seemed to work

So this would just be a small PR then?

Is it possible to test the use case dev containers: clone repo in dev container volume using the template from a PR branch in VSCode? Just wondering if it could be tested before merging any PR. 🙏

Edit: would also be a good idea to check other cases still work with this change before merging, e.g. dev containers: new dev container

@alza-bitz alza-bitz changed the title Error when creating new dev container using basecloj template Error when cloning repo in container volume using basecloj template Mar 6, 2025
alza-bitz added a commit to alza-bitz/devcontainer-templates that referenced this issue Mar 6, 2025
To persist the value into running containers.

Fixes scicloj#29.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants