[英]Bitbucket Pipelines Inappropriate ioctl for device error using Capistrano
我有一個帶有Rails應用程序的DigitalOcean Droplet,我希望通過Pipelines和Capistrano自動部署。
這是我的Capfile:
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
# require "capistrano/rvm"
# require "capistrano/rbenv"
# require "capistrano/chruby"
# require "capistrano/bundler"
require "capistrano/apache/systemd"
require "capistrano/rails"
# require "capistrano/rails/migrations"
# require "capistrano/passenger"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
deploy.rb:
# config valid for current version and patch releases of Capistrano
lock "~> 3.11.0"
server "xx.xx.xx.xx", port: 22, roles: [:web, :app, :db], primary: true
set :application, "myapp"
set :repo_url, "git@bitbucket.org:user/repo.git"
set :user, "deployuser"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "customdir"
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# append :linked_files, "config/database.yml"
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases, 5
# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
#
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 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'apache:reload'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :restart
after :rollback, :restart
end
到位桶,pipelines.yml:
image: ruby:2.5.3
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- apt-get update -y
- apt-get install -y build-essential git-core curl nodejs default-libmysqlclient-dev ssh
- gem install bundler
- bundle install
- bundle exec cap production deploy
我在Settings - > Pipelines - > SSH keys下創建了一個SSH,並將其添加到deployuser
指定的deployuser下的deployuser
的authorized_keys文件中。 當我運行管道時,這是日志跟蹤:
+ bundle exec cap production deploy
00:00 git:wrapper
01 mkdir -p /tmp
#<Thread:0x000055ed4cf70528@/usr/local/bundle/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
/usr/local/bundle/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing on host xx.xx.xx.xx: Inappropriate ioctl for device (SSHKit::Runner::ExecuteError)
from /usr/local/bundle/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xx.xx.xx.xx: Inappropriate ioctl for device
Caused by:
Errno::ENOTTY: Inappropriate ioctl for device
Tasks: TOP => deploy:check => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host xx.xx.xx.xx: Inappropriate ioctl for device
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
# Logfile created on 2019-05-30 00:35:51 +0000 by logger.rb/61378
INFO ---------------------------------------------------------------------------
INFO START 2019-05-30 00:35:51 +0000 cap production deploy
INFO ---------------------------------------------------------------------------
INFO [5548bb68] Running /usr/bin/env mkdir -p /tmp on 142.93.227.140
DEBUG [5548bb68] Command: /usr/bin/env mkdir -p /tmp
@xx.xx.xx.xx's password:
我不確定最后一行是否與正在發生的事情有關。 我打算使部署無密碼且盡可能簡單。
我嘗試將ssh -T deployUser@xx.xx.xx.xx
添加到腳本步驟中。 顯然沒有錯:
ssh -T deployUser@xx.xx.xx.xx
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-50-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Fri May 31 02:14:16 UTC 2019
System load: 0.01 Processes: 140
Usage of /: 19.7% of 24.06GB Users logged in: 1
Memory usage: 74% IP address for eth0: xx.xx.xx.xx
Swap usage: 0%
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
1 package can be updated.
0 updates are security updates.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
回到基礎。 我在Bitbucket上關閉了Pipelines,並嘗試在指向遠程服務器的同時在本地運行cap production deploy
。 事實證明它確實需要一個密碼,當它不應該,並且它也沒有與正確的用戶SSHing,所以a)只添加必要的密鑰到deployUser的authorized_keys
文件b)修改deploy.rb
像這樣:
lock "~> 3.11.0"
set :user, "deployUser" # Notice that set user was moved here so it can be fetched later
server "xx.xx.xx.xx", user: fetch(:user), port: 22, roles: [:app], primary: true
set :application, "my_app"
set :repo_url, "my_git_repo"
set :rvm_type, :system
set :rvm_ruby_version, '2.5.3'
set :bundle_jobs, 2 # Small modification so it doesn't eat up the Droplet's memory
我得到了另一個錯誤,但這是一個更多的谷歌搜索:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.