rocker-org / devcontainer-images

R Docker images built with Dev Container Features
https://rocker-project.org/images/devcontainer/images.html
MIT License
12 stars 4 forks source link

When using ghcr.io/rocker-org/devcontainer/r-ver on VSCode Dev Container on arm64 the host `.gitconfig` is not imported #39

Closed Sparrow0hawk closed 1 year ago

Sparrow0hawk commented 1 year ago

Overview

When using the rocker/r-ver:4.2 image as a base for a VSCode devcontainer it doesn't import the host ~/.gitconfig due to the presence of a .gitconfig in the image for the rstudio user.

My workaround is to build the devcontainer using a local Dockerfile using the rocker/r-ver:4.2 as a base image and removing the .gitconfig file but could this .gitconfig file be removed to prevent this behaviour for devcontainer use?

Example workaround Dockerfile:

FROM ghcr.io/rocker-org/devcontainer/r-ver:4.2

USER rstudio

RUN rm ~/.gitconfig 

Details

Operating system: macOS Ventura 13.0.1 Docker version: Docker version 20.10.17, build 100c701 Image: ghcr.io/rocker-org/devcontainer/r-ver:4.2

Steps to reproduce

  1. Install VSCode and ensure you have the Remote development extension pack installed
  2. Open a project you want to use in a devcontainer in VSCode
  3. Create a directory within the project root called .devcontainer and add the following file .devcontainer/devcontainer.json:

    {
    "name": "R (rocker/r-ver base)",
    "image": "ghcr.io/rocker-org/devcontainer/r-ver:4.2",
    "features": {
        "ghcr.io/devcontainers/features/node:1": {
            "version": "lts"
        },
        "ghcr.io/devcontainers/features/git:1": {}
    }
    
    // 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": "R --version",
    
    // Configure tool-specific properties.
    // "customizations": {},
    
    // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
    // "remoteUser": "root"
    }
  4. Open the project within the container via VSCode command palette
  5. Attempt to make a commit and you'll get the following error:
    
    Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com" git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'rstudio@7784eae43c6f.(none)')

eitsupi commented 1 year ago

The file /home/rstudio/.gitconfig does not exist in ghcr.io/rocker-org/devcontainer/r-ver. I recommend checking to see if there is some other cause.

$ docker run --rm -it ghcr.io/rocker-org/devcontainer/r-ver:4.2 bash
Unable to find image 'ghcr.io/rocker-org/devcontainer/r-ver:4.2' locally
4.2: Pulling from rocker-org/devcontainer/r-ver
e96e057aae67: Already exists
bc51a8f1fa3b: Already exists
0abc830544e9: Already exists
d6e7a8cc8197: Already exists
2a88509eb7d5: Already exists
4e63186387da: Pull complete
149496b167d6: Pull complete
d6c485fa0a38: Pull complete
84721cad5744: Pull complete
1721288cca19: Pull complete
2b3075e95f43: Pull complete
Digest: sha256:21153dd4ca484a342776e4479c88e92b9775d6a680cd5fdc9d339904e475350a
Status: Downloaded newer image for ghcr.io/rocker-org/devcontainer/r-ver:4.2
root ➜ / $ ls -a /home/rstudio/
.  ..  .bash_logout  .bashrc  .cache  .oh-my-zsh  .profile  .zshrc
Sparrow0hawk commented 1 year ago

Curious, i'll do further investigation as it's clearly in another step!

Sparrow0hawk commented 1 year ago

So i'm repeating the steps you've tried @eitsupi and I don't seem to be able to reproduce the build without /home/rstudio/.gitconfig

I've tried this on my Mac after removing the old imagine and all associated layers:

