alpine-docker / git

A useful simple git container running in alpine linux, especially for tiny linux distro, such as RancherOS, which don't have package manager.
Apache License 2.0
155 stars 86 forks source link

Any good example how to add .ssh key from environment variable? #36

Closed Kostanos closed 3 years ago

Kostanos commented 3 years ago

Anyone could provide an easy example to mount .ssh/id_rsa from environment variable?

It is very useful if rsa key is coming from kubernetes secret file or in other way.

ozbillwang commented 3 years ago

this is very basic knowledge about ssh and docker, I would leave this to you and fix by yourself.

Issue is closed.

Kostanos commented 3 years ago

The same as with previous issue that I opened. The solution for this already exists, you just missing it in alpine/git image, and it would be great to have it integrated, without needing to run all this from inside of container.

At this moment, the only way to resolve this issue with this image is by running it inside container.

Something like this:

        - name: my-init
          image: alpine/git
          imagePullPolicy: IfNotPresent
          command: [ "/bin/sh", "-e", "-c" ]
          args:
            - mkdir -p /root/.ssh;
              echo "Generate /root/.ssh/known_hosts";
              touch /root/.ssh/known_hosts;
              ssh-keyscan -H ${HOSTNAME} >> ~/.ssh/known_hosts;
              echo "Create id_rsa";
              echo $DEPLOY_KEY | sed "s/\\\n/\n/g" > /root/.ssh/id_rsa;
              chmod 400 -R /root/.ssh;
              ls -ls /root/.ssh/;
              echo "Cloning Repository";
              git clone -b "{{BRANCH}}" --single-branch -- ${GIT_REPO} /data;
              ls -ls /data;
              echo "Done";

Absense of this and Host verification functionality in this image, makes this image practically useless, and you can use it only in some very specific scenarious.

But it is up to you just to close the topic instead of develop the solution.