I am trying to setup a test for an API which includes a MySQL Database.
version: 2.1
jobs:
linux:
docker:
- image: circleci/buildpack-deps:stretch
- image: swift:4.1
- image: circleci/mysql:5.7
environment:
MYSQL_HOST: 127.0.0.1
MYSQL_ROOT_PASSWORD: XXX
MYSQL_USER: XXX
MYSQL_PASSWORD: XXX
entrypoint: |
sh -c "
echo 'CREATE DATABASE IF NOT EXISTS xxx; CREATE DATABASE IF NOT EXISTS xxx;' > /docker-entrypoint-initdb.d/init.sql;
/usr/local/bin/docker-entrypoint.sh
"
command: |
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--skip-character-set-client-handshake
--general_log
--general_log_file=/var/log/mysql/queries.log
environment:
IMAGE_NAME: XXX/XXX
steps:
- checkout
- run:
name: Wait for db
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 240s
- run:
name: Compile code
working_directory: ./api
command: swift build
- run:
name: Run unit tests
working_directory: ./api
command: swift test
- run:
name: Compile code with optimizations
working_directory: ./api
command: swift build -c release
- setup_remote_docker
- run:
name: Build Docker Image
command: docker build -t $IMAGE_NAME:latest .
- run:
name: Push Docker Image
command: |
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$CIRCLE_SHA1
docker push $IMAGE_NAME:latest
docker push $IMAGE_NAME:$CIRCLE_SHA1
workflows:
version: 2
build-master:
jobs:
- linux:
filters:
branches:
only: master
Every time I run it, it fails waiting for the database with dockerize.
2019/05/29 13:34:42 Waiting for: tcp://127.0.0.1:3306
2019/05/29 13:34:42 Problem with dial: dial tcp 127.0.0.1:3306: connect: connection refused. Sleeping 1s
2019/05/29 13:34:43 Problem with dial: dial tcp 127.0.0.1:3306: connect: connection refused. Sleeping 1s
…
2019/05/29 13:38:42 Timeout after 4m0s waiting on dependencies to become available: [tcp://127.0.0.1:3306]
Exited with code 1
I have no clue why it is constantly failing.
Is there something I am missing?