使用capistrano部署角度应用程序

时间:2018-02-07 17:42:25

标签: angular npm capistrano npm-install

我不知道这是不是最好的方法,但我想使用capistrano(通过gitlab-ci)在远程服务器上部署我的angular 5应用程序。

我遇到了npm install和ng build的问题。对于capistrano,node_modules似乎是空的。这是配置文件。

deploy.rb

set :application, 'bo'
set :repo_url, 'git@...'
set :keep_releases, 5

set :deploy_via, "remote_cache_with_project_root"
set :deploy_to, "/var/www/bo/"
set :current_directory, "bo"
set :npm_flags, '--production' # default

after 'deploy:published','test:npm_install'
after 'deploy:published','test:build'

...

的任务

npm_install.cap

namespace :test do
    desc 'build bo'
    task :npm_install do 
        on roles(:app), in: :sequence, wait: 5 do
            execute :npm, "install"
        end
    end
end

...

build.cap

namespace :test do
    desc 'build bo'
    task :build do 
        on roles(:app), in: :sequence, wait: 5 do
            execute "ng build --aot --env=prod --sourcemaps=false --named-chunks"
        end
    end
end

.... 

我在gitlab-ci中可以看到的错误:

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as bo@test.intra: ng build --aot --env=prod --sourcemaps=false --named-chunks exit status: 1
ng build --aot --env=prod --sourcemaps=false --named-chunks stdout: Nothing written
ng build --aot --env=prod --sourcemaps=false --named-chunks stderr: node_modules appears empty, you may need to run `npm install`
/home/gitlab-runner/builds/7599a2f4/0/bo/deploy/tasks/build.cap:4:in `block (2 levels) in <top (required)>'

Caused by:
SSHKit::Command::Failed: ng build --aot --env=prod --sourcemaps=false --named-chunks exit status: 1
ng build --aot --env=prod --sourcemaps=false --named-chunks stdout: Nothing written
ng build --aot --env=prod --sourcemaps=false --named-chunks stderr: node_modules appears empty, you may need to run `npm install`
/home/gitlab-runner/builds/7599a2f4/0/bo/deploy/tasks/build.cap:5:in `block (3 levels) in <top (required)>'
/home/gitlab-runner/builds/7599a2f4/0/bo/deploy/tasks/build.cap:4:in `block (2 levels) in <top (required)>'

非常感谢

1 个答案:

答案 0 :(得分:0)

最后,我使用gitlab生成构建和capistrano来管理版本;)