0

I have tried almost everything to get shippable working with my laravel app, but it's still not working and errors out when I try to call php artisan migrate My shippable.yml looks like this:

language: php

php:
  - 7.0

services:
  - mysql

addons:
  hosts:
    - example.org

before_script:
  - sudo apt-get update
  # - php -i
  - composer self-update -n
  - composer install  #downloads vendor
  - composer install --prefer-dist -n  # no idea
  - mysql -e "CREATE USER shippable@localhost identified by 'password';GRANT ALL ON *.* TO shippable@localhost IDENTIFIED BY 'password'; FLUSH PRIVILEGES;"  #creating shippable user
  - mysql -e "create database if not exists sample;" # create database
  - mysql -e "show databases;" # lists databases
  # - mysql -e "show variables like '%sock%';"
  - cp .env.shippable .env # creates .env file
  - php artisan key:generate # generates secure key
  - php artisan config:cache  # caches config (without it laravel throws error that secure key is not there)
  - cp ci/database.php resources/config/database.php
  - php artisan --verbose migrate --env=testing --force #creates database table
  - php artisan db:seed # seeds database with seeders'
script:
  - phpunit --log-junit shippable/testresults/junit.xml --coverage-xml shippable/codecoverage

My ci/database.php looks like this:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | PDO Fetch Style
    |--------------------------------------------------------------------------
    |
    | By default, database results will be returned as instances of the PHP
    | stdClass object; however, you may desire to retrieve records in an
    | array format for simplicity. Here you can tweak the fetch style.
    |
    */

    'fetch' => PDO::FETCH_CLASS,

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => storage_path('database.sqlite'),
            'prefix'   => '',
        ],

        'mysql' => [
            'write' => [
                'host' => env('DB_HOST', '127.0.0.1')
            ],
            'read' => [
                'host' => env('DB_HOST_SLAVE', '127.0.0.1')
            ],
            'dump_command_timeout'          => 60 * 5, // 5 minute timeout
            'dump_using_single_transaction' => true,
            'driver'                        => 'mysql',
            'unix_socket'                       => '/var/run/mysqld/mysqld.sock',
            'database'                      => env('DB_DATABASE', 'sample'),
            'username'                      => env('DB_USERNAME', 'shippable'),
            'password'                      => env('DB_PASSWORD', 'password'),
            'charset'                       => 'utf8',
            'collation'                     => 'utf8_unicode_ci',
            'prefix'                        => '',
            'strict'                        => false,
        ],

        'pgsql' => [
            'driver'   => 'pgsql',
            'host'     => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset'  => 'utf8',
            'prefix'   => '',
            'schema'   => 'public',
        ],

        'sqlsrv' => [
            'driver'   => 'sqlsrv',
            'host'     => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset'  => 'utf8',
            'prefix'   => '',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'cluster' => false,

        'default' => [
            'host'     => env('REDIS_HOST', '127.0.0.1'),
            'port'     => 6379,
            'database' => 0,
        ],

    ],

];

And finally my .env.shippable which I copy to .env looks like this:

APP_ENV=testing
APP_DEBUG=true
APP_KEY=key

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sample
DB_USERNAME=shippable
DB_PASSWORD=password

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
MAIL_DRIVER=log

When it reaches the step for php artisan migrate I keep on getting this error:

[PDOException]                                    
  SQLSTATE[HY000] [2002] No such file or directory  


Exception trace:
 () at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55
 PDO->__construct() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55
 Illuminate\Database\Connectors\Connector->createConnection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
 Illuminate\Database\Connectors\MySqlConnector->connect() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11857
 Illuminate\Database\Connectors\ConnectionFactory->createReadPdo() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11852
 Illuminate\Database\Connectors\ConnectionFactory->createReadWriteConnection() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11838
 Illuminate\Database\Connectors\ConnectionFactory->make() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11747
 Illuminate\Database\DatabaseManager->makeConnection() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11702
 Illuminate\Database\DatabaseManager->connection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:171
 Illuminate\Database\Migrations\DatabaseMigrationRepository->getConnection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:139
 Illuminate\Database\Migrations\DatabaseMigrationRepository->repositoryExists() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:404
 Illuminate\Database\Migrations\Migrator->repositoryExists() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:103
 Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase() at /root/src/github.com/fashionvalet/warehouse/vendor/orchestra/kernel/src/Database/Console/Migrations/MigrateCommand.php:40
 Orchestra\Database\Console\Migrations\MigrateCommand->fire() at n/a:n/a
 call_user_func_array() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:1257
 Illuminate\Container\Container->call() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Console/Command.php:169
 Illuminate\Console\Command->execute() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Console/Command.php:155
 Illuminate\Console\Command->run() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:794
 Symfony\Component\Console\Application->doRunCommand() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:186
 Symfony\Component\Console\Application->doRun() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107
 Illuminate\Foundation\Console\Kernel->handle() at /root/src/github.com/fashionvalet/warehouse/artisan:35

Can someone who have done this before please help ? At my wits end.

Muhammad Lukman Low
  • 8,177
  • 11
  • 44
  • 54

1 Answers1

0

Maybe try replacing the read and write hosts part in the ci/database.php config with just one host like the one below.

'host' => env('DB_HOST', 'localhost'),

Try removing unix_socket as well. Bear in mind too that when running tests (that is with phpunit) the configuration environment is set to testing (just in case you have tests that hit the database).

So below is the shippable.yml that worked for me. Note, however, that this is for Laravel 4.2 but I don't think there's much difference in this case.

language: php

php:
  - 5.6

env:
  - APP_ENV=testing

services:
  - mysql

build:
  ci:
    - sudo apt-get update
    - mkdir -p shippable/{testsresults,codecoverage}
    - mysql -e "CREATE DATABASE test;"
    - mysql -e "GRANT ALL ON test.* to test@localhost identified by 'password'; FLUSH PRIVILEGES;"
    - echo "memory_limit = 256M" >> $HOME/.phpenv/versions/$(phpenv version-name)/etc/php.ini
    - cp .env.example.php .env.testing.php
    - composer self-update -n
    - composer install
    - php artisan migrate
    - vendor/bin/phpunit --log-junit shippable/testresults/junit.xml --coverage-xml shippable/codecoverage

Hope this helps.