Ainda não tem acesso? Estude com a gente! Matricule-se
Ainda não tem acesso? Estude com a gente! Matricule-se

Solucionado (ver solução)

Erro no build-project pois não sobe o mysql

Estou tendo erro no build-project pois não sobe o mysql.

Segue os logs.

Running with gitlab-runner 13.3.1 (738bbe5a)
  on runner-bytebank LH_xGgEh
Preparing the "docker" executor
00:41
Using Docker executor with image caiomartin/bytebank:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:66dc2d45749a48592f4348fb3d567bdd65c9dbd5402a413b6d169619e32f6bd2 for docker:dind ...
Starting service mysql:5.7 ...
Pulling docker image mysql:5.7 ...
Using docker image sha256:ef08065b0a302111b56966aa92c89fa0bacdfc537741cbca88a15b10f14332ca for mysql:5.7 ...
Waiting for services to be up and running...
*** WARNING: Service runner-lhxggeh-project-20990856-concurrent-0-cc9264963fa326dd-docker-0 probably didn't start properly.
Health check error:
start service container: Error response from daemon: Cannot link to a non running container: /runner-lhxggeh-project-20990856-concurrent-0-cc9264963fa326dd-docker-0 AS /runner-lhxggeh-project-20990856-concurrent-0-cc9264963fa326dd-docker-0-wait-for-service/service (docker.go:1264:0s)
5 respostas

Olá Caio, tudo bem? Você poderia colocar aqui no fórum o conteúdo do seu arquivo gitlab-ci.yml para gente poder verificar corretamente o que pode está acontecendo e tentar ti dar uma resposta mais exata sobre o problema.

Fico aguardando retorno!

solução

O build-docker executa normal, mais o job build-project que está dando erro.

image: docker:stable

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

build-docker:
  services:
    - docker:dind
  before_script:
    - docker info 
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin 
  stage: pre-build
  script:
  - docker build -t caiomartin/bytbank . 
  - docker tag caiomartin/bytbank caiomartin/bytebank:latest
  - docker push caiomartin/bytebank:latest


build-project:
  image: caiomartin/bytebank:latest
  services:
    - docker: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_PORT: $DB_PORT
    DB_HOST: $DB_HOST
    SECRET_KEY: $SECRET_KEY
  stage: build
  tags:
    - executor-tarefas
  dependencies:
    - build-docker
  script:
    - python manage.py makemigrations
    - python manage.py migrate

Caio, me parece que esse problema é o mesmo que foi relatado nessa issue do GitLab, onde uma das soluções apresentadas foi adicionar:

variables:
  DOCKER_TLS_CERTDIR: "/certs"

No arquivo .gitlab-ci.yml, porém ele indica que está usando a versão19.03, então tenta usar dessa forma:

image: docker:19.03.0

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

build-docker:
  services:
    - docker:19.03.0-dind
  before_script:
    - docker info 
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin 
  stage: pre-build
  script:
  - docker build -t caiomartin/bytbank . 
  - docker tag caiomartin/bytbank caiomartin/bytebank:latest
  - docker push caiomartin/bytebank:latest


build-project:
  image: caiomartin/bytebank: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_PORT: $DB_PORT
    DB_HOST: $DB_HOST
    SECRET_KEY: $SECRET_KEY
  stage: build
  tags:
    - executor-tarefas
  dependencies:
    - build-docker
  script:
    - python manage.py makemigrations
    - python manage.py migrate

E se não funciona, então adiciona o trecho:

variables:
  DOCKER_TLS_CERTDIR: "/certs"

E fala pra gente o resultado!

Infelizmente o erro persiste no com o build-project. Já não sei mais o que fazer para solucionar o problema. Percebi que esse curso esta tendo muitos problemas e deveria ser revisado. Pois gera um stress por parte do aluno que executa a mesma coisa que o instrutor e não funciona.

Running with gitlab-runner 13.3.1 (738bbe5a)
  on runner-bytebank fPzc5j65
