Skip to content

Commit 3e93860

Browse files
authored
Merge pull request #3 from sam-mfb/docker-improvements
Docker improvements
2 parents 3fc01ee + 2671823 commit 3e93860

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ Notes:
4141

4242
- You can turn on more verbose debugging information by setting the environmental variable `GIT_CREDENTIAL_FORWARDER_DEBUG` to `true`
4343

44+
### Using a Dockerfile
45+
46+
Here's a strategy to make this fairly easy to use with a Docker container built with a Dockerfile.
47+
48+
On the host, set a specific port that you will listen on by configuring the env variable `GIT_CREDENTIAL_FORWARDER_PORT`.
49+
50+
Add these lines in the Dockerfile
51+
52+
```
53+
RUN curl -LO https://github.com/sam-mfb/git-credential-forwarder/releases/download/v[VERSION]/git-credential-forwarder.zip
54+
RUN unzip git-credential-forwarder.zip
55+
RUN git config --global credential.helper '!f(){ node ~/gcf-client.js $*; }; f'
56+
ENV GIT_CREDENTIAL_FORWARDER_SERVER host.docker.internal:[PORT]
57+
```
58+
Of course, replace `[VERSION]` and `[PORT]` with the actual version number and port number (or use Docker's `ARG` command).
59+
60+
Note that you may need to add some other things to your git configuration. For example, to work with Azure DevOps OAuth2 authentication add:
61+
62+
```
63+
RUN git config --global credential.https://dev.azure.com.useHttpPath true
64+
```
65+
4466
## Using a File Socket
4567

4668
By default the server uses a tcp server listening on `localhost`. You can tell it to use a file socket instead of tcp by setting the environmental variable `GIT_CREDENTIAL_FORWARDER_SOCKET` to the location you want the socket created. You must have permission to create a socket at that location.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-credential-forwarder",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "utilities for forwarding git credential helper commands to another git installation (e.g. container to host)",
55
"main": "dist/index.js",
66
"scripts": {

src/server/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const instructions = buildOutputWriter({
1414
color: "yellow",
1515
stream: process.stdout
1616
})
17+
const configOutput = buildOutputWriter({
18+
color: "white",
19+
stream: process.stdout
20+
})
1721
const errorOutput = buildOutputWriter({ color: "red", stream: process.stderr })
1822

1923
let serverType: ServerType = "tcp"
@@ -83,7 +87,7 @@ if (serverType === "tcp" && portEnv) {
8387
case "tcp":
8488
appOutput(`Starting TCP server listening on ${deps.host}:${deps.port}`)
8589
instructions(`Run the following command in your docker container:\n`)
86-
instructions(
90+
configOutput(
8791
` export ${EnvKey.SERVER}="${
8892
deps.host === LOCALHOST ? DOCKER_HOST_IP : deps.host
8993
}:${deps.port}"\n`
@@ -93,16 +97,14 @@ if (serverType === "tcp" && portEnv) {
9397
instructions(
9498
`Edit your git configuration file inside your docker container to call the git-credential-forwarder client script, for example:\n`
9599
)
96-
instructions(` [credential]`)
97-
instructions(
98-
` helper = "!f() { node ~/git-credential-forwarder/dist/client/index.js $*; }; f"`
99-
)
100+
configOutput(` [credential]`)
101+
configOutput(` helper = "!f() { node ~/gcf-client.js $*; }; f"\n`)
100102

101103
try {
102104
await credentialReceiver()
103105
} catch (err) {
104106
errorOutput(JSON.stringify(err))
105107
}
106108

107-
appOutput("Press ctrl+c to stop server.")
109+
appOutput("Ctrl+c to stop server.")
108110
})().catch(err => errorOutput(JSON.stringify(err)))

0 commit comments

Comments
 (0)