joe
joe

Reputation: 9494

pip install -r requirements.txt in gitlab ci

I am now studying gitlab-ci by copying the simplest case. It has 2 simple steps. They are installation and test without any test case.

My problem:
After I added the SSH_PRIVATE_KEY to the project. pip still unable to install from github.

I had tried putting echo "$SSH_PRIVATE_KEY" to the file. It does show the value in the gitlab terminal.

gitlab-ci

before_script:
  - '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

test:
  tags:
    - poink
    - Elcolie
  script:
    - pip install -r requirements.txt
    - python manage.py test

Error:

Obtaining django-geoposition from [email protected]:philippbosch/django-geoposition.git@origin/django-1.11#egg=django-geoposition (from -r requirements.txt (line 7))
  Cloning [email protected]:philippbosch/django-geoposition.git (to origin/django-1.11) to ./src/django-geoposition
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Command "git clone -q [email protected]:philippbosch/django-geoposition.git /builds/sarit/poink/src/django-geoposition" failed with error code 128 in None
ERROR: Job failed: exit code 1

requirements.txt: I use pip-tools to do pip-compile it from requirements.in. Then I would like to now change anything the been compiled from it.

#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file requirements.txt requirements.in
#
-e [email protected]:philippbosch/django-geoposition.git@origin/django-1.11#egg=django-geoposition
-e [email protected]:django-money/django-money.git@master#egg=django-money
appnope==0.1.0            # via ipython
boto3==1.4.7              # via django-s3-folder-storage
botocore==1.7.47          # via boto3, s3transfer
certifi==2017.11.5        # via requests
chardet==3.0.4            # via requests
collectfast==0.5.2
decorator==4.1.2          # via ipython, traitlets
django-choices==1.6.0
django-cors-headers==2.1.0
django-countries==5.0
django-debug-toolbar==1.9.1
django-dirtyfields==1.3
django-environ==0.4.4
django-extensions==1.9.7
django-filter==1.1.0
django-guardian==1.4.9
django-reversion==2.0.10
django-s3-folder-storage==0.5
django-storages==1.6.5    # via collectfast, django-s3-folder-storage
django==1.11.7
djangorestframework-jwt==1.11.0
djangorestframework==3.7.3
docutils==0.14            # via botocore
freezegun==0.3.9
gevent==1.2.2
greenlet==0.4.12          # via gevent
gunicorn==19.7.1
idna==2.6                 # via requests
ipython-genutils==0.2.0   # via traitlets
ipython==6.2.1
jedi==0.11.0              # via ipython
jmespath==0.9.3           # via boto3, botocore
model-mommy==1.4.0
olefile==0.44             # via pillow
parso==0.1.0              # via jedi
pexpect==4.3.0            # via ipython
pickleshare==0.7.4        # via ipython
pillow==4.3.0
prompt-toolkit==1.0.15    # via ipython
psycopg2==2.7.3.2
ptyprocess==0.5.2         # via pexpect
py-moneyed==0.7.0
py==1.5.2                 # via pytest
pygments==2.2.0           # via ipython
pyjwt==1.5.3              # via djangorestframework-jwt
pytest-django==3.1.2
pytest==3.2.5             # via pytest-django
python-dateutil==2.6.1    # via botocore, freezegun
pytz==2017.3              # via django, django-dirtyfields
requests==2.18.4
rest-framework-generic-relations==1.1.0
s3transfer==0.1.11        # via boto3
simplegeneric==0.8.1      # via ipython
six==1.11.0               # via django-environ, django-extensions, django-guardian, freezegun, model-mommy, prompt-toolkit, python-dateutil, traitlets
sqlparse==0.2.4           # via django-debug-toolbar
traitlets==4.3.2          # via ipython
typing==3.6.2             # via django-extensions
urllib3==1.22             # via requests
wcwidth==0.1.7            # via prompt-toolkit
werkzeug==0.12.2

Upvotes: 0

Views: 10114

Answers (1)

joe
joe

Reputation: 9494

The document I saw is outdated. The workable version is this

before_script:
  - '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
  - ssh-keyscan github.com >> ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts
  - git config --global user.email "[email protected]"
  - git config --global user.name "sarit"

test:
  tags:
    - poink
    - Elcolie
  script:
  - pip install -r requirements.txt

Upvotes: 3

Related Questions