$ docker run --rm -it ghcr.io/rocker-org/devcontainer/r-ver:4.2 bash
Unable to find image 'ghcr.io/rocker-org/devcontainer/r-ver:4.2' locally
4.2: Pulling from rocker-org/devcontainer/r-ver
0509fae36eb0: Pull complete 
bcac16e78051: Pull complete 
082776f72106: Pull complete 
c911869ac4ea: Pull complete 
cf0cbe3645ff: Pull complete 
4ea8bfccaaef: Pull complete 
409c7764fccb: Pull complete 
c94e4cbce7b4: Pull complete 
7136fb71f437: Pull complete 
489aca13b8d8: Pull complete 
29c7f74c444f: Pull complete 
Digest: sha256:21153dd4ca484a342776e4479c88e92b9775d6a680cd5fdc9d339904e475350a
Status: Downloaded newer image for ghcr.io/rocker-org/devcontainer/r-ver:4.2
root ➜ / $ ls -la /home/rstudio
total 40
drwxr-x---  1 rstudio rstudio 4096 Nov  3 18:45 .
drwxr-xr-x  1 root    root    4096 Nov  3 16:59 ..
-rw-r--r--  1 rstudio rstudio  220 Jan  6  2022 .bash_logout
-rw-r--r--  1 rstudio rstudio 4910 Nov  3 17:02 .bashrc
drwxrwxr-x  3 rstudio rstudio 4096 Nov  3 17:07 .cache
-rw-rw-r--  1 rstudio rstudio   29 Nov  3 18:45 .gitconfig
drwxr-xr-x 12 rstudio rstudio 4096 Nov  3 17:02 .oh-my-zsh
-rw-r--r--  1 rstudio rstudio  807 Jan  6  2022 .profile
-rw-r--r--  1 rstudio rstudio 3897 Nov  3 17:02 .zshrc
root ➜ / $ cat /home/rstudio/.gitconfig 
[credential]
    helper = cache
root ➜ / $ exit

And on my Raspberry Pi 4B running Docker version 20.10.21, build baeda1f

$ docker run --rm -it ghcr.io/rocker-org/devcontainer/r-ver:4.2 bash
Unable to find image 'ghcr.io/rocker-org/devcontainer/r-ver:4.2' locally
4.2: Pulling from rocker-org/devcontainer/r-ver
0509fae36eb0: Pull complete 
bcac16e78051: Pull complete 
082776f72106: Pull complete 
c911869ac4ea: Pull complete 
cf0cbe3645ff: Pull complete 
4ea8bfccaaef: Pull complete 
409c7764fccb: Pull complete 
c94e4cbce7b4: Pull complete 
7136fb71f437: Pull complete 
489aca13b8d8: Pull complete 
29c7f74c444f: Pull complete 
Digest: sha256:21153dd4ca484a342776e4479c88e92b9775d6a680cd5fdc9d339904e475350a
Status: Downloaded newer image for ghcr.io/rocker-org/devcontainer/r-ver:4.2
root ➜ / $ cat /home/rstudio/.gitconfig 
[credential]
    helper = cache
root ➜ / $ ls -la /home/rstudio
total 40
drwxr-x---  1 rstudio rstudio 4096 Nov  3 18:45 .
drwxr-xr-x  1 root    root    4096 Nov  3 16:59 ..
-rw-r--r--  1 rstudio rstudio  220 Jan  6  2022 .bash_logout
-rw-r--r--  1 rstudio rstudio 4910 Nov  3 17:02 .bashrc
drwxrwxr-x  3 rstudio rstudio 4096 Nov  3 17:07 .cache
-rw-rw-r--  1 rstudio rstudio   29 Nov  3 18:45 .gitconfig
drwxr-xr-x 12 rstudio rstudio 4096 Nov  3 17:02 .oh-my-zsh
-rw-r--r--  1 rstudio rstudio  807 Jan  6  2022 .profile
-rw-r--r--  1 rstudio rstudio 3897 Nov  3 17:02 .zshrc

Any thoughts?

eitsupi commented 1 year ago

It seems that the .gitconfig file is generated when installing some package only on the arm64 platform. Unfortunately I do not have the time to find out where it is coming from.

Sparrow0hawk commented 1 year ago

@eitsupi I'm happy to do some investigating and will report back.

Sparrow0hawk commented 1 year ago

Just to verify @eitsupi's observation adding --platform linux/amd64 on macOS ventura 13.0.1, Docker version 20.10.21, build baeda1f builds without the .gitconfig.

