Passing files from Google Cloud Container Builder to Docker build task

前端 未结 3 1720
灰色年华
灰色年华 2021-02-06 07:17

Context

A Ruby on Rails application built with Container Builder destined for App Engine. We require bundler to be able to install dependencies from a p

相关标签:
3条回答
  • 2021-02-06 07:58

    Ok, I managed to do what was referenced in the answer and comments above. here's what I did. Note that I had my id_rsa and known_hosts file in the volume /root/.ssh, as the question author posted. I assume he got to his state by following this article: https://cloud.google.com/container-builder/docs/access-private-github-repos

    In my cloudbuild.yaml: After cloning my repo, but before the docker build, I added this step:

    - name: 'gcr.io/cloud-builders/git' entrypoint: 'bash' args: - '-c' - cp /root/.ssh/{id_rsa,known_hosts} . volumes: - name: 'ssh' path: /root/.ssh

    then, in the Dockerfile:

    COPY id_rsa /root/.ssh/id_rsa COPY known_hosts /root/.ssh/known_hosts RUN eval $(ssh-agent) && \ echo -e "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \ ssh-add /root/.ssh/id_rsa

    Note, I'm not worried about the keys living in my container, because I'm using multi-stage builds.

    0 讨论(0)
  • 2021-02-06 08:06

    I also had to deal with the same problem, instead of copying ssh keys in to Docker files and cleaning up I cloned the repo in to workspace as a cloud build step. Contents in workspace is persisted across builds steps and can be used indocker file during build.

    # Clone git repo.
    - name: 'gcr.io/cloud-builders/git'
      id: git-clone
      args:
      - clone
      - git@github.com:repo.git
      - workspace/repo-clone
      volumes:
      - name: 'ssh'
      path: /root/.ssh
    

    Then in docker file.

    COPY workspace/repo-name build/
    
    0 讨论(0)
  • 2021-02-06 08:07

    Dockerfile COPY can use multiple <src> resources, but the paths of files and directories will be interpreted as relative to the source of the context of the build.

    That is your current path where you execute the docker build . command.

    In your case, if /root/.ssh is mounted when the Dockerfile executes its step, a simple RUN cp /root/.ssh/... /destination/path would be enough.

    However, you cannot mount a volume at docker build time (see moby issue 14080), so check this solution: a multi-stage build can help.

    0 讨论(0)
提交回复
热议问题