dropbox1111 2019-03-18 22:10
浏览 477

Laravel | 使用gitlab ci部署和自动部署

i want to setup automatic deploy to my production server.

This is my log from gitlab ci ->

Running with gitlab-runner 11.9.0-rc2 (227934c0)
  on docker-auto-scale fa6cab46
Using Docker executor with image lorisleiva/laravel-docker:latest ...
Pulling docker image lorisleiva/laravel-docker:latest ...
Using docker image sha256:4bd5ecacba7b0f46950944f376647090071a70a7b1ffa0eacb492719bd476c6b for lorisleiva/laravel-docker:latest ...
Running on runner-fa6cab46-project-11286864-concurrent-0 via runner-fa6cab46-srm-1552945620-f480ce3e...
Initialized empty Git repository in /builds/Woblex/web/.git/
Fetching changes...
Created fresh repository.
From https://gitlab.com/Woblex/web
 * [new branch]      master     -> origin/master
Checking out ce51a64e as master...

Skipping Git submodules setup
Downloading artifacts for composer (179849020)...
Downloading artifacts from coordinator... ok        id=179849020 responseStatus=200 OK token=zy8-CGce
Downloading artifacts for npm (179849021)...
Downloading artifacts from coordinator... ok        id=179849021 responseStatus=200 OK token=NvUWyzkg
$ eval $(ssh-agent -s) # collapsed multi-line command
Agent pid 11
Identity added: (stdin) (git@gitlab.com)
$ find . -type f -not -path "./vendor/*" -exec chmod 664 {} \;     # collapsed multi-line command
$ whoami
root
$ php artisan deploy woblex.cz -s upload
✈︎ Deploying HEAD on woblex.cz with upload strategy
➤ Executing task deploy:prepare
✔ Ok
➤ Executing task deploy:lock
✔ Ok
➤ Executing task deploy:release
✔ Ok
➤ Executing task deploy:update_code
➤ Executing task deploy:failed
✔ Ok
➤ Executing task deploy:unlock
✔ Ok

In Client.php line 99:

  The command "cd /var/www/dev.woblex.cz && (/usr/bin/git clone   --recursive  
    git@gitlab.com:Woblex/web.git /var/www/dev.woblex.cz/releases/1 2>&1)" fa  
  iled.                                                                        

  Exit Code: 128 (Invalid exit argument)                                       

  Host Name: woblex.cz                                                         

  ================                                                             
  Warning: Identity file /home/gitlab/.ssh/id_rsa not accessible: No such fil  
  e or directory.                                                              


deploy [-p|--parallel] [-l|--limit LIMIT] [--no-hooks] [--log LOG] [--roles ROLES] [--hosts HOSTS] [-o|--option OPTION] [--] [<stage>]


In Process.php line 239:

  The command "vendor/bin/dep --file=vendor/lorisleiva/laravel-deployer/.buil  
  d/deploy.php deploy 'woblex.cz'" failed.                                     

  Exit Code: 128(Invalid exit argument)                                        

  Working directory: /builds/Woblex/web                                        

  Output:                                                                      
  ================                                                             
  ✈︎ Deploying HEAD on woblex.cz with upload strategy                          
  ➤ Executing task deploy:prepare                                              
  ✔ Ok                                                                         
  ➤ Executing task deploy:lock                                                 
  ✔ Ok                                                                         
  ➤ Executing task deploy:release                                              
  ✔ Ok                                                                         
  ➤ Executing task deploy:update_code                                          
  ➤ Executing task deploy:failed                                               
  ✔ Ok                                                                         
  ➤ Executing task deploy:unlock                                               
  ✔ Ok                                                                         


  Error Output:                                                                
  ================                                                             

  In Client.php line 99:                                                       


    The command "cd /var/www/dev.woblex.cz && (/usr/bin/git clone   --recursi  
  ve                                                                           
      git@gitlab.com:Woblex/web.git /var/www/dev.woblex.cz/releases/1 2>&1)"   
  fa                                                                           
    iled.                                                                      



    Exit Code: 128 (Invalid exit argument)                                     



    Host Name: woblex.cz                                                       



    ================                                                           

    Warning: Identity file /home/gitlab/.ssh/id_rsa not accessible: No such f  
  il                                                                           
    e or directory.                                                            




  deploy [-p|--parallel] [-l|--limit LIMIT] [--no-hooks] [--log LOG] [--roles  
   ROLES] [--hosts HOSTS] [-o|--option OPTION] [--] [<stage>]                  


ERROR: Job failed: exit code 1