Preparing the "docker" executor
Using Docker executor with image caiomartin/bytebank:latest ...
Starting service docker:19.03.0-dind ...
Pulling docker image docker:19.03.0-dind ...
Using docker image sha256:fd0c64832f7e46b63a180e6000dbba7ad7a63542c5764841cba73429ba74a39e for docker:19.03.0-dind ...
Starting service mysql:5.7 ...
Pulling docker image mysql:5.7 ...
Using docker image sha256:ef08065b0a302111b56966aa92c89fa0bacdfc537741cbca88a15b10f14332ca for mysql:5.7 ...
Waiting for services to be up and running...
*** WARNING: Service runner-fpzc5j65-project-20990856-concurrent-0-2d6e4d914e34c060-mysql-1 probably didn't start properly.
Health check error:
service "runner-fpzc5j65-project-20990856-concurrent-0-2d6e4d914e34c060-mysql-1-wait-for-service" timeout
Health check container logs:
Service container logs:
2020-09-15T13:39:01.361233174Z 2020-09-15 13:39:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started.
2020-09-15T13:39:01.556618289Z 2020-09-15 13:39:01+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-09-15T13:39:01.573688441Z 2020-09-15 13:39:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started.
2020-09-15T13:39:01.750424904Z 2020-09-15 13:39:01+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
2020-09-15T13:39:01.750440890Z     You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
*********
*** WARNING: Service runner-fpzc5j65-project-20990856-concurrent-0-2d6e4d914e34c060-docker-0 probably didn't start properly.
Health check error:
service "runner-fpzc5j65-project-20990856-concurrent-0-2d6e4d914e34c060-docker-0-wait-for-service" timeout
Health check container logs:
Service container logs:
2020-09-15T13:38:58.287821721Z Generating RSA private key, 4196 bit long modulus (2 primes)
2020-09-15T13:38:58.658114266Z ...........................................++++
2020-09-15T13:38:59.498213510Z .............................................................................................................++++
2020-09-15T13:38:59.498721511Z e is 65537 (0x010001)
2020-09-15T13:38:59.522217615Z Generating RSA private key, 4196 bit long modulus (2 primes)
2020-09-15T13:38:59.623644376Z ...........++++
2020-09-15T13:38:59.761905880Z ................++++
2020-09-15T13:38:59.762368988Z e is 65537 (0x010001)
2020-09-15T13:38:59.797978404Z Signature ok
2020-09-15T13:38:59.798010955Z subject=CN = docker:dind server
2020-09-15T13:38:59.798154482Z Getting CA Private Key
2020-09-15T13:38:59.817542960Z /certs/server/cert.pem: OK
2020-09-15T13:38:59.821434008Z Generating RSA private key, 4196 bit long modulus (2 primes)
2020-09-15T13:39:00.228630354Z ...................................................++++
2020-09-15T13:39:01.691861061Z ..................................................................................................................................................................................++++
2020-09-15T13:39:01.691885618Z e is 65537 (0x010001)
2020-09-15T13:39:01.748803723Z Signature ok
2020-09-15T13:39:01.748847482Z subject=CN = docker:dind client
2020-09-15T13:39:01.748957041Z Getting CA Private Key
2020-09-15T13:39:01.787176325Z /certs/client/cert.pem: OK
2020-09-15T13:39:01.850905203Z time="2020-09-15T13:39:01.850390577Z" level=info msg="Starting up"
2020-09-15T13:39:01.853905419Z time="2020-09-15T13:39:01.853789531Z" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found"
2020-09-15T13:39:01.854083924Z failed to load listeners: can't create unix socket /var/run/docker.sock: device or resource busy
*********
Pulling docker image caiomartin/bytebank:latest ...
Using docker image sha256:57d40a5cf316ed171f1e015c1a52b6fd0a20ff93fb27bf21f9d8820d95dfd458 for caiomartin/bytebank:latest ...
.
.
.
.
    super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'mysql' (115)")
ERROR: Job failed: exit code 1

Agora parece que o log foi diferente e mais claro sobre o erro. Está falando que o MySQL não foi iniciado corretamente:

Database is uninitialized and password option is not specified
2020-09-15T13:39:01.750440890Z     You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

E que não foi indicado as opções, e pelo que vi foi usado a versão 5.7.31, porém essa versão sai a exatamente seis dias atrás, ainda não tive a oportunidade de testar essa versão, então tenta fixar uma versão anterior como por exemplo a verão 5.7.27 no arquivo .gitlab-ci.yml, ficando da seguinte forma:

image: docker:19.03.0

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

build-docker:
  services:
    - docker:19.03.0-dind
  before_script:
    - docker info 
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin 
  stage: pre-build
  script:
  - docker build -t caiomartin/bytbank . 
  - docker tag caiomartin/bytbank caiomartin/bytebank:latest
  - docker push caiomartin/bytebank:latest


build-project:
  image: caiomartin/bytebank:latest
  services:
    - docker:19.03.0-dind
    - mysql:5.7.27
  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_PORT: $DB_PORT
    DB_HOST: $DB_HOST
    SECRET_KEY: $SECRET_KEY
  stage: build
  tags:
    - executor-tarefas
  dependencies:
    - build-docker
  script:
    - python manage.py makemigrations
    - python manage.py migrate

E fala pra gente o resultado!