Skip to content

Commit 2b42283

Browse files
committed
Brush through the suggested changes with minor additions
1 parent 9556550 commit 2b42283

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Diff for: README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -123,28 +123,30 @@ If you are using the `docker/build-push-action`, and would like to pass the SSH
123123
default=${{ env.SSH_AUTH_SOCK }}
124124
```
125125

126-
### Using docker based workflows together with multiple Deploy Keys
126+
Make sure not to miss the next section, though.
127+
128+
### Forwarding the SSH agent into Docker build processes, together with multiple Deploy Keys
127129

128130
If you use one of:
129131
* the `docker/build-push-action`
130132
* manual `docker build`
131133
* manual `docker compose build`
132134

133-
and want to use multiple GitHub deploy keys, you need to copy the git and ssh configuration to the container during the build. Otherwise, the Docker build process would still not know how to handle multiple deploy keys. Even if the ssh agent was set up correctly on the runner.
135+
_and_ want to use multiple GitHub deploy keys, you need to copy the Git and SSH configuration to the container during the build. This is necessary so that Git can pick the right one from your deployment keys. This is necessary _in addition to_ forwarding the SSH agent socket into the build process.
134136

135-
This requires an additional step in the actions workflow **after** the ssh-agent step and **before** the docker build step.
136-
You also need two additional lines in the Dockerfile to actually copy the configs.
137+
This requires an additional step in the workflow file **after** the `ssh-agent` step and **before** the Docker build step. You also need two additional lines in the `Dockerfile` to actually copy the configs.
137138

138-
This does the following:
139-
* make the git and ssh configs accessible to Docker
140-
* copy the configs into the build stage
139+
The following example will:
140+
* collect the necessary Git and SSH configuration files in a directory that must be part of the Docker build context so that...
141+
* ... the files can be copied into the Docker image (or an intermediate build stage).
141142

142143
Workflow:
144+
143145
```yml
144146
- name: ssh-agent setup
145147
...
146148
147-
- name: Prepare git and ssh config for build context
149+
- name: Collect Git and SSH config files in a directory that is part of the Docker build context
148150
run: |
149151
mkdir root-config
150152
cp -r ~/.gitconfig ~/.ssh root-config/
@@ -155,15 +157,16 @@ Workflow:
155157
```
156158

157159
Dockerfile:
160+
158161
```Dockerfile
162+
# Copy the two files in place and fix different path/locations inside the Docker image
159163
COPY root-config /root/
160164
RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config
161165
```
162166

163-
Have in mind that the Dockerfile now contains customized git and ssh configurations. If you don't want that in your final image, use multi-stage builds.
167+
Keep in mind that the resulting Docker image now might contain these customized Git and SSH configuration files! Your private SSH keys are never written to files anywhere, just loaded into the SSH agent and forwarded into the container. The config files might, however, give away details about your build or development process and contain the names and URLs of your (private) repositories. You might want to use a multi-staged build to make sure these files do not end up in the final image.
164168

165-
If you still get the error message: `fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.` you most likely forgot one of the steps above.
166-
169+
If you still get the error message: `fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.`, you most likely forgot one of the steps above.
167170

168171
### Cargo's (Rust) Private Dependencies on Windows
169172

0 commit comments

Comments
 (0)