簡體   English   中英

如何使用 mysql 和 php docker 容器創建 jenkins 管道

[英]How to create jenkins pipeline with mysql and php docker container

請幫助我,我嘗試在詹金斯中制作管道項目。 我需要 dmstr/php-yii2, mysql:5 容器來運行我的應用程序

node('lm.backend.test') {
            checkout scm
       docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw"'){ c ->
            docker.image('mysql:5').inside("--link ${c.id}:db") {
                sh 'service mysql start'
            }
            docker.image('dmstr/php-yii2').inside("--link ${c.id}:db") {
                 sh 'php -v'
                 sh 'mysql -v'

                 stage('Build') {
                     sh 'cd basic && composer dump-autoload && composer clear-cache && composer install'
                     }
                 stage('TEST API'){
                     sh 'cd basic && vendor/bin/codecept build && vendor/bin/codecept run'
                 }
            }
        }
        stage('Deploy'){
            echo 'Deploying....'
        }
    }

結果

+ docker run -d -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5
    Unable to find image 'mysql:5' locally
    5: Pulling from library/mysql
    85b1f47fba49: Pulling fs layer
    27dc53f13a11: Pulling fs layer
    095c8ae4182d: Pulling fs layer
    ...
    Status: Downloaded newer image for mysql:5
    ...
    + service mysql start
    2017-10-26T13:13:19.717210Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2017-10-26T13:13:20.596078Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2017-10-26T13:13:20.784780Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2017-10-26T13:13:20.867922Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7061064d-ba4f-11e7-8f0f-0242ac110003.
    2017-10-26T13:13:20.874019Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2017-10-26T13:13:20.884048Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    2017-10-26T13:13:22.427363Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
    2017-10-26T13:13:22.427401Z 1 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
    2017-10-26T13:13:22.427411Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
    2017-10-26T13:13:22.427428Z 1 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
    2017-10-26T13:13:22.427435Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
    2017-10-26T13:13:22.427445Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
    2017-10-26T13:13:22.427480Z 1 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
    2017-10-26T13:13:22.427490Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
    ...
    $ docker stop --time=1 b4a8a716f4aa142b142a458b7ef5b26a241b0afb8c0ad60440558e64a4f8393f
    $ docker rm -f b4a8a716f4aa142b142a458b7ef5b26a241b0afb8c0ad60440558e64a4f8393f
    [Pipeline] // withDockerContainer
    [Pipeline] sh
    [live-monitors-control_new-CALN2TMKEXYXFJOAARVVINY7KIIEDLY2MJOL4IZEPHIXNJTTWPXA] Running shell script
    + docker stop e59fc8bfc4d6a9214b90dbc7a0c8ba0915cf0f05b0799e36cbc986fe792d904d
    e59fc8bfc4d6a9214b90dbc7a0c8ba0915cf0f05b0799e36cbc986fe792d904d
    + docker rm -f e59fc8bfc4d6a9214b90dbc7a0c8ba0915cf0f05b0799e36cbc986fe792d904d
    e59fc8bfc4d6a9214b90dbc7a0c8ba0915cf0f05b0799e36cbc986fe792d904d
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    ERROR: script returned exit code -1
    Finished: FAILURE

如果您嘗試在 mysql 容器內運行 php 容器,您可以嘗試在 mysql 容器內掛載 docker sock。

 mysqlimage.inside('-v /var/run/docker.sock:/var/run/docker.sock')
    {
          phpimage.inside()
          {
            ..........
          }
    }

我從未嘗試過這個,但它可以工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM