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

Using git (with SSH) in workspace #2266

Closed
boumanb opened this issue Sep 6, 2019 · 4 comments
Closed

Using git (with SSH) in workspace #2266

boumanb opened this issue Sep 6, 2019 · 4 comments

Comments

@boumanb
Copy link

boumanb commented Sep 6, 2019

Info:

  • Docker version ($ docker --version): 19.03.0-rc2, build f97efcc
  • Laradock commit ($ git rev-parse HEAD): cb910c5
  • System info (Mac, PC, Linux): Windows 10 Pro
  • System info disto/version: Version 10.0.18362 Build 18362

Since I'm using bitbucket with SSH I'm looking for the best approach to get my SSH keys into the workspace container. Is there any documentation about this? (couldn't find it)

I already tried mounting my hosts ~/.ssh to /root/.ssh/ which results in having the right keys in the workspace. However, when using git commands git starts complaining about wrong file permissions (as expected) because my host machine (Windows) isn't aware of file permissions as in Linux.

Does someone have a working solution that we could add to the documentation?

@philno
Copy link

philno commented Sep 11, 2019

Isn't your project's code mounted to the workspace container with a volume anyways?
So you should be able to regularly pull your code from bitbucket on your Windows host. It will update inside the container as well.

If you absolutely have to pull from inside the workspace container for some reason, you can check these snippets that show how to set the correct permissions and add a SSH key to the agent: https://gist.github.com/grenade/6318301

@boumanb
Copy link
Author

boumanb commented Sep 12, 2019

Isn't your project's code mounted to the workspace container with a volume anyways?
Yes, it is. 😃

So you should be able to regularly pull your code from bitbucket on your Windows host. It will update inside the container as well.
I am able to do so. 😄

If you absolutely have to pull from inside the workspace container for some reason, you can check these snippets that show how to set the correct permissions and add a SSH key to the agent: https://gist.github.com/grenade/6318301
Yes, I absolutely want to. I am using VS Code with the new remote feature for docker containers. So basically my terminal in VS Code is a shell in the workspace container. I do not want to have another terminal running alongside my VS Code terminal just for Git purposes.

Thanks for the link you gave me. However, I do not want to generate new keys. I want to use the keypair of my Windows host.

So my question is, how to get my Windows host keypair into the workspace container properly?

@philno
Copy link

philno commented Sep 13, 2019

Yes, I absolutely want to. I am using VS Code with the new remote feature for docker containers. So basically my terminal in VS Code is a shell in the workspace container. I do not want to have another terminal running alongside my VS Code terminal just for Git purposes.

Okay, I see. That could be annoying. Just curious, does syncing git via the VS Code GUI work?

Thanks for the link you gave me. However, I do not want to generate new keys. I want to use the keypair of my Windows host.

So my question is, how to get my Windows host keypair into the workspace container properly?

I didn't link this gist for key generation purposes. There are three scripts. The first one is irrelevant for your case. The third one should help you to set permissions for SSH keys. You might need the second one to make sure git can use the key. This is supposed to prevent the wrong file permissions error you described.

Fortunately for you, it seems like there is a complete solution in the VS Code documentation: https://code.visualstudio.com/docs/remote/containers#_sharing-git-credentials-with-your-container

I am assuming you are using the Visual Studio Code Remote - Containers extension.

There are other ways to share the SSH keys of your host when using the SSH extension.
Finally, in case someone finds this who does not use VS code: See this question on stackoverflow for various other possible solutions.

Please let me know if it works.

@boumanb
Copy link
Author

boumanb commented Sep 14, 2019

Everything working now. Ended up using: https://code.visualstudio.com/docs/remote/containers#_using-ssh-keys

Thanks. I was kind of confused since there are many ways to do this. I've been using https://github.com/cytopia/devilbox too, and that project had a very different solution for this particular problem.

@boumanb boumanb closed this as completed Sep 14, 2019
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

No branches or pull requests

2 participants