Skip to content

Commit

Permalink
Merge pull request #3 from sam-mfb/docker-improvements
Browse files Browse the repository at this point in the history
Docker improvements
  • Loading branch information
sam-mfb authored Apr 21, 2024
2 parents 3fc01ee + 2671823 commit 3e93860
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ Notes:

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

### Using a Dockerfile

Here's a strategy to make this fairly easy to use with a Docker container built with a Dockerfile.

On the host, set a specific port that you will listen on by configuring the env variable `GIT_CREDENTIAL_FORWARDER_PORT`.

Add these lines in the Dockerfile

```
RUN curl -LO https://github.com/sam-mfb/git-credential-forwarder/releases/download/v[VERSION]/git-credential-forwarder.zip
RUN unzip git-credential-forwarder.zip
RUN git config --global credential.helper '!f(){ node ~/gcf-client.js $*; }; f'
ENV GIT_CREDENTIAL_FORWARDER_SERVER host.docker.internal:[PORT]
```
Of course, replace `[VERSION]` and `[PORT]` with the actual version number and port number (or use Docker's `ARG` command).

Note that you may need to add some other things to your git configuration. For example, to work with Azure DevOps OAuth2 authentication add:

```
RUN git config --global credential.https://dev.azure.com.useHttpPath true
```

## Using a File Socket

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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "git-credential-forwarder",
"version": "1.0.0",
"version": "1.0.1",
"description": "utilities for forwarding git credential helper commands to another git installation (e.g. container to host)",
"main": "dist/index.js",
"scripts": {
Expand Down
14 changes: 8 additions & 6 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const instructions = buildOutputWriter({
color: "yellow",
stream: process.stdout
})
const configOutput = buildOutputWriter({
color: "white",
stream: process.stdout
})
const errorOutput = buildOutputWriter({ color: "red", stream: process.stderr })

let serverType: ServerType = "tcp"
Expand Down Expand Up @@ -83,7 +87,7 @@ if (serverType === "tcp" && portEnv) {
case "tcp":
appOutput(`Starting TCP server listening on ${deps.host}:${deps.port}`)
instructions(`Run the following command in your docker container:\n`)
instructions(
configOutput(
` export ${EnvKey.SERVER}="${
deps.host === LOCALHOST ? DOCKER_HOST_IP : deps.host
}:${deps.port}"\n`
Expand All @@ -93,16 +97,14 @@ if (serverType === "tcp" && portEnv) {
instructions(
`Edit your git configuration file inside your docker container to call the git-credential-forwarder client script, for example:\n`
)
instructions(` [credential]`)
instructions(
` helper = "!f() { node ~/git-credential-forwarder/dist/client/index.js $*; }; f"`
)
configOutput(` [credential]`)
configOutput(` helper = "!f() { node ~/gcf-client.js $*; }; f"\n`)

try {
await credentialReceiver()
} catch (err) {
errorOutput(JSON.stringify(err))
}

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

0 comments on commit 3e93860

Please sign in to comment.