4
respostas

"Unknown MySQL server host 'mysql'

Meu yml, onde adicionei as variaveis do mysql.

image: docker:19.03.0

stages:
- pre-build
- build
- test
- deploy

build-docker:
    services:
      - docker:19.03.0-dind
    variables:
        DOCKER_HOST: tcp://docker:2375
        DOCKER_DRIVER: overlay2
        DOCKER_TLS_CERTDIR: ""
        GIT_SSL_NO_VERIFY: "1"
    before_script:
      - docker info
      - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD

    stage: pre-build
    script: 
      - docker build -t todo-list-img .
      - docker tag todo-list-img azosnosredna/gitlab_todolist_img:latest
      - docker push azosnosredna/gitlab_todolist_img:latest

build-project:
    image: azosnosredna/gitlab_todolist_img:latest
    services:
      - docker:19.03.0-dind
      - mysql:5.7
    variables:
        MYSQL_USER: $DB_USER
        MYSQL_PASSWORD: $DB_PASSWORD
        MYSQL_DATABASE: $DB_DATABASE
        MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD

        DB_NAME: $DB_DATABASE
        DB_USER:  $DB_USER
        DB_PASSWORD: $DB_PASSWORD
        DB_HOST: 'mysql'
        DB_PORT: '3306'
        SECRET_KEY: $DB_SECRET_KEY

    stage: build
    image: azosnosredna/gitlab_todolist_img:latest
    tags:
      - executor-tarefas
    dependencies:
      - build-docker
    script:
      - python manage.py makemigrations
      - python manage.py migrate

test-project:
    image: azosnosredna/gitlab_todolist_img:latest
    stage: test
    services:
    - docker:19.03.0-dind
    - mysql:5.7
    variables:
        MYSQL_USER: $DB_USER
        MYSQL_PASSWORD: $DB_PASSWORD
        MYSQL_DATABASE: $DB_DATABASE
        MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD

        DB_NAME: $DB_DATABASE
        DB_USER:  $DB_USER
        DB_PASSWORD: $DB_PASSWORD
        DB_HOST: 'mysql'
        DB_PORT: '3306'
        SECRET_KEY: $DB_SECRET_KEY
    dependencies:
    - build-project
    tags:
    - executor-tarefas

    script:
    - python -m unittest setUp
4 respostas

Segue link do log do pipeline: Vi algo sobre faltar a senha de root... mas ta feito conforme a aula.

2020-10-15T22:17:21.390405608Z     You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

https://gist.github.com/anderson-soza/da795f9add7c0a2f8b0529b5f2c8e8de

O erro foi meu, adicionei o nome da variavel diferente do yml. $DB_ROOT_PASS

O erro "lookup docker on 10.0.2.3:53: no such host" reapareceu, sem explicação. O que fiz e aparentemente foi o que resolveu para a pipeline finalmente completar todas as etapas: parei o gitlab-runner, editei o config toml, startei o gitlab-runner. Removi o runner que tinha a mais e ficou apenas o que realmente estou usando.

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  environment = ["DOCKER_TLS_CERTDIR="]
  name = ""
  url = ""
  token = ""
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = ""
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    shm_size = 0

[[runners]]
  environment = ["DOCKER_TLS_CERTDIR="]
  name = "runner-bytebank"
  url = "https://gitlab.com/"
  token = "tGAL-YBx8zMmoUe-Mr99"
  executor = "docker"
    [runners.custom_build_dir]
    [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "azosnosredna/gitlab_todolist_img:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]

Olá Anderson, tudo bem? Que legal que você conseguiu resolver os problemas, e mais legal ainda que você compartilhou a solução aqui na comunidade! Continue assim e bons estudos!