简体   繁体   中英

Docker pulled image inside Gitlab CI/CD doesn't recognise django tests

Title says for itself. Everything works perfectly, except tests. After pulling and running test (test stage) service, it says Ran 0 tests in 0.000s , but i have some basic tests and they run perfectly on my system. Just can't quite figure out what is wrong. I have a docker-compose file like this:

version: '2'
services:
  postgres:
    image: "postgres"
    ports:
      - 5432:5432
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=solo
      - POSTGRES_DB=solo
      - POSTGRES_PASSWORD=solo
      - POSTGRES_HOST_AUTH_METHOD=trust
  web:
    image: $CI_REGISTRY:$CI_COMMIT_REF_NAME
    build: .
    environment:
      - SECRET_KEY
    command: bash -c "cd src && gunicorn solo.wsgi:application --bind 0.0.0.0:8000"
    volumes:
      - static:/app/static
    expose:
      - 8000
    depends_on:
      - postgres
    restart: always
  test:
    image: $CI_REGISTRY:$CI_COMMIT_REF_NAME
    command: bash -c "python /app/src/manage.py test"
    depends_on:
      - postgres
  nginx:
    build: ./nginx
    volumes:
      - static:/app/static
    ports:
      - 80:80
    depends_on:
      - web


volumes:
  static:
  postgres_data:

And.gitlab-ci.yml like this:

image: docker:latest
services:
    - docker:dind

stages:
    - build
    - test
    - deploy

before_script:
    - apk add --no-cache py-pip
    - pip install docker-compose==1.9.0
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY

build:
    stage: build
    script:
        - docker-compose build
        - docker-compose push

test:
    stage: test
    script:
        - docker-compose pull test
        - docker-compose run test

deploy:
    stage: deploy
    only:
        - master
        - cicddev
    before_script:
        - apk add --update alpine-sdk
        - apk add python3-dev libffi-dev libffi-dev libressl-dev
        - apk add --no-cache openssh-client py-pip bash rsync
        - pip install Fabric3==1.14.post1
        - eval $(ssh-agent -s)
        - bash -c 'echo "${DEPLOY_KEY}" | ssh-add -'
        - mkdir -p ~/.ssh
        - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    script:
        - fab -H ${DEPLOY_ADDRESS} deploy

Any thoughts or suggestions?

Found solution here Django test runner not finding tests . Django won't find test if you're trying to call test from parent folders. So I had to change command: bash -c "python /app/src/manage.py test" to command: bash -c "cd src && python manage.py test"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM