I’m running Gitlab via the Gitlab-Omnibus Helm Chart
I’m attempting to build a docker image. It is a Dart project that has git dependencies. I assume I’d get the same error if it was an npm project with git dependencies as well.
Here is my .gitlab-ci.yml:
image: gitlab/dind
variables:
REGISTRY: gitlab.company.com
GIT_SUBMODULE_STRATEGY: recursive
DOCKER_HOST: tcp://localhost:2375
DOCKER_DRIVER: overlay2
services:
- docker:dind
before_script:
# This stuff is required to git pull from git dependency project
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
types:
- analyze
- build
analyze:
type: analyze
image: google/dart:1.24.3
script:
- dart --version
- pub get
- dartanalyzer --fatal-hints --fatal-warnings bin/server.dart
build_image:
type: build
before_script:
# This stuff is required to git pull from git dependency project
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- docker info
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY
- docker build -t $REGISTRY/group/project.
# Push to gitlab registry
- docker push $REGISTRY/group/project
As you can see, I’m injecting the private ssh key as recommended here, which works for the analyze job, but doesn’t work for build_image. The error I get is:
Resolving dependencies...
Git error. Command: git clone --mirror git@gitlab.company.com:group/other-project.git /root/.pub-cache/git/cache/other-project-4b9580110672b03c6de9df76806507239de7a297
Cloning into bare repository '/root/.pub-cache/git/cache/other-project-4b9580110672b03c6de9df76806507239de7a297'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The command '/bin/sh -c pub get' returned a non-zero code: 1
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1
I’m not tied to any particular approach I’m trying here, just that I want to be able to pull from another git repo on the same server.