rup
rup

Reputation: 141

Continuous Integration - How to run npm install on offline server

Our continuous integration system uses ansible playbooks to deploy our repo (including node modules) to a list of servers as specified in our ansible host file. We have numerous environments which are configured in individual host files. Jenkins is our build server which is used to kick of each ansible run on a schedule. One of the tasks in the ansible playbook is npm install.

Our problem arises because only one of the environments is offline, so when the playbook performs the npm install task on this particular environment (read "host file"), it fails due to lack of internet connectivity.

I've seen lots of answers on how to get around this manually, but the whole point of our continuous integration system is to run automatically, and consistently (from environment to environment). So I don't want to introduce a bunch of workarounds in the playbook and/or repo to bundle up, etc. the node modules just to get around this particular hosts offline issue.

Since this is a lower enviroment, I am willing to do something specific in advance, as a one time step, on this server in order to bypass this issue. But since the playbook tasks tar up all existing files under the user account in a rollback zip file prior to installing the new code, anything I introduce on the server under this user account will be essentially removed (with the exception of . files and directories).

So, how to us CI to run npm install on single offline server without manual intervention?

Upvotes: 0

Views: 1558

Answers (2)

grizzthedj
grizzthedj

Reputation: 7505

An alternative would be to setup an internal NPM registry, so that your offline Jenkins server can talk to your internal NPM, however keeping this in sync with the public NPM repository would likely be a nightmare, presenting a number of problems.

You need to allow "outbound only" internet access to this Jenkins server in order for this to work effectively without workarounds.

Upvotes: 0

James
James

Reputation: 82136

I'm not familiar with ansible but the problem you're experiencing isn't uncommon, and there are definitely automated ways of solving it e.g.

  • Setup a local NPM registry e.g. sinopia and configure this as your default registry. Nodes with no internet access will receive the latest cached version of the package (presuming it was previously downloaded by a node)
  • Run npm install once, package the nodes up and share the artifacts across the environments

Personally, I prefer and advocate the second solution because:

  • Faster CI runs (only one download)
  • Package version is guarenteed across all environments (although strict versioning would also solve this)

Upvotes: 1

Related Questions