$ docker run --rm -it --platform linux/amd64 ghcr.io/rocker-org/devcontainer/r-ver:4.2 bash
Unable to find image 'ghcr.io/rocker-org/devcontainer/r-ver:4.2' locally
4.2: Pulling from rocker-org/devcontainer/r-ver
e96e057aae67: Pull complete 
bc51a8f1fa3b: Pull complete 
0abc830544e9: Pull complete 
d6e7a8cc8197: Pull complete 
2a88509eb7d5: Pull complete 
4e63186387da: Pull complete 
149496b167d6: Pull complete 
d6c485fa0a38: Pull complete 
84721cad5744: Pull complete 
1721288cca19: Pull complete 
2b3075e95f43: Pull complete 
Digest: sha256:21153dd4ca484a342776e4479c88e92b9775d6a680cd5fdc9d339904e475350a
Status: Downloaded newer image for ghcr.io/rocker-org/devcontainer/r-ver:4.2
root ➜ / $ ls -la /home/rstudio/
total 36
drwxr-x---  1 rstudio rstudio 4096 Nov  3 17:00 .
drwxr-xr-x  1 root    root    4096 Nov  3 16:59 ..
-rw-r--r--  1 rstudio rstudio  220 Jan  6  2022 .bash_logout
-rw-r--r--  1 rstudio rstudio 4910 Nov  3 16:59 .bashrc
drwxrwxr-x  3 rstudio rstudio 4096 Nov  3 17:00 .cache
drwxr-xr-x 12 rstudio rstudio 4096 Nov  3 16:59 .oh-my-zsh
-rw-r--r--  1 rstudio rstudio  807 Jan  6  2022 .profile
-rw-r--r--  1 rstudio rstudio 3897 Nov  3 16:59 .zshrc
eitsupi commented 1 year ago

The timestamp of the .gitconfig file indicates that file may have been generated during the installation of the R packages. https://github.com/rocker-org/devcontainer-images/actions/runs/3387665501/jobs/5628707079#step:7:5825

I tried installing several R packages on my local arm64 machine, but no .gitconfig files were generated. In other words, we are unable to address this issue as we are unable to reproduce it at this time.

eitsupi commented 1 year ago

In the first place, I think there is a discussion about whether it is appropriate not to copy .gitconfig on the host when .gitconfig exists in the container. microsoft/vscode-remote-release#7589 microsoft/vscode-remote-release#6810

eitsupi commented 1 year ago

.gitconfig was still present in the image built yesterday.

$ ls -la /home/rstudio/
total 40
drwxr-x---  1 rstudio rstudio 4096 Dec  9 18:10 .
drwxr-xr-x  1 root    root    4096 Dec  9 16:33 ..
-rw-r--r--  1 rstudio rstudio  220 Jan  6  2022 .bash_logout
-rw-r--r--  1 rstudio rstudio 4910 Dec  9 16:36 .bashrc
drwxrwxr-x  3 rstudio rstudio 4096 Dec  9 16:40 .cache
-rw-rw-r--  1 rstudio rstudio   29 Dec  9 18:10 .gitconfig
drwxr-xr-x 12 rstudio rstudio 4096 Dec  9 16:37 .oh-my-zsh
-rw-r--r--  1 rstudio rstudio  807 Jan  6  2022 .profile
-rw-r--r--  1 rstudio rstudio 3897 Dec  9 16:37 .zshrc

Checking the log for this timestamp, the following R packages are installed. So probably these packages are the cause.

https://github.com/rocker-org/devcontainer-images/actions/runs/3659083276/jobs/6184682938#step:7:5898

[2022-12-09T18:08:31.332Z] #30 5485.0 ℹ Building openssl 2.0.5

[2022-12-09T18:10:12.488Z] #30 5586.2 ✔ Built openssl 2.0.5 (1m 41s)

[2022-12-09T18:10:13.065Z] #30 5586.8 ✔ Installed openssl 2.0.5  (365ms)
#30 5586.9 ℹ Building credentials 1.3.2

[2022-12-09T18:10:28.396Z] #30 5602.1 ✔ Built credentials 1.3.2 (15s)

[2022-12-09T18:10:28.547Z] #30 5602.2 ℹ Building httr 1.4.4

[2022-12-09T18:11:07.737Z] #30 5641.6 ✔ Built httr 1.4.4 (39s)
eitsupi commented 1 year ago

I have confirmed that when I install the credentials package, .gitconfig is generated.

root ➜ / $ ls -la /home/rstudio/
total 40
drwxr-x---  1 rstudio rstudio 4096 Dec  9 18:10 .
drwxr-xr-x  1 root    root    4096 Dec  9 16:33 ..
-rw-r--r--  1 rstudio rstudio  220 Jan  6  2022 .bash_logout
-rw-r--r--  1 rstudio rstudio 4910 Dec  9 16:36 .bashrc
drwxrwxr-x  3 rstudio rstudio 4096 Dec  9 16:40 .cache
-rw-rw-r--  1 rstudio rstudio   29 Dec  9 18:10 .gitconfig
drwxr-xr-x 12 rstudio rstudio 4096 Dec  9 16:37 .oh-my-zsh
-rw-r--r--  1 rstudio rstudio  807 Jan  6  2022 .profile
-rw-r--r--  1 rstudio rstudio 3897 Dec  9 16:37 .zshrc
root ➜ / $ rm /home/rstudio/.gitconfig
root ➜ / $ su rstudio -c "R -q -e \"pak::pkg_remove('credentials')\""
> pak::pkg_remove('credentials')
>
>
root ➜ / $ su rstudio -c "R -q -e \"pak::pak(unlist(strsplit('credentials', ' ')))\""
> pak::pak(unlist(strsplit('credentials', ' ')))
✔ Loading metadata database ... done

