【问题标题】:Docker pulled image inside Gitlab CI/CD doesn't recognise django testsDocker 在 Gitlab CI/CD 中提取的图像无法识别 django 测试
【发布时间】:2020-10-19 17:16:51
【问题描述】:

标题不言自明。一切正常,除了测试。拉动并运行test(test stage) 服务后,它显示Ran 0 tests in 0.000s,但我有一些基本测试,它们在我的系统上完美运行。只是无法完全弄清楚出了什么问题。 我有一个像这样的 docker-compose 文件:

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:

还有 .gitlab-ci.yml 像这样:

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

有什么想法或建议吗?

【问题讨论】:

    标签: django docker gitlab-ci


    【解决方案1】:

    在这里找到解决方案Django test runner not finding tests。 如果您尝试从父文件夹调用test,Django 将找不到测试。所以我不得不把command: bash -c "python /app/src/manage.py test"改成command: bash -c "cd src && python manage.py test"

    【讨论】:

      猜你喜欢
      • 2018-08-23
      • 2022-08-10
      • 2021-01-15
      • 1970-01-01
      • 2020-08-09
      • 2021-03-21
      • 2021-10-04
      • 2019-09-30
      • 2021-05-03
      相关资源
      最近更新 更多