openstax / napkin-notes

:notebook: virtual back-of-a-napkin notes (persistent non-structured discussions)
3 stars 8 forks source link

How to install yarn? #83

Open philschatz opened 6 years ago

philschatz commented 6 years ago

There are many ways to install https://yarnpkg.com . The options I see are:

  1. curl -o- -L https://yarnpkg.com/install.sh | bash || exit 1
  2. if [[ ! $(which yarn) ]]; then if [[ $(which brew) ]]; then brew install yarn; else; sudo apt-get install yarn; fi
  3. npm install --global yarn (does not work when folks use nvm)
  4. npm install yarn (annoyingly requires installing additional packages all the time)

It seems that the use-cases are (everyone would use it implicitly through ./script/setup):

  1. devs would use it on their laptops
  2. Travis would use it to run tests (and speed up running the tests)
  3. Jenkins would use it to generate the JS+CSS tarballs of Frontend repos
  4. bastion would use it (until tarballs are used everywhere)

Some questions are:

  1. Should this be assumed to be installed on every machine or should ./script/setup install it?
    • ./script/setup already installs system packages for osx & debian (and so do Dockerfiles)

It would be great to get feedback from @dtwilliamson, @pandafulmanda , @nathanstitt , @reedstrm, @pumazi , @karenc on which approach to use. Since it would impact almost all of the Frontend repositories I posted it in here.

Refs https://github.com/openstax/os-webview/pull/964 , https://github.com/openstax/os-webview/pull/957 , https://github.com/Connexions/cnx-recipes/pull/346

dtwilliamson commented 6 years ago

None of these are the preferred way to install yarn on Ubuntu. This is what I recommend:

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list and

On Ubuntu 16.04 or below and Debian Stable, you will also need to configure the NodeSource repository to get a new enough version of Node.js.

then

sudo apt-get update && sudo apt-get install yarn

which is from the documentation at https://yarnpkg.com/lang/en/docs/install/#linux-tab

Option 2 in the initial message above hurts my eyes. It would be better as:

if type -a yarn > /dev/null; then if type -a brew > /dev/null; then brew install yarn; else; curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -; echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list; sudo apt-get update && sudo apt-get install yarn; fi

in order to use proper Bash conditionals, use a builtin instead of an external executable (it will detect functions and aliases in addition to files in the $PATH) and it incorporates the recommended installation method.

reedstrm commented 6 years ago

As a general comment, it might be better for the repo-specific setup scripts to only be used in dev environments; operational deployments should use the operational automation, which for CNX is cnx-deploy and ansible. This can lead to divergence, but I think it's important to be able to look in one, cross repo location for things like the list of system packages a deployment requires, rather than parsing every setup script.

m1yag1 commented 6 years ago

I don't know if this would be useful but I have this ansible role: https://github.com/openstax/ansible-role-nodejs. If you need to install yarn you can add it to the npm global packages and it will be installed.

philschatz commented 6 years ago

Ok. So, what if:

  1. bastion* has yarn already installed (in addition to nvm)
  2. jenkins.cnx.org gets yarn installed
  3. ./script/setup will prompt "Would you like to install yarn now? (y/N)" if yarn is not installed and being executed on a debian machine

I think that addresses @dtwilliamson concerns and partially @reedstrm 's concern.

I would like to have a separate discussion about reducing the need to update deployment scripts whenever dev tools change. DM me if you have a preference for where that discussion should occur (GitHub Issue, Trello Card, Schedule a meeting, etc)

@m1yag1 Thanks for bringing up that option but it seems like the consensus is to install it as a system package. I'm curious, are there any other packages you install globally? (I'm not a fan of globals because they run into each other)

@kajalp Should I create a DevOps Trello card to get yarn installed on bastion and jenkins?


🎊 🐰

I started looking into how to prompt the user when... all of a sudden.... a wild @dtwilliamson appeared! https://stackoverflow.com/a/1885534

karenc commented 6 years ago

Yeah I also feel like ./script/setup can be used for development and testing (travis), but it probably shouldn't be used directly in deployment (ansible). It can be used as a reference to see what needs to be done when someone works on the deployment script.

Tutor deployment should include installation for everything (all the local_action) that needs to be done locally (install nvm, rbenv, yarn? etc).

m1yag1 commented 6 years ago

@philschatz, The only one I'm installing globally is gulp-cli and it's per the install instructions for hypothes.is. There could be a task added to install yarn as package too.