Skip to content

Multiple deploy keys + docker build, ssh config missing #152

@danseely

Description

@danseely

I'm in the same boat raised in Issue 78, and later defined in the Using the docker/build-push-action Action together with multiple Deploy Keys section of the readme. I.e., I need multiple ssh keys to be used as deploy keys for multiple Github repos, in the context of docker build.

The only difference between that and my use-case is that I'm not using the build-push-action, but manually building & pushing. I don't think that difference is related to the problem I'm seeing, but I could be wrong. I'm passing the ssh agent socket into the docker build manually like so:

- name: Build Docker image
  run: |
    DOCKER_BUILDKIT=1 docker build --ssh default=${{ env.SSH_AUTH_SOCK }} --tag our-stuff/our-stuff:tag --file our_dockerfile .

To verify, I have all 4 separate ssh public keys installed in 4 of our private repos as deploy keys, and the corresponding private keys installed in our org as CI secrets. We're running on our self-hosted runner, and using a base image we've made with some of the tools we need pre-installed.

I have my ssh setup in the action in the way defined in the README:

...
runs-on: [self-hosted]
container: /our/container/path/here:tag
steps:
- uses: actions/checkout@v3
- uses: webfactory/ssh-agent@v0.7.0
    with:
    ssh-private-key: |
        ${{ secrets.GH_DEPLOY_KEY_REPO_ONE }}
        ${{ secrets.GH_DEPLOY_KEY_REPO_TWO }}
        ${{ secrets.GH_DEPLOY_KEY_REPO_THREE }}
        ${{ secrets.GH_DEPLOY_KEY_REPO_FOUR }}

- name: Prepare git and ssh config for build context
    run: |
    mkdir root-config
    cp -r ~/.gitconfig ~/.ssh root-config/
...

And I added the relevant lines to my dockerfile:

COPY root-config /root/
RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config

However, I get this error on the sed command:

sed: can't read /root/.ssh/config: No such file or directory

When I add this to the workflow after the above blocks:

- name: Confirm original ssh directory
    run: |
    ls ~/.ssh

- name: Confirm copied ssh directory
  run: |
    ls root-config/.ssh

... it only shows known_hosts being present in both directories. And when I do the same ls in the dockerfile, same thing.

I feel like I'm probably looking right at the problem, but I can't see it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions