From: whitestar Date: Sun, 3 Mar 2019 09:25:49 +0000 (+0900) Subject: add yarn-installer recipe to the nodejs_utils cookbook. X-Git-Tag: nodejs_utils-0.2.0 X-Git-Url: http://git.osdn.net/view?p=metasearch%2Fgrid-chef-repo.git;a=commitdiff_plain;h=refs%2Ftags%2Fnodejs_utils-0.2.0 add yarn-installer recipe to the nodejs_utils cookbook. --- diff --git a/cookbooks/nodejs_utils/CHANGELOG.md b/cookbooks/nodejs_utils/CHANGELOG.md index 0801015..9769554 100644 --- a/cookbooks/nodejs_utils/CHANGELOG.md +++ b/cookbooks/nodejs_utils/CHANGELOG.md @@ -1,5 +1,9 @@ # nodejs_utils CHANGELOG +0.2.0 +----- +- add yarn-installer recipe. + 0.1.0 ----- - Initial release. diff --git a/cookbooks/nodejs_utils/Gemfile.lock b/cookbooks/nodejs_utils/Gemfile.lock new file mode 100644 index 0000000..6fb9a3b --- /dev/null +++ b/cookbooks/nodejs_utils/Gemfile.lock @@ -0,0 +1,22 @@ +GEM + remote: https://rubygems.org/ + specs: + chef-api (0.8.0) + logify (~> 0.1) + mime-types + logify (0.2.0) + mime-types (3.2.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2018.0812) + stove (6.0.0) + chef-api (~> 0.5) + logify (~> 0.2) + +PLATFORMS + ruby + +DEPENDENCIES + stove + +BUNDLED WITH + 1.16.0 diff --git a/cookbooks/nodejs_utils/README.md b/cookbooks/nodejs_utils/README.md index 2b3a5c0..67a2e17 100644 --- a/cookbooks/nodejs_utils/README.md +++ b/cookbooks/nodejs_utils/README.md @@ -1,7 +1,7 @@ nodejs_utils Cookbook ===================== -This cookbook installs `n`, `nvm` (Node.js Version Managers) setup scripts. +This cookbook installs `n`, `nvm` (Node.js Version Managers) and `yarn` setup scripts. ## Contents @@ -15,6 +15,7 @@ This cookbook installs `n`, `nvm` (Node.js Version Managers) setup scripts. - [nodejs_utils::default](#nodejs_utilsdefault) - [nodejs_utils::n-installer](#nodejs_utilsn-installer) - [nodejs_utils::nvm-installer](#nodejs_utilsnvm-installer) + - [nodejs_utils::yarn-installer](#nodejs_utilsyarn-installer) - [License and Authors](#license-and-authors) ## Requirements @@ -34,7 +35,8 @@ This cookbook installs `n`, `nvm` (Node.js Version Managers) setup scripts. |Key|Type|Description, example|Default| |:--|:--|:--|:--| -|`['nodejs_utils']['nvm']['version']`|String|latest: 'master'|`'v0.33.6'`| +|`['nodejs_utils']['nvm']['version']`|String|latest: 'master'|`'v0.33.11'`| +|`['nodejs_utils']['yarn']['version']`|String||`'latest'`| ## Usage @@ -52,12 +54,16 @@ This recipe installs the `n` setup script. This recipe installs the `nvm` setup script. +#### nodejs_utils::nvm-installer + +This recipe installs the `yarn` setup script. + ## License and Authors - Author:: whitestar at osdn.jp ```text -Copyright 2017, whitestar +Copyright 2017-2019, whitestar Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cookbooks/nodejs_utils/Rakefile b/cookbooks/nodejs_utils/Rakefile index 8b85e6a..1ba86c6 100644 --- a/cookbooks/nodejs_utils/Rakefile +++ b/cookbooks/nodejs_utils/Rakefile @@ -3,12 +3,58 @@ require 'rubocop/rake_task' require 'foodcritic' require 'stove/rake_task' +tpl_cookbook = '00cookbook' +cookbook_name = File.basename(Dir.pwd) + +desc 'Initialize project' +task :init do + next if cookbook_name == tpl_cookbook + + [ + '.foodcritic', + '.rubocop.yml', + 'Berksfile', + 'chefignore', + 'concourse.yml', + 'fly-vars.yml', + 'fly-vars.local.yml', + 'Gemfile', + 'Gemfile.lock', + 'version', + ].each {|conf| + sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf) + } + + ruby [ + %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'), + '-i fly-vars.local.yml', + ].join(' ') +end + +desc 'Update project' +task :update do + next if cookbook_name == tpl_cookbook + + [ + 'Rakefile', + 'chefignore', + 'concourse.yml', + 'fly-vars.yml', + 'Gemfile', + 'Gemfile.lock', + ].each {|conf| + sh "cp ../#{tpl_cookbook}/#{conf} ./" + } +end + +desc 'fly set-pipeline' task :'set-pipeline' do sh [ - "fly -t $CC_TARGET sp -p #{File.basename(Dir.pwd)}-cookbook -c concourse.yml", - '-l fly-vars.yml -l ~/sec/credentials-prod.yml', + "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml", + '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml', ].join(' ') end +desc 'rake set-pipeline alias' task sp: 'set-pipeline' namespace :style do diff --git a/cookbooks/nodejs_utils/attributes/default.rb b/cookbooks/nodejs_utils/attributes/default.rb index b5456fb..f176abb 100644 --- a/cookbooks/nodejs_utils/attributes/default.rb +++ b/cookbooks/nodejs_utils/attributes/default.rb @@ -2,7 +2,7 @@ # Cookbook Name:: nodejs_utils # Attributes:: default # -# Copyright 2017, whitestar +# Copyright 2017-2019, whitestar # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,4 +17,5 @@ # limitations under the License. # -default['nodejs_utils']['nvm']['version'] = 'v0.33.6' # latest: 'master' +default['nodejs_utils']['nvm']['version'] = 'v0.33.11' # latest: 'master' +default['nodejs_utils']['yarn']['version'] = 'latest' diff --git a/cookbooks/nodejs_utils/chefignore b/cookbooks/nodejs_utils/chefignore new file mode 100644 index 0000000..10e314a --- /dev/null +++ b/cookbooks/nodejs_utils/chefignore @@ -0,0 +1,20 @@ +# Put files/directories that should be ignored in this file. +# Lines that start with '# ' are comments. + +Berksfile.lock + +# concourse +concourse.yml +fly-vars.yml +fly-vars.local.yml + +# emacs +*~ + +.rubocop_todo.yml + +# vim +*.sw[a-z] + +# subversion +*/.svn/* diff --git a/cookbooks/nodejs_utils/concourse.yml b/cookbooks/nodejs_utils/concourse.yml index 72d436b..d373185 100644 --- a/cookbooks/nodejs_utils/concourse.yml +++ b/cookbooks/nodejs_utils/concourse.yml @@ -1,5 +1,4 @@ --- -# $ fly -t $CC_TARGET sp -p nodejs_utils-cookbook -c concourse.yml -l fly-vars.yml -l ~/sec/credentials-prod.yml resources: - name: src-git type: git diff --git a/cookbooks/nodejs_utils/fly-vars.yml b/cookbooks/nodejs_utils/fly-vars.yml index 949254d..76f2fcd 100644 --- a/cookbooks/nodejs_utils/fly-vars.yml +++ b/cookbooks/nodejs_utils/fly-vars.yml @@ -1,3 +1,2 @@ --- -cookbook-name: nodejs_utils chefdk-version: 1.6.11 diff --git a/cookbooks/nodejs_utils/recipes/yarn-installer.rb b/cookbooks/nodejs_utils/recipes/yarn-installer.rb new file mode 100644 index 0000000..6c9e712 --- /dev/null +++ b/cookbooks/nodejs_utils/recipes/yarn-installer.rb @@ -0,0 +1,53 @@ +# +# Cookbook Name:: nodejs_utils +# Recipe:: yarn-installer +# +# Copyright 2019, whitestar +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +doc_url = 'https://yarnpkg.com/en/docs/' + +[ + 'curl', +].each {|pkg| + resources(package: pkg) rescue package pkg do + action :install + end +} + +[ + 'yarn_install', +].each {|script| + template "/usr/local/bin/#{script}" do + source "usr/local/bin/#{script}" + owner 'root' + group 'root' + mode '0755' + action :create + end +} + +log 'yarn-installer post install message' do + message <<-"EOM" +Note: You must execute the following command manually. + See #{doc_url} + * install yarn: + $ yarn_install + ... + $ source ~/.bashrc + $ yarn -v + 1.13.0 +EOM +end diff --git a/cookbooks/nodejs_utils/templates/default/usr/local/bin/yarn_install b/cookbooks/nodejs_utils/templates/default/usr/local/bin/yarn_install new file mode 100644 index 0000000..f4647a9 --- /dev/null +++ b/cookbooks/nodejs_utils/templates/default/usr/local/bin/yarn_install @@ -0,0 +1,13 @@ +#!/bin/sh + +PATH=.:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin + +<% +yarn_ver = node['nodejs_utils']['yarn']['version'] + +if yarn_ver == 'latest' +-%> +curl -o- -L https://yarnpkg.com/install.sh | bash +<% else -%> +curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version <%= yarn_ver %> +<% end -%> diff --git a/cookbooks/nodejs_utils/version b/cookbooks/nodejs_utils/version index 6e8bf73..0ea3a94 100644 --- a/cookbooks/nodejs_utils/version +++ b/cookbooks/nodejs_utils/version @@ -1 +1 @@ -0.1.0 +0.2.0 diff --git a/roles/nodejs-utils.rb b/roles/nodejs-utils.rb new file mode 100644 index 0000000..c5caf24 --- /dev/null +++ b/roles/nodejs-utils.rb @@ -0,0 +1,16 @@ +name 'nodejs-utils' +description 'Node.js Setup Utilities' + +run_list( + 'recipe[nodejs_utils::n-installer]', + 'recipe[nodejs_utils::nvm-installer]', + 'recipe[nodejs_utils::yarn-installer]', +) + +#env_run_lists + +default_attributes( +) + +override_attributes( +)