简体   繁体   English

在 Jenkins 管道(AWS EC2 实例)上捆绑安装真的很慢

[英]Bundle install really slow on Jenkins Pipeline (AWS EC2 Instance)

I am running Jenkins on AWS EC2 Linux Instance and I am trying to bundle install the gems needed for my rails repo on GitHub.我在 AWS EC2 Linux 实例上运行 Jenkins,我正在尝试在 GitHub 上捆绑安装我的 rails 存储库所需的 gem。

It is a new project that I created for testing but the bundle takes hours, Jenkins freezes and I need to restart the server and Jenkins and it never finishes installing the gems in the end.这是我为测试而创建的一个新项目,但捆绑包需要数小时,Jenkins 冻结,我需要重新启动服务器和 Jenkins 并且它最终永远无法完成 gems 的安装。

This is my code:这是我的代码:

    pipeline {
    agent { docker { image 'ruby:2.6.6' } }
    stages {
        stage('Fetching Git') {

            steps {
                git credentialsId: 'user-key',
                    url: 'git@github.com:user/jenkins_project.git'
            }
        }
        stage('Build') {

            steps {
                sh 'gem install bundler'
                sh 'bundle install --jobs 4'
                sh 'RAILS_ENV=test rake db:migrate'
            }
        }
        stage('Test') {

            steps {
                sh 'RAILS_ENV=test bundle exec rspec --format RspecJunitFormatter --out result_spec.xml'
            }
        }
    }
}

What I tried doing is:我尝试做的是:

  1. Using --jobs when bundle install (it doesn't seem to work)捆绑安装时使用 --jobs (它似乎不起作用)

  2. Using http instead of https on the Gemfile when on打开时在 Gemfile 上使用 http 而不是 https

    source 'http://rubygems.org'来源“http://rubygems.org”

I know it is unsafe.我知道这是不安全的。 And this doesn't seem to work either.这似乎也不起作用。 3. Also tried this: 3.也试过这个:

echo 'export MAKE="make -j$(nproc)"' >> $home/.bash_profile
time MAKE="make --jobs 8" bundle install

From here ( https://build.betterup.com/one-weird-trick-that-will-speed-up-your-bundle-install/ ).从这里( https://build.betterup.com/one-weird-trick-that-will-speed-up-your-bundle-install/ )。 But it doesn't work either.但它也不起作用。

Any ideas on why is this happening and how can I solve it greatly appreciated!关于为什么会发生这种情况以及如何解决它的任何想法,非常感谢!

Solved this by:通过以下方式解决了这个问题:

  1. Creating a master server with Java & Jenkins使用 Java & Jenkins 创建主服务器
  2. Creating a slave server (called 'linux_slave') with Java & Git & Docker使用 Java & Git & Docker 创建从服务器(称为“linux_slave”)

The code would be something like this:代码将是这样的:

pipeline {
    agent {
        docker {
            image 'ruby:2.6.6'
            label 'linux_slave'
        }
    }
    stages {
        stage('Fetching Git') {
            
            steps {
                git credentialsId: 'user-key',
                    url: 'git@github.com:user/jenkins_project.git'
            }
        }
        stage('Build') {
            steps {
                sh 'gem install bundler:2.0.1'
                sh 'bundle install'
                sh 'RAILS_ENV=test rake db:migrate'
            }
        }
    }
}

Hope it helps someone in need sometime!希望对有需要的人有所帮助!

add this as first line before gem install as each installed package will be less in size because no documenation is been downloaded with it将此添加为 gem install 之前的第一行,因为每个安装的 package 的大小会更小,因为没有下载文档

'echo''gem: --no-document'' > ~/.gemrc'

I have used this for Travis and it helped a lot I am not fully sure for Jenkins syntax but try the following one我已经将它用于 Travis,它帮助很大

        stage('Build') {

        steps {
            sh 'echo''gem: --no-document'' > ~/.gemrc'
            sh 'gem install bundler'
            sh 'bundle install --jobs 4'
            sh 'RAILS_ENV=test rake db:migrate'
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM