8000 Explain how to use `docker/build-push-action` with deployment-key con… · webfactory/ssh-agent@b19b28d · GitHub
[go: up one dir, main page]

10000 Skip to content

Commit b19b28d

Browse files
authored
Explain how to use docker/build-push-action with deployment-key configs (#133)
This PR adds a recipe for using `docker/build-push-action` with multiple Deploy Keys (#78) to the docs.
1 parent 2c78a1c commit b19b28d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,28 @@ If you are using this action on container-based workflows, make sure the contain
114114

115115
If you are using the `docker/build-push-action`, and would like to pass the SSH key, you can do so by adding the following config to pass the socket file through:
116116

117+
```yml
118+
- name: Build and push
119+
id: docker_build
120+
uses: docker/build-push-action@v2
121+
with:
122+
ssh: |
123+
default=${{ env.SSH_AUTH_SOCK }}
117124
```
125+
126+
### Using the `docker/build-push-action` Action together with multiple Deploy Keys
127+
128+
If you use the `docker/build-push-action` 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.
129+
130+
This requires an additional step in the actions workflow and two additional lines in the Dockerfile.
131+
132+
Workflow:
133+
```yml
134+
- name: Prepare git and ssh config for build context
135+
run: |
136+
mkdir root-config
137+
cp -r ~/.gitconfig ~/.ssh root-config/
138+
118139
- name: Build and push
119140
id: docker_build
120141
uses: docker/build-push-action@v2
@@ -123,6 +144,15 @@ If you are using the `docker/build-push-action`, and would like to pass the SSH
123144
default=${{ env.SSH_AUTH_SOCK }}
124145
```
125146

147+
Dockerfile:
148+
```Dockerfile
149+
COPY root-config /root/
150+
RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config
151+
```
152+
153+
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.
154+
155+
126156
### Cargo's (Rust) Private Dependencies on Windows
127157

128158
If you are using private repositories in your dependencies like this:

0 commit comments

Comments
 (0)
0