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

Apply host git config with ddev auth ssh #1459

Closed
mfrieling opened this issue Feb 15, 2019 · 5 comments
Closed

Apply host git config with ddev auth ssh #1459

mfrieling opened this issue Feb 15, 2019 · 5 comments
Labels
Prioritized We expect to do this in an upcoming release

Comments

@mfrieling
Copy link

Is your feature request related to a problem? Please describe.
ddev auth ssh is a really helpful feature. But commits created inside the container always have DDEV-Local User <nobody@example.com> as author. This is good as a default but doesn't make much sense in active project development.

Describe the solution you'd like
When ddev auth ssh is executed, check if the host OS has a global configuration for user.name and user.email (git config --global --get user.name, git config --global --get user.email) and set those values globally inside the container.

Describe alternatives you've considered
There are no good alternatives as the difficulty lies within fetching the host config and transporting them into the containers.

@rfay
Copy link
Member

rfay commented Feb 15, 2019

Related bash config ideas: #926 - We probably need to try for a more general approach that allows various home directory files to be configured into the web container.

@rfay rfay added the Prioritized We expect to do this in an upcoming release label Feb 15, 2019
@mfrieling
Copy link
Author

Related bash config ideas: #926 - We probably need to try for a more general approach that allows various home directory files to be configured into the web container.

But I'm not sure if #926 is a good solution for this, as the host gitconfig file might contain other configs which should not go into the container, especially for Windows hosts (e. g. different core.filemode settings on Windows and Linux)

@rfay
Copy link
Member

rfay commented Feb 15, 2019

Yeah, in #926 I was thinking about a special config that would be mounted as bash_profile or bashrc, not actually mount the exact config. bash configs have the exact same problem you mention.

@mbomb007
Copy link
Contributor

mbomb007 commented Mar 23, 2021

I didn't want to commit a .gitconfig file with a specific user's name and email configuration. I found the following suggestion on the In-container Configuration page:

If you use git inside the container, you may want to copy your ~/.gitconfig into ~/.ddev/homeadditions or the project's .ddev/homeadditions so that use of git inside the container will use your regular username and email, etc.

This still didn't solve the problem the way the OP mentioned, but it gave me an idea.

Now that I remembered the global DDEV config, I realized a great solution is to add a symlink from ~/.ddev/homeadditions/.gitconfig to ~/.gitconfig. I wasn't sure if symlinks would work for this, but they do! This solves the issue in the way the OP wanted without needed to hardcode a specific user's configuration or copy a file for each project.

ln -s ~/.gitconfig ~/.ddev/homeadditions/.gitconfig

@mfrieling
Copy link
Author

Thanks @mbomb007, I found a solution but already forgot this issue. That symlinks work is new for me and back when I created this issue the homeadditions feature didn't exists, so the only way would be an overridden Dockerfile which copies files into the images and that was sth. I don't want to do. But copying (or symlinking) files in the host file system into a place where DDEV can use them for a specific project is fine.

I created a script .ddev/commands/pre-start which copies some files into the homeadditions folder:

#!/bin/bash

AUTHFILE1=~/.composer/auth.json
AUTHFILE2=~/.config/composer/auth.json
AUTHDDEV=.ddev/homeadditions/.composer/auth.json
SSHFILE=~/.ssh/id_ed25519*
SSHDDEV=.ddev/homeadditions/.ssh
GITCONFIG=~/.gitconfig
GITCONFIGDDEV=.ddev/homeadditions/.gitconfig

if [[ -f "$AUTHFILE1" ]]; then
  mkdir -p .ddev/homeadditions/.composer
  cp $AUTHFILE1 $AUTHDDEV
  echo "Using $AUTHFILE1"
elif [[ -f "$AUTHFILE2" ]]; then
  mkdir -p .ddev/homeadditions/.composer
  cp $AUTHFILE2 $AUTHDDEV
  echo "Using $AUTHFILE2"
fi

mkdir -p $SSHDDEV
cp $SSHFILE $SSHDDEV/
echo "Using SSH key from host."

cp $GITCONFIG $GITCONFIGDDEV
if [[ -f ~/.git-completion.bash ]]; then
  cp ~/.git-completion.bash .ddev/homeadditions/
fi
if [[ -f ~/.git-prompt.sh ]]; then
  cp ~/.git-prompt.sh .ddev/homeadditions/
fi
cp ~/.bashrc .ddev/homeadditions/
echo "Using .gitconfig and Git completion from host."

In addition I create a .ddev/homeadditions/.gitignore which ensures none of these files can make it into git:

.bashrc
.composer/
.ssh/
.gitconfig
.git-completion.bash
.git-prompt.sh

and a .ddev/config.hooks.yaml which hooks up the pre-start script:

hooks:
  pre-start:
    - exec-host: ".ddev/commands/pre-start"

As you can see, I also copy the composer auth.json which in my case contains GitLab tokens for private GitLab servers used as well as the SSH key to use. This is defined via a variable because in general I use ED25519 keys but for one server I'm forced to use RSA keys. These are all files containing secrets or personalized data together with the .gitconfig file, the others are host specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prioritized We expect to do this in an upcoming release
Projects
None yet
Development

No branches or pull requests

3 participants