From b19b28d091cde6811b86fbb6ef3a8322a40e4dc7 Mon Sep 17 00:00:00 2001 From: j-riebe <52535122+j-riebe@users.noreply.github.com> Date: Wed, 19 Oct 2022 13:32:32 +0200 Subject: [PATCH] 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. --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7924d98..63d86fd 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ If you are using this action on container-based workflows, make sure the contain 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: -``` +```yml - name: Build and push id: docker_build uses: docker/build-push-action@v2 @@ -123,6 +123,36 @@ If you are using the `docker/build-push-action`, and would like to pass the SSH default=${{ env.SSH_AUTH_SOCK }} ``` +### Using the `docker/build-push-action` Action together with multiple Deploy Keys + +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. + +This requires an additional step in the actions workflow and two additional lines in the Dockerfile. + +Workflow: +```yml + - name: Prepare git and ssh config for build context + run: | + mkdir root-config + cp -r ~/.gitconfig ~/.ssh root-config/ + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + ssh: | + default=${{ env.SSH_AUTH_SOCK }} +``` + +Dockerfile: +```Dockerfile +COPY root-config /root/ +RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config +``` + +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. + + ### Cargo's (Rust) Private Dependencies on Windows If you are using private repositories in your dependencies like this: