You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-11
Original file line number
Diff line number
Diff line change
@@ -123,28 +123,30 @@ If you are using the `docker/build-push-action`, and would like to pass the SSH
123
123
default=${{ env.SSH_AUTH_SOCK }}
124
124
```
125
125
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
127
129
128
130
If you use one of:
129
131
* the `docker/build-push-action`
130
132
* manual `docker build`
131
133
* manual `docker compose build`
132
134
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.
134
136
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.
137
138
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).
141
142
142
143
Workflow:
144
+
143
145
```yml
144
146
- name: ssh-agent setup
145
147
...
146
148
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
148
150
run: |
149
151
mkdir root-config
150
152
cp -r ~/.gitconfig ~/.ssh root-config/
@@ -155,15 +157,16 @@ Workflow:
155
157
```
156
158
157
159
Dockerfile:
160
+
158
161
```Dockerfile
162
+
# Copy the two files in place and fix different path/locations inside the Docker image
159
163
COPY root-config /root/
160
164
RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config
161
165
```
162
166
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.
164
168
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.
167
170
168
171
### Cargo's (Rust) Private Dependencies on Windows
0 commit comments