→ Will install 1 package.
→ Will download 1 CRAN package (230.07 kB).
+ credentials   1.3.2 [bld][dl] (230.07 kB)
ℹ Getting 1 pkg (230.07 kB)
✔ Cached copy of credentials 1.3.2 (source) is the latest build
ℹ Building credentials 1.3.2
✔ Built credentials 1.3.2 (4.6s)
✔ Installed credentials 1.3.2  (176ms)
✔ 1 pkg + 5 deps: kept 5, added 1 [15.8s]
>
>
root ➜ / $ ls -la /home/rstudio/
total 52
drwxr-x---  1 rstudio rstudio 4096 Dec 10 06:20 .
drwxr-xr-x  1 root    root    4096 Dec  9 16:33 ..
-rw-r--r--  1 rstudio rstudio  220 Jan  6  2022 .bash_logout
-rw-r--r--  1 rstudio rstudio 4910 Dec  9 16:36 .bashrc
drwxrwxr-x  1 rstudio rstudio 4096 Dec  9 16:40 .cache
-rw-rw-r--  1 rstudio rstudio   29 Dec 10 06:20 .gitconfig
drwxr-xr-x 12 rstudio rstudio 4096 Dec  9 16:37 .oh-my-zsh
-rw-r--r--  1 rstudio rstudio  807 Jan  6  2022 .profile
-rw-r--r--  1 rstudio rstudio 3897 Dec  9 16:37 .zshrc

Edit: Create a new issue r-lib/credentials#25

eitsupi commented 1 year ago

I have updated the r-rig feature that is used for installing R packages on the image. (rocker-org/devcontainer-features#118) So I suppose this bug will be fixed the next build...

Sparrow0hawk commented 1 year ago

Thanks @eitsupi for sorting this much appreciated! Will have a test when the next builds have gone through.

eitsupi commented 1 year ago

I am manually pulling the trigger of the build workflow, but for now I am going to wait until devcontainers/features#326 is merged and common-utils version 2.0.0 is released.

eitsupi commented 1 year ago

Fixed by rocker-org/devcontainer-features#118

https://github.com/rocker-org/devcontainer-images/actions/runs/3717877591/jobs/6305657608#step:7:5820

However, there is another error in bashrc of the latest build... (devcontainers/features#342)

$ docker run --rm -it ghcr.io/rocker-org/devcontainer/r-ver:4.2 bash
Unable to find image 'ghcr.io/rocker-org/devcontainer/r-ver:4.2' locally
4.2: Pulling from rocker-org/devcontainer/r-ver
10175de2f0c4: Already exists
38ca03cb4341: Already exists
432758119fe9: Already exists
ad8696308fec: Pull complete
15287ae5115b: Pull complete
5c24efc2483b: Pull complete
19b2d76f30c0: Pull complete
1e2dab89175d: Pull complete
f3458fd2879c: Pull complete
eb16060a1a6b: Pull complete
a8db1a71d912: Pull complete
Digest: sha256:903a03e1b7224957ccd5c0739720edc004abce007cd894e0c47e05a23d3d0c9b
Status: Downloaded newer image for ghcr.io/rocker-org/devcontainer/r-ver:4.2
bash: /etc/bash.bashrc: line 100: syntax error: unexpected end of file
root ➜ / $ ls -la /home/rstudio/
total 36
drwxr-x---  1 rstudio rstudio 4096 Dec 17 03:40 .
drwxr-xr-x  1 root    root    4096 Dec 17 01:49 ..
-rw-r--r--  1 rstudio rstudio  220 Jan  6  2022 .bash_logout
-rw-r--r--  1 rstudio rstudio 5226 Dec 17 01:52 .bashrc
drwxrwxr-x  3 rstudio rstudio 4096 Dec 17 01:56 .cache
drwxr-xr-x 12 rstudio rstudio 4096 Dec 17 01:52 .oh-my-zsh
-rw-r--r--  1 rstudio rstudio  807 Dec 17 01:52 .profile
-rw-r--r--  1 rstudio rstudio 3903 Dec 17 01:52 .zshrc