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

[Devcontainer] move git setup to postStartCommand #40068

Merged
merged 1 commit into from Oct 15, 2023

Conversation

R0Wi
Copy link
Member

@R0Wi R0Wi commented Aug 27, 2023

Problem summary

If you create a new devcontainer (locally), you will find the following in the logs:

[5245 ms] 
Running the postCreateCommand from devcontainer.json...

[5246 ms] Start: Run in container: /bin/sh -c .devcontainer/setup.sh

# ...

[7822 ms] Start: Run in container: # Test for /home/devcontainer/.gitconfig and git
[7826 ms] /home/devcontainer/.gitconfig exists
[7827 ms] 
[7828 ms] Exit code 1

Like shown, the git config --global commands executed in setup.sh will create the file /home/devcontainer/.gitconfig which will prevent that the .gitconfig of the local user gets copied to the devcontainer. A similar issue is described here: devcontainers/cli#98.

If you for example execute git config --global user.name after the container has been created, you will see that the username is empty and not set to the local git user of the host system.

Fix

The fix here moves the git config --global commands to a later setup stage. The logs will now look like the following (see also microsoft/vscode-remote-release#4855 (comment)):

[5519 ms] 
Running the postCreateCommand from devcontainer.json...

[5520 ms] Start: Run in container: /bin/sh -c .devcontainer/setup.sh

# ...

[7960 ms] Start: Run in container: # Test for /home/devcontainer/.gitconfig and git
[7962 ms] 
[7962 ms] 
[7963 ms] Start: Run in container: # Copy /home/robin/.gitconfig to /home/devcontainer/.gitconfig
[7965 ms] 

# ...

[8418 ms] 
Running the postStartCommand from devcontainer.json...

[8419 ms] Start: Run in container: /bin/sh -c .devcontainer/postStart.sh

Now git config --global user.name outputs Robin Windey in my case.

Copying the local git settings into the container is usually necessary to execute git commit (and git signing).

@R0Wi R0Wi requested review from artonge and szaimen August 27, 2023 17:19
Copy link
Contributor

@kesselb kesselb left a comment

Choose a reason for hiding this comment

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

Thank you 👍

@szaimen szaimen added this to the Nextcloud 28 milestone Aug 28, 2023
@kesselb kesselb added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Aug 28, 2023
@R0Wi R0Wi force-pushed the devcontainer-fix-git-config branch from 1dae47f to ff45fbf Compare September 2, 2023 07:27
@R0Wi
Copy link
Member Author

R0Wi commented Sep 8, 2023

@kesselb I guess the CI failures are unrelated?

@kesselb
Copy link
Contributor

kesselb commented Sep 12, 2023

@kesselb I guess the CI failures are unrelated?

Most likely.

@susnux susnux force-pushed the devcontainer-fix-git-config branch from ff45fbf to f74a12c Compare October 11, 2023 00:07
@susnux
Copy link
Contributor

susnux commented Oct 11, 2023

@R0Wi would you mind to sign you commit so it passed the DCO check? :)
(simply run git commit -s --amend)

* postCreateCommand is executed too early
* If git config commands run in postCreate, a global .gitconfig will be created
* Copy of local .gitconfig will be skipped if .gitconfig already exists in container
* Move to later stage
* devcontainers/cli#98
* microsoft/vscode-remote-release#4855 (comment)

Signed-off-by: GitHub <noreply@github.com>
@R0Wi R0Wi force-pushed the devcontainer-fix-git-config branch from f74a12c to 9dd158b Compare October 13, 2023 16:19
@R0Wi
Copy link
Member Author

R0Wi commented Oct 13, 2023

@susnux done ✔️

@susnux
Copy link
Contributor

susnux commented Oct 15, 2023

Drone unrelated

@susnux susnux merged commit ca946e7 into master Oct 15, 2023
36 of 39 checks passed
@susnux susnux deleted the devcontainer-fix-git-config branch October 15, 2023 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish developer experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants