0
我嘗試在gitlab ci中運行我的django測試python manage.py test
。因此我正在使用一個泊塢窗圖像。泊塢窗圖像建立很好,但是當它運行在gitlab的測試中,我得到ImportError: No module named 'django'
和無法在Docker鏡像上導入Django GitLab CI
Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
見我.gitlab-ci.yml
image: registry.gitlab.com/app/core:latest
services:
- postgres:latest
stages:
- test
variables:
SECRET_KEY: test-secret
POSTGRES_DB: ...
POSTGRES_USER: ...
POSTGRES_PASSWORD: ...
python_tests:
stage: test
before_script:
- export DATABASE_NAME=...
- export DATABASE_USER=...
- export DATABASE_PASSWORD=...
- export DATABASE_HOST=postgres
- source /app/venv/bin/activate
script:
- python manage.py test
和Dockerfile
FROM ubuntu:16.04
RUN apt-get update -y -qq
RUN apt-get install -y -qq build-essential libffi-dev libpq-dev libfontconfig1
RUN apt-get install -y -qq python3 python3-dev python3-pip
RUN apt-get install -y -qq libpq-dev
RUN apt-get install -y -qq nodejs npm
WORKDIR /app
# pip
COPY requirements.txt /app
RUN pip3 install --upgrade pip
RUN pip3 install virtualenv
RUN virtualenv --no-site-packages venv
RUN . venv/bin/activate
RUN pip3 install -r /app/requirements.txt
# npm
RUN ln -s `which nodejs` /usr/bin/node
COPY web/vueapp/package.json /app
RUN npm install