I there is my deploy.php configuration ->

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default deployment strategy
    |--------------------------------------------------------------------------
    |
    | This option defines which deployment strategy to use by default on all
    | of your hosts. Laravel Deployer provides some strategies out-of-box
    | for you to choose from explained in detail in the documentation.
    |
    | Supported: 'basic', 'firstdeploy', 'local', 'pull'.
    |
    */

    'default' => 'basic',

    /*
    |--------------------------------------------------------------------------
    | Custom deployment strategies
    |--------------------------------------------------------------------------
    |
    | Here, you can easily set up new custom strategies as a list of tasks.
    | Any key of this array are supported in the `default` option above.
    | Any key matching Laravel Deployer's strategies overrides them.
    |
    */

    'strategies' => [
        //
    ],

    /*
    |--------------------------------------------------------------------------
    | Hooks
    |--------------------------------------------------------------------------
    |
    | Hooks let you customize your deployments conveniently by pushing tasks 
    | into strategic places of your deployment flow. Each of the official
    | strategies invoke hooks in different ways to implement their logic.
    |
    */

    'hooks' => [
        // Right before we start deploying.
        'start' => [
            //
        ],

        // Code and composer vendors are ready but nothing is built.
        'build' => [
            //
        ],

        // Deployment is done but not live yet (before symlink)
        'ready' => [
            'artisan:storage:link',
            'artisan:view:clear',
            'artisan:cache:clear',
            'artisan:config:cache',
            'artisan:migrate',
            'artisan:horizon:terminate',
        ],

        // Deployment is done and live
        'done' => [
            //
        ],

        // Deployment succeeded.
        'success' => [
            //
        ],

        // Deployment failed.
        'fail' => [
            //
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Deployment options
    |--------------------------------------------------------------------------
    |
    | Options follow a simple key/value structure and are used within tasks
    | to make them more configurable and reusable. You can use options to
    | configure existing tasks or to use within your own custom tasks.
    |
    */

    'options' => [
        'application' => env('APP_NAME', 'Laravel'),
        'repository' => 'git@gitlab.com:Woblex/web.git',
        'git_tty' => false,
    ],

    /*
    |--------------------------------------------------------------------------
    | Hosts
    |--------------------------------------------------------------------------
    |
    | Here, you can define any domain or subdomain you want to deploy to.
    | You can provide them with roles and stages to filter them during
    | deployment. Read more about how to configure them in the docs.
    |
    */

    'hosts' => [
        'woblex.cz' => [
            'deploy_path' => '/var/www/dev.woblex.cz',
            'user' => 'gitlab',
            'identityFile' => '/home/gitlab/.ssh/id_rsa',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Localhost
    |--------------------------------------------------------------------------
    |
    | This localhost option give you the ability to deploy directly on your
    | local machine, without needing any SSH connection. You can use the
    | same configurations used by hosts to configure your localhost.
    |
    */

    'localhost' => [
        //
    ],

    /*
    |--------------------------------------------------------------------------
    | Include additional Deployer recipes
    |--------------------------------------------------------------------------
    |
    | Here, you can add any third party recipes to provide additional tasks, 
    | options and strategies. Therefore, it also allows you to create and
    | include your own recipes to define more complex deployment flows.
    |
    */

    'include' => [
        //
    ],

    /*
    |--------------------------------------------------------------------------
    | Use a custom Deployer file
    |--------------------------------------------------------------------------
    |
    | If you know what you are doing and want to take complete control over
    | Deployer's file, you can provide its path here. Note that, without
    | this configuration file, the root's deployer file will be used.
    |
    */

    'custom_deployer_file' => false,

];

I think that there is a problem with user connected to my ubuntu server from laravel deployer, because i set in config the username to 'gitlab', but if deployer connect to ubuntu server with this user it can see a file /home/gitlab/.ssh/id_rsa. Have anybody someting, that can help me? Thanks a lot!

Edit: Here my gitlab-ci.yml

image: lorisleiva/laravel-docker:latest

.init_ssh: &init_ssh |
  eval $(ssh-agent -s)
  echo "$SSH_PRIVATE_KEY" | tr -d '' | ssh-add - > /dev/null
  mkdir -p ~/.ssh
  chmod 700 ~/.ssh
  [[ -f /.dockerenv ]] && echo -e "Host *
\tStrictHostKeyChecking no

" > ~/.ssh/config

# Replace the last line with the following lines if you'd rather
# leave StrictHostKeyChecking enabled (replace yourdomain.com):
#
#  ssh-keyscan yourdomain.com >> ~/.ssh/known_hosts
#  chmod 644 ~/.ssh/known_hosts

.change_file_permissions: &change_file_permissions |
  find . -type f -not -path "./vendor/*" -exec chmod 664 {} \;    
  find . -type d -not -path "./vendor/*" -exec chmod 775 {} \;

composer:
  stage: build
  cache:
    key: ${CI_COMMIT_REF_SLUG}-composer
    paths:
      - vendor/
  script:
      - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
      - cp .env.example .env
      - php artisan key:generate
  artifacts:
    expire_in: 1 month
    paths:
      - vendor/
      - .env

npm:
  stage: build
  cache:
    key: ${CI_COMMIT_REF_SLUG}-npm
    paths:
      - node_modules/
  script:
      - npm install
      - npm run production
  artifacts:
    expire_in: 1 month
    paths:
      - node_modules/
      - public/css/
      - public/js/

#codestyle:
#  stage: test
#  dependencies: []
#  script:
#    - phpcs --standard=PSR2 --extensions=php --ignore=app/Support/helpers.php app

phpunit:
  stage: test
  dependencies:
    - composer
  script:
    - phpunit --coverage-text --colors=never

staging:
  stage: deploy
  script:
    - *init_ssh
    - *change_file_permissions
    - whoami
    - php artisan deploy woblex.cz -s upload
  environment:
    name: staging
    url: http://www.dev.woblex.cz
  only:
    - master

production:
  stage: deploy
  script:
    - *init_ssh
    - *change_file_permissions
    - php artisan deploy new.woblex.cz -s upload
  environment:
    name: production
    url: https://www.new.woblex.cz
  when: manual
  only:
   - master
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建