Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Created September 23, 2019 11:06
Show Gist options
  • Select an option

  • Save jonashackt/260f3fecc35bf1b67e382f1bb72658fa to your computer and use it in GitHub Desktop.

Select an option

Save jonashackt/260f3fecc35bf1b67e382f1bb72658fa to your computer and use it in GitHub Desktop.

Revisions

  1. jonashackt renamed this gist Sep 23, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jonashackt created this gist Sep 23, 2019.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Add the following key to the 'Deploy Keys' section in Settings/Repository of your GitLab repository
    # Dockerfile:
    FROM centos:7

    ARG SSH_KEY_GITLAB_DEPLOY_KEY

    RUN \
    ### ssh configuration, see https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
    # run ssh-agent inside build environment
    eval $(ssh-agent -s); \
    # add ssh-key from GitLab variable to ssh agent store incl. fixing line endings
    echo "${SSH_KEY_GITLAB_DEPLOY_KEY}" | tr -d '\r' | ssh-add -; \
    # create the SSH directory and give it the right permissions
    mkdir -p ~/.ssh; \
    # Allow access to gitlab.your.lan
    echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config; \
    chmod 700 ~/.ssh; \
    \
    git clone ssh://[email protected]:2222/yourgroup/yourrepository.git;

    # Run with docker build and include Deploy Key fully as build-arg
    docker build . --force-rm --build-arg SSH_KEY_GITLAB_DEPLOY_KEY="-----BEGIN OPENSSH PRIVATE KEY-----
    c8g6t5...."