RoR cap 部署与 gitlab-runner 卡住并且没有触发通过响应
Posted
技术标签:
【中文标题】RoR cap 部署与 gitlab-runner 卡住并且没有触发通过响应【英文标题】:RoR cap deploy with gitlab-runner getting stuck and not triggering a pass response 【发布时间】:2019-07-15 17:00:04 【问题描述】:我有一个 gitlab-runner,我想用它来将我的 Ruby on Rails 应用程序部署到服务器上。我正在使用 Capistrano Gem 中的 cap deploy 功能部署到我的远程服务器。当我在本地运行 cap deploy 功能时,它可以正常工作并正确完成,但是当我在我的 gitlab-runner 中运行它时,它只会在到达某个点时坐下并旋转,并最终在运行 Publish 阶段时使我的 gitlab-runner 超时。 我想让它正常工作,所以如果有人有任何想法或可以提供指导,我将不胜感激。
.gitlab-ci.yml
before_script:
- ruby -v
- whoami
- which ruby
- bundle install --quiet
- RAILS_ENV=test bundle exec rake db:migrate --quiet
stages:
- citest
- security
- lint
- publish
- sendnotice
Citest:
stage: citest
script:
- rails t
Security:
stage: security
script:
- bundle exec brakeman -z -q
Lint:
stage: lint
script:
- bundle exec rubocop -a
- bundle exec rubocop -P
Publish:
stage: publish
script:
- eval `ssh-agent -s`
- ssh-add
- cap production deploy
SendNotice:
stage: sendnotice
script:
- ruby deploy_notice.rb
gitlab-runner - config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "cilinux"
url = "http://example.com/"
token = "ssssssssssssssssssss"
executor = "shell"
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
这是我的 gitlab-runner 控制台输出,它位于最后一行并旋转
Running with gitlab-runner 11.7.0 (8bb608ff)
on cilinux zzBcVZd6
Using Shell executor...
Running on proserver...
Cloning repository...
Cloning into '/home/ci/builds/zzBcVZd6/0/Library/csi'...
Checking out 78654903 as master...
Skipping Git submodules setup
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
$ whoami
ci
$ which ruby
/home/ci/.rvm/rubies/ruby-2.5.1/bin/ruby
$ bundle install --quiet
$ RAILS_ENV=test bundle exec rake db:migrate --quiet
$ eval `ssh-agent -s`
Agent pid 9096
$ ssh-add
Identity added: /home/ci/.ssh/id_rsa (/home/ci/.ssh/id_rsa)
$ cap production deploy
Skipping task `puma:restart'.
Capistrano tasks may only be invoked once. Since task `puma:restart' was previously invoked, invoke("puma:restart") at /home/ci/.rvm/gems/ruby-2.5.1/gems/capistrano3-puma-3.1.1/lib/capistrano/tasks/puma.rake:96 will be skipped.
If you really meant to run this task again, use invoke!("puma:restart")
THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.
https://github.com/capistrano/capistrano/issues/1686
INFO [62149be6] Running /usr/bin/env mkdir -p /tmp on 192.168.4.68
INFO [17c17043] Finished in 0.039 seconds with exit status 0 (successful).
INFO Uploading /tmp/git-ssh-CSI-production-ci.sh 100.0%
INFO [2ea27bf0] Running /usr/bin/env chmod 700 /tmp/git-ssh-CSI-production-ci.sh on 192.168.4.68
INFO [ec4b6bc5] Finished in 0.044 seconds with exit status 0 (successful).
INFO [d0d40773] Running /usr/bin/env git ls-remote git@example.com:Library/csi.git HEAD on 192.168.4.68
INFO [1c63f5ce] Finished in 5.555 seconds with exit status 0 (successful).
INFO [0c2cdf20] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/shared /home/deploy/apps/CSI/releases on 192.168.4.68
INFO [ec964bdd] Finished in 0.010 seconds with exit status 0 (successful).
INFO [0ae11325] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/shared/public/assets on 192.168.4.68
INFO [d9121d4f] Finished in 0.047 seconds with exit status 0 (successful).
INFO [8806e1ba] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/shared/config on 192.168.4.68
INFO [f3e1f3c4] Finished in 0.046 seconds with exit status 0 (successful).
INFO The repository mirror is at /home/deploy/apps/CSI/repo
INFO [40d9a02e] Running /usr/bin/env git remote set-url origin git@examplecom:mydomain/csi.git on 192.168.4.68
INFO [8a0a2d6d] Finished in 0.047 seconds with exit status 0 (successful).
INFO [4b634e41] Running /usr/bin/env git remote update --prune on 192.168.4.68
INFO [0efa9ecf] Finished in 5.588 seconds with exit status 0 (successful).
INFO [7cf384f1] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659 on 192.168.4.68
INFO [089f6fd2] Finished in 0.045 seconds with exit status 0 (successful).
INFO [79e639ea] Running /usr/bin/env git archive master | /usr/bin/env tar -x -f - -C /home/deploy/apps/CSI/releases/20190219192659 on 192.168.4.68
INFO [2e47c81b] Finished in 0.060 seconds with exit status 0 (successful).
INFO [132ffc7e] Running /usr/bin/env echo "78654903778db4079706dc5c990292c11fc3bfd6" > REVISION on 192.168.4.68
INFO [e9a299c4] Finished in 0.045 seconds with exit status 0 (successful).
INFO [61aebbb2] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659/config on 192.168.4.68
INFO [c32f803c] Finished in 0.047 seconds with exit status 0 (successful).
INFO [5de3f8d7] Running /usr/bin/env ln -s /home/deploy/apps/CSI/shared/config/master.key /home/deploy/apps/CSI/releases/20190219192659/config/master.key on 192.168.4.68
INFO [fd68c3e6] Finished in 0.044 seconds with exit status 0 (successful).
INFO [ae83c25d] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659/public on 192.168.4.68
INFO [219cde3c] Finished in 0.043 seconds with exit status 0 (successful).
INFO [8daea977] Running /usr/bin/env ln -s /home/deploy/apps/CSI/shared/public/assets /home/deploy/apps/CSI/releases/20190219192659/public/assets on 192.168.4.68
INFO [776bd6d9] Finished in 0.045 seconds with exit status 0 (successful).
INFO [9b6d224d] Running ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/CSI/shared/bundle --jobs 4 --without development test --deployment --quiet on 192.168.4.68
INFO [a7a6eab9] Finished in 12.598 seconds with exit status 0 (successful).
INFO [aa1ce450] Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on 192.168.4.68
INFO [361e893b] Finished in 26.688 seconds with exit status 0 (successful).
INFO [df357b56] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659/assets_manifest_backup on 192.168.4.68
INFO [4b7c3340] Finished in 0.048 seconds with exit status 0 (successful).
INFO [a7d45495] Running /usr/bin/env cp /home/deploy/apps/CSI/releases/20190219192659/public/assets/.sprockets-manifest-6c09bafc512e6d668d8d88812378e77c.json /home/deploy/apps/CSI/releases/20190219192659/assets_manifest_backup on 192.168.4.68
INFO [b6ebf727] Finished in 0.047 seconds with exit status 0 (successful).
INFO [deploy:migrate] Run `rake db:migrate`
INFO [5e0d430c] Running ~/.rvm/bin/rvm default do bundle exec rake db:migrate on 192.168.4.68
INFO [64374921] Finished in 7.839 seconds with exit status 0 (successful).
INFO [3e852c97] Running /usr/bin/env ln -s /home/deploy/apps/CSI/releases/20190219192659 /home/deploy/apps/CSI/releases/current on 192.168.4.68
INFO [10e08783] Finished in 0.048 seconds with exit status 0 (successful).
INFO [36c88135] Running /usr/bin/env mv /home/deploy/apps/CSI/releases/current /home/deploy/apps/CSI on 192.168.4.68
INFO [0408953b] Finished in 0.046 seconds with exit status 0 (successful).
INFO Keeping 3 of 4 deployed releases on 192.168.4.68
INFO [44ecd2da] Running /usr/bin/env rm -rf /home/deploy/apps/CSI/releases/20190219173006 on 192.168.4.68
INFO [baa3970a] Finished in 0.149 seconds with exit status 0 (successful).
INFO [b90baafa] Running ~/.rvm/bin/rvm default do bundle exec pumactl -S /home/deploy/apps/CSI/shared/tmp/pids/puma.state -F /home/deploy/apps/CSI/shared/puma.rb restart on 192.168.4.68
INFO [bcbdb282] Finished in 1.102 seconds with exit status 0 (successful).
INFO [da13ee51] Running /usr/bin/env echo "Branch master (at 78654903778db4079706dc5c990292c11fc3bfd6) deployed as release 20190219192659 by ci" >> /home/deploy/apps/CSI/revisions.log on 192.168.4.68
INFO [6a780fb0] Finished in 0.046 seconds with exit status 0 (successful).
//SITS AND SPINS HERE
cap deploy.rb
# frozen_string_literal: true
server '192.168.4.68', roles: %i[web app db], primary: true
set :repo_url, 'git@codelib.pennunited.com:PennUnited_Code_Library/csi.git'
set :application, 'CSI'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 4
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#fetch(:user)/apps/#fetch(:application)"
set :puma_bind, "unix://#shared_path/tmp/sockets/#fetch(:application)-puma.sock"
set :puma_state, "#shared_path/tmp/pids/puma.state"
set :puma_pid, "#shared_path/tmp/pids/puma.pid"
set :puma_access_log, "#release_path/log/puma.error.log"
set :puma_error_log, "#release_path/log/puma.access.log"
set :ssh_options, forward_agent: true, user: fetch(:user), keys: %w[~/.ssh/id_rsa.pub], keepalive: true
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to true if using ActiveRecord
## Defaults:
set :branch, :master
set :format, :pretty
set :log_level, :info
set :keep_releases, 3
## Linked Files & Directories (Default None):
set :linked_files, %w[config/master.key]
# set :linked_dirs, %wbin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #shared_path/tmp/sockets -p"
execute "mkdir #shared_path/tmp/pids -p"
end
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
在 :start, :make_dirs 之前 结束
【问题讨论】:
【参考方案1】:在 cap 生产部署后删除添加到 ssh-agent (ssh-agent - k) 的密钥帮助我,作业停止挂起
【讨论】:
以上是关于RoR cap 部署与 gitlab-runner 卡住并且没有触发通过响应的主要内容,如果未能解决你的问题,请参考以下文章