0

我已经尝试了几乎所有的方法来让我的 laravel 应用程序可交付使用,但是当我尝试调用php artisan migrate我的shippable.yml外观时它仍然无法正常工作并且出现错误,如下所示:

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

我的ci/database.php样子是这样的:

<?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,
        ],

    ],

];

最后我.env.shippable复制到的我的.env看起来像这样:

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

当它到达php artisan migrate我不断收到此错误的步骤时:

[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

以前做过这件事的人可以帮忙吗?在我的智慧结束。

4

1 回答 1

0

也许尝试用下面的一个替换配置中的readwrite主机部分。ci/database.phphost

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

尝试删除unix_socket。还要记住,在运行测试时(即使用phpunit),配置环境设置为testing(以防万一您有命中数据库的测试)。

所以下面是shippable.yml对我有用的。但是请注意,这是针对 Laravel 4.2 的,但我认为在这种情况下没有太大区别。

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

希望这可以帮助。

于 2017-05-20T17:59:28.683 回答