I am trying to clone a repo that has submodules in it. The main repo is cloning fine but when I do git submodule update --init --recursive in the dockerfile the submodules throws and error.
fatal: clone of '[email protected]:jkeys089/lua-resty-hmac.git' into submodule path '/tmp/third-party/lua-resty-hmac' failed Failed to clone 'third-party/lua-resty-hmac'. Retry scheduled Cloning into '/tmp/third-party/lua-resty-jwt'... load pubkey "/root/.ssh/id_rsa": invalid format Warning: Permanently added the RSA host key for IP address '140.82.118.3' to the list of known hosts. Load key "/root/.ssh/id_rsa": invalid format [email protected]: Permission denied (publickey). In the image I have this
# authorise ssh host RUN mkdir /root/.ssh/ \ && chmod 700 /root/.ssh \ && ssh-keyscan github.com > /root/.ssh/known_hosts # add key and set permission RUN echo "${SSH_PRIVATE_KEY}" >> /root/.ssh/id_rsa \ && echo "$ssh_pub_key" > /root/.ssh/id_rsa.pub \ && chmod 600 /root/.ssh/id_rsa.pub \ && chmod 600 /root/.ssh/id_rsa I have no control of the submodules. I am not sure if I can change from [email protected]to https to get submodules.
I even tried using the GITHUB_TOKEN route
# start up git and clone RUN git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/" \ && git clone https://github.com/GluuFederation/gluu-gateway.git /tmp \ && cd /tmp/ \ && git submodule update --init --recursive And below is the part of the build command. build --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)"
Please help out on this. It's very frustrating. :(
SSH_PRIVATE_KEYis the public key. Note that doing this will compromise your key pair, since anyone who gets the image can trivially extract it, and there are several other disadvantages of runninggitcommands inside the Dockerfile; I'd set this up (clone the repository, check out the specific branch I want to build, ...) on the host before runningdocker build.insteadOftrick to change[email protected]:...into an https URL, but see David Maze's comment.