Config CircleCI for mysql database

mysql
circle.yml

#1

I am unable to setup build for my laravel project with mysql db.


#2

I’m sorry to hear that.

(I guess you intended to show us your Circle config and any error messages you get - unfortunately my crystal ball has run out of batteries, so we’re just going to have to help the non-supernatural way).


#3

Can you share your config and any error messages that you get? Please take a look at this post for how to get help faster in the future.


#4
version: 2

jobs:
  build:
    docker:
      - image: circleci/php:7.1-node-browsers
        environment:
          MYSQL_HOST: 127.0.0.1
          MYSQL_DB: mate
          MYSQL_USER: root
          MYSQL_ALLOW_EMPTY_PASSWORD: true
          MYSQL_PASSWORD:
      - image: mysql:5.7
        command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --innodb-large-prefix=true --innodb-file-format=Barracuda
        environment:
          MYSQL_USER: root
          MYSQL_ALLOW_EMPTY_PASSWORD: true

    working_directory: ~/laravel

    steps:
      - checkout
      - run: sudo apt install -y libsqlite3-dev zlib1g-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo composer self-update
      - restore_cache:
          keys:
            - composer-v1-{{ checksum "composer.lock" }}
            - composer-v1-
      - run: composer install --dev --ignore-platform-reqs
      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor
      - run:
          name: Mysql database
          command: mysql  -h 127.0.0.1 -u root -e "create database mate;"
      - run: cp .env.travis .env
      - run: php artisan key:generate
      - run: php artisan migrate
      - run: mkdir -p build/logs
      - run: php vendor/bin/phpunit tests/ --coverage-clover build/logs/clover.xml
      - run: php vendor/bin/phpcbf --standard=ruleset.xml app/
      - run: php vendor/bin/phpcs --standard=ruleset.xml app/

It shows the error mysql not found and can you pls let me know how to write code for continuous deployment on DigitalOcean droplet.


#5

I’m guessing the answer is in the manual (see the bolded part):

It is possible to specify multiple images for your job. Specify multiple images if, for example, you need to use a database for your tests or for some other required service. In a multi-image configuration job, all steps are executed in the container created by the first image listed.

So, you are trying to run the mysql binary on the first container, when MySQL is installed only on the second container.

To solve this, add a new run line after checkout which does something like:

sudo apt install -y mysql-client

You only need the client here, rather than a full server.


#6

Thanks alot, It works and please help me in deployment on digitalocean droplet.


#7

Great!

That’s not a question, that’s a request for free private tuition :wink:

My answer is “no”, of course, but if you make a solid effort to try getting a CD working based on the excellent documentation, and then ask a specific and focussed question if you have exhausted every other avenue, then someone will be pleased to help.

Good luck!

Update

While the following advice was written for Stack Overflow, it is a a very worthwhile read, even if it is a bit hyperbolic: How much research effort is expected of Stack Overflow users? I think it is relevant to all volunteer-powered fora on the web.


#8