Having trouble getting tests working with mysql


#1

I’m writing a Node.js app, connecting to mysql using the node-mysql package.
the install bcrypt is because when running circleci build locally it was importing the package with the wrong OS.

When my tests run I get

Error: connect ECONNREFUSED 127.0.0.1:3306

Locally i’m using a docker-compose file:

database:
  image: mysql:latest
  ports:
     - 3306:3306
  expose:
     - 3306
  volumes:
     - ./db/dev_schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro
  env_file: .env
  environment:
    - MYSQL_HOST
    - MYSQL_DATABASE
    - MYSQL_USER
    - MYSQL_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD

Which i’m launching as docker-compose up -d

This is my config.yml

version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:9.4
    environment:
      - MYSQL_HOST=localhost
      - MYSQL_DATABASE=dev
      - MYSQL_USER=uea
      - MYSQL_PASSWORD=password
      - MYSQL_RANDOM_ROOT_PASSWORD=yes

    working_directory: ~/repo

    steps:
      - checkout

      - run:
          name: Install Docker Compose
          command: |
            curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
            chmod +x ~/docker-compose
            sudo mv ~/docker-compose /usr/local/bin/docker-compose

      - setup_remote_docker

      - run:
          name: Get all dependencies
          command: |
            touch .env
            sudo docker-compose up -d
            npm install
            cd client
            npm install
            npm run build
            cd ..
            npm install bcrypt

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      # run tests!

      - run:
          name: Run front and back tests
          command: |
            yarn ci:test
            cd client
            yarn ci:test

#2

Readers would probably need to also see:

  • Your logs from the build (any steps you think are relevant)
  • Your Docker Compose logs

Would you also clarify if running the docker-compose up command works locally for you?


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.