Capistrano + SVN 个人安装部署总结
一. 安装 capistrano
# 1 . yum install gem
# 2 . gem install capistrano 当前执行步骤如果报错执行 执行3-8步骤
gem install 安装很慢的情况下执行切换镜像 gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
# 3. gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
# 4. curl -sSL https://get.rvm.io | bash -s stable 第一个不行 用第二个 curl -L get.rvm.io | bash -s stable
# 5. source /usr/local/rvm/scripts/rvm
# 6. rvm list know
# 7. rvm install 2.4.4
# 8. gem install capistrano
二. 使用
1.创建一个文件夹承载 capistrano 执行命令 cap install/cap init 初始化 capistrano
2. 编辑Capfile
打开svn的注释
require "capistrano/scm/svn"
install_plugin Capistrano::SCM::Svn
# 注释掉GIT方式(默认是git方式)
# #require "capistrano/scm/git"
# #install_plugin Capistrano::SCM::Git**
3. 进入config目录,编辑deploy.rb文件
示例配置文件如下 :
> lock "~> 3.11.2"
> set :application, "project_name"
> #手动输入设置分支
> ask(:branch, "staging")
> #获取分支
> set :repo_url, "svn://xx.xx.xxx.xxx:22223/smallapp/#{fetch(:branch)}/"
> #设置保存版本
> set :keep_releases, 5
> set :pty, true
> #svn账号
> set :svn_username, 'svn_username'
> #svn密码
> set :svn_password, 'svn_password'
> set :current_directory,'current'
> #服务器公共配置 日志 静态资源 配置文件存放目录 文件内容需要先上传
> set :shared_directory,'shared'
> #部署到服务器指定目录
> set :deploy_to, "/home/project_name"
> task :create_link do
> on roles(:web) do
> execute :rm, "-rf", "#{release_path}/trunk/www/logs"
> execute :rm, "-rf", "#{release_path}/trunk/www/site.config.php"
> execute :rm, "-rf", "#{release_path}/trunk/www/project_config/module_config/account.config.php"
> execute :ln, "-s", "#{shared_path}/www/logs #{release_path}/trunk/www/logs"
> execute :ln, "-s", "#{shared_path}/www/site.config.php #{release_path}/trunk/www/site.config.php #{release_path}/trunk/www/system_service.config.php"
> execute :ln, "-s", "#{shared_path}/www/project_config/module_config/account.config.php #{release_path}/trunk/www/project_config/module_config/account.config.php"
> end
> end
> #部署完毕创建软链接到 shared 目录下对应的配置文件
> after "deploy:published", "create_link"
编辑config目录下 staging.rb 文件 添加服务器发布用户 deploy
> role :web, 'deploy@服务器地址',password: 服务器密码
执行发布的时候如果出现pending 的情况 并且出现 capistrano 目录的log对应日志文件出现 Store password unencrypted (yes/no)? 则修改 deploy 用户下的svn隐藏文件 ./subversion/servers
**store-plaintext-passwords = yes**
cap staging deploy:check 初始化项目 会生成 shared 目录 系统配置文件需要提前放置
cap staging deploy 发布预发
cap production deploy 发布正式
cap staging deploy:rollback 回滚操作
发布成功之后应该是这样的
有关capistrano的更多说明请查看官方文档 https://capistranorb.com/
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: