diff --git a/.circleci/config.yml b/.circleci/config.yml index 3020fb1f..dd81046e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,73 +1,61 @@ --- version: 2.1 orbs: - kitchen: sous-chefs/kitchen@1.0.1 + kitchen: taqtiqa/kitchen@dev:1.3.5 + cmds: taqtiqa/commands@dev:0.1.14 + +jobs: + ignite: + executor: kitchen/chef + steps: + - cmds/ignite-install: + version: workflows: kitchen: jobs: - - kitchen/danger: - name: danger - context: Danger - - kitchen/lint: - name: lint - - kitchen/dokken-single: - suite: global - platform: debian-8 - name: global-debian-8 - requires: [lint, danger] - - kitchen/dokken-single: - suite: global - platform: debian-9 - name: global-debian-9 - requires: [lint, danger] - - kitchen/dokken-single: - suite: global - platform: centos-6 - name: global-centos-6 - requires: [lint, danger] - - kitchen/dokken-single: - suite: global - platform: centos-7 - name: global-centos-7 - requires: [lint, danger] - - kitchen/dokken-single: - suite: global - platform: ubuntu-1604 - name: global-ubuntu-1604 - requires: [lint, danger] - - kitchen/dokken-single: - suite: global - platform: ubuntu-1804 - name: global-ubuntu-1804 - requires: [lint, danger] - - kitchen/dokken-single: + # - ignite: + # name: ignite + # - kitchen/danger: + # name: danger + # context: Danger + - kitchen/mdlint: + name: mdlint + - kitchen/yamllint: + name: yamllint + - kitchen/dokken: suite: global - platform: opensuse-leap - name: global-opensuse-leap - requires: [lint, danger] - - kitchen/dokken-single: - name: system-install - suite: system-install - platform: centos-7 - requires: [lint, danger] - - kitchen/dokken-single: - name: user-install - suite: user-install - platform: centos-7 - requires: [lint, danger] - - kitchen/dokken-single: - name: gem - suite: gem - platform: centos-7 - requires: [lint, danger] - - kitchen/dokken-single: - name: ruby-uninstall - suite: ruby-uninstall - platform: ubuntu-1804 - requires: [lint, danger] - - kitchen/dokken-single: - name: custom-group - suite: custom-group-install - platform: centos-7 - requires: [lint, danger] + name: global + requires: [mdlint, yamllint] + # requires: [mdlint, yamllint, ignite] + # Kitchen/dokken-single runs a single Instance + # - kitchen/dokken-single: + # suite: global-opensuse-leap + # name: global-opensuse-leap + # requires: [mdlint, yamllint] + # requires: [mdlint, yamllint, danger] + # - kitchen/dokken-single: + # name: system-install-centos-7 + # suite: system-install-centos-7 + # requires: [mdlint, yamllint] + # requires: [mdlint, yamllint, danger] + # - kitchen/dokken-single: + # name: user-install-centos-7 + # suite: user-install-centos-7 + # requires: [mdlint, yamllint] + # requires: [mdlint, yamllint, danger] + # - kitchen/dokken-single: + # name: pkg-centos-7 + # suite: pkg-centos-7 + # requires: [mdlint, yamllint] + # requires: [mdlint, yamllint, danger] + # - kitchen/dokken-single: + # name: julia-uninstall-ubuntu-1804 + # suite: julia-uninstall-ubuntu-1804 + # requires: [mdlint, yamllint] + # requires: [mdlint, yamllint, danger] + # - kitchen/dokken-single: + # name: custom-group + # suite: custom-group-install-centos-7 + # requires: [mdlint, yamllint] + # requires: [mdlint, yamllint, danger] diff --git a/.delivery/project.toml b/.delivery/project.toml index 3accb43c..376a950c 100644 --- a/.delivery/project.toml +++ b/.delivery/project.toml @@ -1,5 +1,5 @@ [local_phases] -unit = "rspec" +unit = "chef exec rspec test/spec" lint = 'cookstyle --display-cop-names --extra-details' syntax = "foodcritic ." provision = "echo skipping" diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 92151e07..9f3e9181 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* sous-chefs/ruby_rbenv +* jlenv/jlenv-cookbook diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index bce1ae57..e3b01f77 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -10,4 +10,4 @@ - [ ] All tests pass. - [ ] New functionality includes testing. -- [ ] New functionality has been documented in the README if applicable \ No newline at end of file +- [ ] New functionality has been documented in the `docs/` folder (if applicable). \ No newline at end of file diff --git a/.github/lock.yml b/.github/lock.yml index 97037158..d59c23ea 100644 --- a/.github/lock.yml +++ b/.github/lock.yml @@ -1,9 +1,11 @@ +--- # Configuration for lock-threads - https://github.com/dessant/lock-threads # Number of days of inactivity before a closed issue or pull request is locked daysUntilLock: 365 -# Issues and pull requests with these labels will not be locked. Set to `[]` to disable +# Issues and pull requests with these labels will not be locked. Set to `[]` +# to disable exemptLabels: [] # Label to add before locking, such as `outdated`. Set to `false` to disable diff --git a/.gitignore b/.gitignore index ef781459..3b9e896e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,12 +21,14 @@ _Store *.bk *.bkup -# ruby/bundler files -.ruby-version -.ruby-gemset +# IDE +.vscode + +# julia/bundler files +.julia-version +.julia-gemset .rvmrc -Gemfile.lock -.bundle +Pkgfile.lock *.gem # YARD artifacts @@ -50,3 +52,5 @@ Cheffile.lock .vagrant/ .vagrant.d/ .kitchen/ + +test/*.lock.json diff --git a/.kitchen.appveyor.yml b/.kitchen.appveyor.yml index cb328cc0..a29423a8 100644 --- a/.kitchen.appveyor.yml +++ b/.kitchen.appveyor.yml @@ -1,3 +1,4 @@ +--- driver: name: proxy host: localhost diff --git a/.kitchen.dokken.yml b/.kitchen.dokken.yml deleted file mode 100644 index ccb51566..00000000 --- a/.kitchen.dokken.yml +++ /dev/null @@ -1,75 +0,0 @@ -driver: - name: dokken - privileged: true - env: [CHEF_LICENSE=accept] - -transport: - name: dokken - -provisioner: - name: dokken - deprecations_as_errors: true - -verifier: - name: inspec - -platforms: -- name: debian-8 - driver: - image: dokken/debian-8 - pid_one_command: /sbin/init - intermediate_instructions: - - RUN /usr/bin/apt-get update - - RUN /usr/bin/apt-get install sudo -y - -- name: debian-9 - driver: - image: dokken/debian-9 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - RUN /usr/bin/apt-get install sudo -y - -- name: centos-6 - driver: - image: dokken/centos-6 - pid_one_command: /sbin/init - intermediate_instructions: - - RUN yum -y install sudo - -- name: centos-7 - driver: - image: dokken/centos-7 - pid_one_command: /usr/lib/systemd/systemd - intermediate_instructions: - - RUN yum -y install sudo - -- name: fedora-latest - driver: - image: dokken/fedora-latest - pid_one_command: /usr/lib/systemd/systemd - intermediate_instructions: - - RUN dnf -y install sudo - -- name: ubuntu-16.04 - driver: - image: dokken/ubuntu-16.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - RUN /usr/bin/apt-get install sudo -y - -- name: ubuntu-18.04 - driver: - image: dokken/ubuntu-18.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - RUN /usr/bin/apt-get install sudo -y - -- name: opensuse-leap - driver: - image: dokken/opensuse-leap - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN zypper --non-interactive install sudo diff --git a/.kitchen.vagrant.yml b/.kitchen.vagrant.yml new file mode 100644 index 00000000..b9fcafbb --- /dev/null +++ b/.kitchen.vagrant.yml @@ -0,0 +1,43 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + product_name: chef + product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> + install_strategy: once + deprecations_as_errors: true + policyfile: Policyfile.rb + +verifier: + name: inspec + +platforms: + - name: centos-6 + - name: centos-7 + - name: fedora-latest + - name: debian-8 + - name: debian-9 + - name: ubuntu-16.04 + - name: ubuntu-18.04 + - name: opensuse-leap + +suites: + - name: pkg + run_list: recipe[test::pkg] + includes: [centos-7] + - name: global + run_list: recipe[test::global] + - name: julia_uninstall + run_list: recipe[test::julia_uninstall] + includes: [ubuntu-18.04] + - name: system_install + run_list: recipe[test::system_install] + includes: [centos-7] + - name: user_install + run_list: recipe[test::user_install] + includes: [centos-7] + - name: custom_group_install + run_list: recipe[test::custom_group_install] + includes: [centos-7] diff --git a/.kitchen.yml b/.kitchen.yml index 1132c5a5..4a217c4d 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,40 +1,124 @@ +--- driver: - name: vagrant + name: dokken + privileged: true + env: [CHEF_LICENSE=accept] + +transport: + name: dokken provisioner: - product_name: chef - product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> - install_strategy: once + name: dokken deprecations_as_errors: true verifier: name: inspec platforms: - - name: centos-6 - - name: centos-7 - - name: fedora-latest - - name: debian-8 - - name: debian-9 - - name: ubuntu-16.04 - - name: ubuntu-18.04 - - name: opensuse-leap + - + name: debian-8 + driver: + image: dokken/debian-8 + pid_one_command: /sbin/init + intermediate_instructions: + - RUN /usr/bin/apt-get update + # - RUN /usr/bin/apt-get upgrade -y + - + name: debian-9 + driver: + image: dokken/debian-9 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + # - RUN /usr/bin/apt-get upgrade -y + - + name: centos-6 + driver: + image: dokken/centos-6 + pid_one_command: /sbin/init + intermediate_instructions: + - RUN yum -y install sudo + - + name: centos-7 + driver: + image: dokken/centos-7 + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN yum -y install sudo + - + name: amazonlinux + driver: + image: dokken/amazonlinux + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN yum -y install sudo + - + name: amazonlinux-2 + driver: + image: dokken/amazonlinux-2 + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN yum -y install sudo + - + name: fedora-latest + driver: + image: dokken/fedora-latest + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN dnf -y install sudo + - + name: ubuntu-16.04 + driver: + image: dokken/ubuntu-16.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + # - RUN /usr/bin/apt-get upgrade -y + - + name: ubuntu-18.04 + driver: + image: taqtiqa/dokken-images:ubuntu-18.04-latest + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + # - RUN /usr/bin/apt-get upgrade -y + - + name: opensuse-leap + driver: + image: dokken/opensuse-leap + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN zypper --non-interactive install sudo suites: -- name: gem - run_list: recipe[test::gem] - includes: [centos-7] -- name: global - run_list: recipe[test::global] -- name: ruby_uninstall - run_list: recipe[test::ruby_uninstall] - includes: [ubuntu-18.04] -- name: system_install - run_list: recipe[test::system_install] - includes: [centos-7] -- name: user_install - run_list: recipe[test::user_install] - includes: [centos-7] -- name: custom_group_install - run_list: recipe[test::custom_group_install] - includes: [centos-7] + - name: resources + provisioner: + policyfile: test/fixtures/cookbooks/resources/Policyfile.rb + verifier: + inspec_tests: + - test/integration/resources + - name: recipes + provisioner: + policyfile: test/fixtures/cookbooks/recipes/Policyfile.rb + verifier: + inspec_tests: + - test/integration/recipes + - name: issues + provisioner: + policyfile: test/fixtures/cookbooks/issues/Policyfile.rb + verifier: + inspec_tests: + - test/integration/issues + # - name: system_install + # provisioner: + # policyfile: test/fixtures/cookbooks/resources/system_install.pf.rb + # verifier: + # inspec_tests: + # - test/integration/resources/system_install + # - name: global + # provisioner: + # policyfile: test/fixtures/cookbooks/resources/global.pf.rb + # verifier: + # inspec_tests: + # - test/integration/resources/global + # attributes: diff --git a/.markdownlint.yml b/.markdownlint.yml new file mode 100644 index 00000000..f9a89e17 --- /dev/null +++ b/.markdownlint.yml @@ -0,0 +1,4 @@ +{ + "default": true, + "MD003": { "style": "atx" } +} \ No newline at end of file diff --git a/.mdlrc b/.mdlrc new file mode 100644 index 00000000..fdf88b64 --- /dev/null +++ b/.mdlrc @@ -0,0 +1 @@ +rules "~MD033", "~MD013" \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 65620004..b42d3014 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +inherit_from: .rubocop_todo.yml + +--- AllCops: Exclude: - 'Dangerfile' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..5a34606f --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,71 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2019-08-01 09:44:31 +1000 using RuboCop version 0.55.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'test/spec/spec_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'Policyfile.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingBlankLines: + Exclude: + - 'test/fixtures/cookbooks/test/Policyfile.rb' + - 'test/spec/spec_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'Policyfile.rb' + - 'test/spec/spec_helper.rb' + +# Offense count: 1 +Lint/EmptyWhen: + Exclude: + - 'libraries/package_deps.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'Dangerfile' + - 'libraries/helpers.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: only_raise, only_fail, semantic +Style/SignalException: + Exclude: + - 'Dangerfile' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'Policyfile.rb' + - 'test/fixtures/cookbooks/test/Policyfile.rb' + +# Offense count: 25 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 157 diff --git a/Berksfile b/Berksfile deleted file mode 100644 index e09849c7..00000000 --- a/Berksfile +++ /dev/null @@ -1,7 +0,0 @@ -source 'https://supermarket.chef.io' - -metadata - -group :integration do - cookbook 'test', path: 'test/fixtures/cookbooks/test' -end diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f35396..e294ad87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ -# ruby_rbenv Cookbook Changelog +# jlenv Cookbook Changelog -This file is used to list changes made in each version of the ruby_rbenv cookbook. +This file is used to list changes made in each version of the jlenv cookbook. + +## 0.1.0 (2019-07-03) + +### NOTICE: Cookbook has been ported to Julia + +- Renamed to jlenv-cookbook and uploaded to Supermarket. +- Updated Circle-CI config to run integration tests using kitchen-docker ## 2.1.2 (2018-11-09) @@ -52,23 +59,28 @@ This file is used to list changes made in each version of the ruby_rbenv cookboo ## 2.0.1 (2017-08-02) -- Fix user_install resource bug where the script wasn't being called with the correct environment. Fixes #175 +- Fix user_install resource bug where the script wasn't being called with the + correct environment. Fixes #175 ## 2.0.0 (2017-07-24) - Switch libraries to custom resources - Use gem install from core Chef - Add rbenv_system_install resource -- Remove system_install recipe. Please see the system_install test recipe for usage. +- Remove system_install recipe. Please see the system_install test recipe for + usage. - Remove user_install recipe. Please see the user_install test recipe for usage. - Removed all other recipes for consistent usage. - Remove FreeBSD "support" (the platform isn't currently tested) -- Remove Arch Linux support in README. We never really supported this, and it isn't tested +- Remove Arch Linux support in README. We never really supported this, and it + isn't tested - Update required chef-version to the one we test with (Chef 12.19+) ### Known Current Bugs -- Installing Ruby 2.3.1 on Fedora requires a patched version of 2.3.1\. As patching is currently unavailable please pin to a prior version if you need this installing. +- Installing Ruby 2.3.1 on Fedora requires a patched version of 2.3.1\. As + patching is currently unavailable please pin to a prior version if you need + this installing. ## 1.2.1 (2017-06-23) @@ -80,16 +92,21 @@ This file is used to list changes made in each version of the ruby_rbenv cookboo ## 1.2.0 (2017-04-11) - Migrated maintenance of this cookbook to Sous Chefs -- Remove the check to see if the homebrew provider exists since this always exists in Chef 12 and the code failed on Chef 13 -- Added checks to user install recipes to avoid breaking if the rbenv_home does not exist +- Remove the check to see if the homebrew provider exists since this always + exists in Chef 12 and the code failed on Chef 13 +- Added checks to user install recipes to avoid breaking if the rbenv_home does + not exist - Removed test deps from the Gemfile as we should be testing with ChefDK -- Removed the "suggests 'java'" metadata as suggests was never implemented in Chef and has been removed from Chef 13 +- Removed the "suggests 'java'" metadata as suggests was never implemented in + Chef and has been removed from Chef 13 - Bumped the required Chef release from 12.0 to 12.1 ## 1.1.0 (2016-06-17) -- Restored compatibility for platforms that don't yet support multipackage installs in Chef (BSD and OS X in particular) -- Updated to Grab rbenv from the new repo URL and use https vs. git for compatibility +- Restored compatibility for platforms that don't yet support multipackage + installs in Chef (BSD and OS X in particular) +- Updated to Grab rbenv from the new repo URL and use https vs. git for + compatibility - Added missing Chefspec matchers - Enabled use_inline_resources in all providers - Added chef_version metadata to metadata.rb @@ -107,25 +124,36 @@ This file is used to list changes made in each version of the ruby_rbenv cookboo ### WARNING: Cookbook has been renamed -- Renamed to ruby_rbenv and uploaded to Supermarket (all attributes rename in the rbenv cookbook). If you wrap this cookbook you're going to need to update the recipes you include. All providers have been updated to keep their existing rbenv_xyz names for backwards compatibility and attributes still maintain the rbenv namespace. +- Renamed to ruby_rbenv and uploaded to Supermarket (all attributes rename in + the rbenv cookbook). If you wrap this cookbook you're going to need to update + the recipes you include. All providers have been updated to keep their + existing rbenv_xyz names for backwards compatibility and attributes still + maintain the rbenv namespace. - Updated Travis config to run integration tests in Travis using kitchen-docker ## 0.9.0 (2015-10-12) -- Fixed base platform case statement in the cookbook that set install_pkgs and user_home_root attributes. This has been converted to a platform_family statement to better support derivitive operating systems and the attributes are set at default levels so they can be overwritten in wrapper cookbooks +- Fixed base platform case statement in the cookbook that set install_pkgs and + user_home_root attributes. This has been converted to a platform_family + statement to better support derivitive operating systems and the attributes + are set at default levels so they can be overwritten in wrapper cookbooks - Updated Travis to test using Chef DK vs. Gem installs - Fixed Chefspecs and Test Kitchen bats tests to all pass - Added the Apache 2.0 license file - Updated and added new development dependencies to the Gemfile -- Use Chef 12.1+ multi-package installs for the dependency packages to speed up installs +- Use Chef 12.1+ multi-package installs for the dependency packages to speed up + installs - Removed the empty Vagrant recipe -- Actually depend on ruby_version vs. suggests since suggests isn't implemented in Chef +- Actually depend on ruby_version vs. suggests since suggests isn't implemented + in Chef ## 0.8.1 (2015-08-28) -- Add rbenv_action attribute to rbenv_ruby LWRP so to allow using rvm-download rbenv plugin to download ruby vs. installing ruby +- Add rbenv_action attribute to rbenv_ruby LWRP so to allow using rvm-download + rbenv plugin to download ruby vs. installing ruby - Fix the ability to install gems to a specific version of ruby -- Remove Chef version checks around use_inline_resources since we require Chef 12 +- Remove Chef version checks around use_inline_resources since we require Chef + 12 - Use default_action method in the LWRPs - Fix various rubocop warnings @@ -137,59 +165,90 @@ This file is used to list changes made in each version of the ruby_rbenv cookboo ## 0.7.3 (2015-07-8) -- Issue [#91](https://github.com/fnichol/chef-rbenv/issues/91) [#79](https://github.com/fnichol/chef-rbenv/issues/79) [#92](https://github.com/fnichol/chef-rbenv/pull/92): Add matchers for rbenv_gem and rbenv_ruby. ([@tduffield](https://github.com/tduffield) and many others) -- Issue [#107](https://github.com/fnichol/chef-rbenv/issues/107): "Option name must be a kind of String!" when installing gems. -- Issue [#101](https://github.com/fnichol/chef-rbenv/issues/101): Use full class name for rbenv_rehash resource -- Fix undefined method `timeout' for LWRP resource rbenv_gem. ([@nathantsoi](https://github.com/nathantsoi) and others) -- Issue [#110](https://github.com/fnichol/chef-rbenv/issues/110): Chef 12.3.0 - undefined method `clear_sources' for Chef::Resource::RbenvGem. ([@tatat](https://github.com/tatat) and others) +- Issue [#91](https://github.com/fnichol/chef-rbenv/issues/91) + [#79](https://github.com/fnichol/chef-rbenv/issues/79) + [#92](https://github.com/fnichol/chef-rbenv/pull/92): Add matchers for + rbenv_gem and rbenv_ruby. ([@tduffield](https://github.com/tduffield) and + many others) +- Issue [#107](https://github.com/fnichol/chef-rbenv/issues/107): "Option name + must be a kind of String!" when installing gems. +- Issue [#101](https://github.com/fnichol/chef-rbenv/issues/101): Use full + class name for rbenv_rehash resource +- Fix undefined method `timeout' for LWRP resource rbenv_gem. + ([@nathantsoi](https://github.com/nathantsoi) and others) +- Issue [#110](https://github.com/fnichol/chef-rbenv/issues/110): Chef 12.3.0 - + undefined method `clear_sources' for Chef::Resource::RbenvGem. + ([@tatat](https://github.com/tatat) and others) - Fork from ## 0.7.2 (2012-12-31) -- Pull request [#26](https://github.com/fnichol/chef-rbenv/pull/26): Don't call libexec commands directly. ([@mhoran]) +- Pull request [#26](https://github.com/fnichol/chef-rbenv/pull/26): Don't call + libexec commands directly. ([@mhoran]) - Add integration tests for a system Ruby version. ([@fnichol]) ## 0.7.1 (unreleased) -- Pull request [#36](https://github.com/fnichol/chef-rbenv/pull/36): Use the ruby name as the definition to install ([@gsandie]) -- Pull request [#55](https://github.com/fnichol/chef-rbenv/pull/55): Fix some CHEF-3694 warnings when using with ruby_build ([@trinitronx]) +- Pull request [#36](https://github.com/fnichol/chef-rbenv/pull/36): Use the + ruby name as the definition to install ([@gsandie]) +- Pull request [#55](https://github.com/fnichol/chef-rbenv/pull/55): Fix some + CHEF-3694 warnings when using with ruby_build ([@trinitronx]) ### New features -- Pull request [#26](https://github.com/fnichol/chef-rbenv/pull/26): Allow setting environment vars per ruby install ([@jasherai]) -- Pull request [#37](https://github.com/fnichol/chef-rbenv/pull/37): Allows use `include_recipe("ruby_build")` instead of having to put it in the `run_list` ([@tjwallace]) -- Pull request [#42](https://github.com/fnichol/chef-rbenv/pull/42): Load rbenv environment after install ([@msaffitz]) -- Pull request [#62](https://github.com/fnichol/chef-rbenv/pull/62): Add Gentoo as supported platform ([@gentooboontoo]) -- Pull request [#46](https://github.com/fnichol/chef-rbenv/pull/46): Add a `definition_file` attribute to the `rbenv_ruby` resource to prevent continually trying to build a custom ruby when passed a build file name instead of a built-in definition ([@jf647]) -- Pull request [#60](https://github.com/fnichol/chef-rbenv/pull/60): Support `definition_file` in rubies definition ([@cyu]) -- Pull request [#75](https://github.com/fnichol/chef-rbenv/pull/75): Update testing support and add unit tests for existing resources ([@fnichol]) -- Pull request [#70](https://github.com/fnichol/chef-rbenv/pull/70): Support ruby 2.1.0 ([@WhyEee]) +- Pull request [#26](https://github.com/fnichol/chef-rbenv/pull/26): Allow + setting environment vars per ruby install ([@jasherai]) +- Pull request [#37](https://github.com/fnichol/chef-rbenv/pull/37): Allows use + `include_recipe("ruby_build")` instead of having to put it in the `run_list` + ([@tjwallace]) +- Pull request [#42](https://github.com/fnichol/chef-rbenv/pull/42): Load rbenv + environment after install ([@msaffitz]) +- Pull request [#62](https://github.com/fnichol/chef-rbenv/pull/62): Add Gentoo + as supported platform ([@gentooboontoo]) +- Pull request [#46](https://github.com/fnichol/chef-rbenv/pull/46): Add a + `definition_file` attribute to the `rbenv_ruby` resource to prevent + continually trying to build a custom ruby when passed a build file name + instead of a built-in definition ([@jf647]) +- Pull request [#60](https://github.com/fnichol/chef-rbenv/pull/60): Support + `definition_file` in rubies definition ([@cyu]) +- Pull request [#75](https://github.com/fnichol/chef-rbenv/pull/75): Update + testing support and add unit tests for existing resources ([@fnichol]) +- Pull request [#70](https://github.com/fnichol/chef-rbenv/pull/70): Support + ruby 2.1.0 ([@WhyEee]) ## 0.7.0 (2012-11-21) -- Issue [#14](https://github.com/fnichol/chef-rbenv/pull/14): Create /etc/profile.d on system-wide and add note for Mac. ([@fnichol]) -- Pull request [#20](https://github.com/fnichol/chef-rbenv/pull/20): Set an attribute to create profile.d for user install. ([@jtimberman]) -- Pull request [#12](https://github.com/fnichol/chef-rbenv/pull/12): Add name attribute to metadata. ([@jtimberman]) +- Issue [#14](https://github.com/fnichol/chef-rbenv/pull/14): Create + `/etc/profile.d` on system-wide and add note for Mac. ([@fnichol]) +- Pull request [#20](https://github.com/fnichol/chef-rbenv/pull/20): Set an + attribute to create profile.d for user install. ([@jtimberman]) +- Pull request [#12](https://github.com/fnichol/chef-rbenv/pull/12): Add name + attribute to metadata. ([@jtimberman]) - Update foodcritic configuration and update .travis.yml. ([@fnichol]) - Update Installation section of README (welcome Berkshelf). ([@fnichol]) ## 0.6.10 (2012-05-18) -- Pull request [#11](https://github.com/fnichol/chef-rbenv/pull/11): Add FreeBSD support. ([@jssjr]) +- Pull request [#11](https://github.com/fnichol/chef-rbenv/pull/11): Add FreeBSD + support. ([@jssjr]) - Add other platform supports in metadata.rb and README. ([@fnichol]) ## 0.6.8 (2012-05-06) -- Add official hook resource `log[rbenv-post-init-*]` for inter-cookbook integration. ([@fnichol]) +- Add official hook resource `log[rbenv-post-init-*]` for inter-cookbook + integration. ([@fnichol]) ## 0.6.6 (2012-05-04) -- Fix FC022: Resource condition within loop may not behave as expected. ([@fnichol]) +- Fix FC022: Resource condition within loop may not behave as expected. + ([@fnichol]) - Add plaform equivalents in default attrs (FC024). ([@fnichol]) - Ensure update-java-alternatives is called before JRuby is built. ([@fnichol]) -- Pull request [#8](https://github.com/fnichol/chef-rbenv/pull/8): Add /etc/profile.d/rbenv.sh support for user installs. ([@thoughtless]) +- Pull request [#8](https://github.com/fnichol/chef-rbenv/pull/8): Add + `/etc/profile.d/rbenv.sh` support for user installs. ([@thoughtless]) - Add TravisCI to run Foodcritic linter. ([@fnichol]) -- Pull request [#10](https://github.com/fnichol/chef-rbenv/pull/10): README proofreading. ([@jdsiegel]) +- Pull request [#10](https://github.com/fnichol/chef-rbenv/pull/10): README + proofreading. ([@jdsiegel]) - README updates. ([@fnichol]) - Confirm debian platform support. ([@fnichol]) @@ -201,11 +260,16 @@ This file is used to list changes made in each version of the ruby_rbenv cookboo ## 0.6.2 (2012-02-22) -- Issues [#1](https://github.com/fnichol/chef-rbenv/issues/1), [#2](https://github.com/fnichol/chef-rbenv/issues/2): Stub mixins in RbenvRubygems to avoid libraries load ordering issues. ([@fnichol]) -- Pull request [#5](https://github.com/fnichol/chef-rbenv/pull/5): Include user setting in rehash calls. ([@magnetised]) -- Issue [#4](https://github.com/fnichol/chef-rbenv/issues/4): Fix rbenv/gems hash parsing. ([@fnichol]) +- Issues [#1](https://github.com/fnichol/chef-rbenv/issues/1), + [#2](https://github.com/fnichol/chef-rbenv/issues/2): Stub mixins in + RbenvRubygems to avoid libraries load ordering issues. ([@fnichol]) +- Pull request [#5](https://github.com/fnichol/chef-rbenv/pull/5): Include user + setting in rehash calls. ([@magnetised]) +- Issue [#4](https://github.com/fnichol/chef-rbenv/issues/4): Fix rbenv/gems + hash parsing. ([@fnichol]) - Large formatting updates to README. ([@fnichol]) -- Add gh-pages branch for sectioned README at +- Add gh-pages branch for sectioned README at + ## 0.6.0 (2011-12-21) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ad60f136..d739dbcc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,9 +3,22 @@ We are glad you want to contribute to the sysctl cookbook! The first step is the desire to improve the project. +## Recognizing All Contributors + +This project follows the +[All Contributors](https://allcontributors.org/docs/en/overview) specification +for recognizing contributors to an open source project in a way that recognizes +different types of contributions, not just code. + +### Adding a contributor + +Contributors are encouraged to add themselves to the list using the +[All Contributors (Git Hub) bot](https://allcontributors.org/docs/en/bot/overview). +See the bot [usage instructions](https://allcontributors.org/docs/en/bot/usage)). + ## Quick-contribute -* Create an issue on the github [issue tracker](https://github.com/sous-chefs/sysctl/issues) +* Create an issue on the github [issue tracker](https://github.com/jlenv/jlenv/issues) * Link to your patch as a rebased git branch or pull request from the ticket We regularly review contributions and will get back to you if we have @@ -16,8 +29,8 @@ any suggestions or concerns. You should submit your patch as a git branch named after the change. It is a best practice to have your commit message have a _summary -line_, followed by an empty line and then a brief description of -the commit. This also helps other contributors understand the +line_, followed by an empty line and then a brief description of +the commit. This also helps other contributors understand the purpose of changes to the code. Remember that not all users use Chef in the same way or on the same @@ -35,12 +48,22 @@ downloading the branch. ## Functional and Unit Tests -This cookbook is set up to run tests under [test-kitchen](https://kitchen.ci/). It -uses serverspec to run integration tests after the node has been -converged to verify that the state of the node. +This cookbook is set up to: + +1. Run lint and unit test with [delivery](https://github.com/chef/delivery-cli). + Uses `delivery local ` to tun lint and unit tests locally. +1. Run integration tests with [test-kitchen](https://kitchen.ci/). + It uses serverspec to run integration tests after the node has been + converged to verify that the state of the node. + +For faster testing, we use [Dokken](https://github.com/someara/kitchen-dokken) kitchen file, invoked by: + +``` +KITECHEN_YAML=.kitchen.dokken.yml kitchen test +``` Test kitchen should run completely without exception using the default -[baseboxes provided by Chef](http://opscode.github.io/bento/). +[containers provided by Dokken](https://hub.docker.com/u/dokken/). Because Test Kitchen creates VirtualBox machines and runs through every configuration in the .kitchen.yml file, it may take some time for these tests to complete. @@ -68,6 +91,17 @@ for it. If you need help writing tests, please ask on the Chef Developer's mailing list, or the #chef-hacking IRC channel. +Test kitchen can be run using the default +[baseboxes provided by Chef](http://opscode.github.io/bento/): + +``` +KITECHEN_YAML=.kitchen.vagrant.yml kitchen test +``` + +Because Test Kitchen creates VirtualBox machines and runs through +every configuration in the .kitchen.yml file, it may take some time for +these tests to complete. + ## Cookbook Contribution Do's and Don't's Please do include tests for your contribution. If you need help, ask @@ -81,8 +115,9 @@ isn't trivial so we don't have to duplicate effort in testing. Chef 10.14+ "doc" formatted output is sufficient. Please do indicate new platform (families) or platform versions in the -commit message, and update the relevant ticket. If a contribution adds -new platforms or platform versions, indicate such in the body of the commit message(s). +commit message, and update the relevant ticket. If a contribution adds +new platforms or platform versions, indicate such in the body of the commit +message(s). Please do use [foodcritic](http://www.foodcritic.io/) to lint-check the cookbook. Except FC007, it should pass all correctness diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..c4673760 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,14 @@ +Copyright 2019 Mark Van de Vyver +Copyright 2019 TAQTIQA LLC + +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. diff --git a/Policyfile.rb b/Policyfile.rb new file mode 100644 index 00000000..aa59b599 --- /dev/null +++ b/Policyfile.rb @@ -0,0 +1,6 @@ +name 'jlenv' + +path = File.expand_path('policyfiles/base.rb', __dir__) +instance_eval(IO.read(path)) + +run_list 'jlenv::default' diff --git a/README.md b/README.md index ccd74b51..04e1b07a 100755 --- a/README.md +++ b/README.md @@ -1,19 +1,18 @@ -# Chef ruby_rbenv Cookbook -[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors) +# Chef Jlenv Cookbook -[![Cookbook Version](https://img.shields.io/cookbook/v/ruby_rbenv.svg)](https://supermarket.chef.io/cookbooks/ruby_rbenv) -[![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/ruby_rbenv/master.svg)](https://circleci.com/gh/sous-chefs/ruby_rbenv) -[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) -[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) +[![Cookbook Version](https://img.shields.io/cookbook/v/jlenv-cookbook.svg)](https://supermarket.chef.io/cookbooks/jlenv-cookbook) +[![Build Status](https://img.shields.io/circleci/project/github/jlenv/jlenv-cookbook/master.svg)](https://circleci.com/gh/jlenv/jlenv-cookbook) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) +[![CircleCI](https://circleci.com/gh/taqtiqa-mark/jlenv-cookbook.svg?style=svg)](https://circleci.com/gh/taqtiqa-mark/jlenv-cookbook) ## Description -Manages [rbenv][rbenv_site] and its installed Rubies. +Manages [jlenv](https://github.com/jlenv/jlenv) installed Julias. ## Maintainers -This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). +This cookbook is maintained by volunteers. +[All contributions and bug reports are welcome](./CONTRIBUTING). ## Requirements @@ -23,148 +22,176 @@ This cookbook requires Chef 13.0+. ### Platform -- Debian derivatives +- Debian derivatives (Ubuntu etc.) - Fedora - macOS (not currently tested) - RHEL derivatives (RHEL, CentOS, Amazon Linux, Oracle, Scientific Linux) - openSUSE and openSUSE leap +- Windows (not supported) -# Usage - -**Please read** +## Usage Example installations are provided in `test/fixtures/cookbooks/test/recipes/`. -A `rbenv_system_install` or `rbenv_user_install` is required to be set so that rbenv knows which version you want to use, and is installed on the system. +A `jlenv_user_install` is required to be set so that jlenv knows which version +you want to use, and is installed on the system. + +| **NOTE:** | +| System wide installations of jlenv are discouraged by the jlenv maintainer.| +|---| -System wide installations of rbenv are supported by this cookbook, but discouraged by the rbenv maintainer, see [these][rbenv_issue_38] [two][rbenv_issue_306] issues in the rbenv repository. +However they are supported by this cookbook, see +[these](https://github.com/rbenv/rbenv/issues/38/) +[two](https://github.com/rbenv/rbenv/issues/306/) issues in the rbenv repository +for the reasons why. -## Gem +## Package -Used to install a gem into the selected rbenv environment. +Used to install a package into the selected jlenv environment. ```ruby -rbenv_gem 'gem_name' do - options # Optional: Options to pass to the gem command e.g. '--no-rdoc --no-ri' +jlenv_package 'pkg_name' do + options # Optional: Options for the packagecommand e.g. '--no-rdoc --no-ri' source # Optional: source URL/location for gem. - timeout # Optional: Gem install timeout - version # Optional: Gem version to install + timeout # Optional: Pkg install timeout + version # Optional: Pkg version to install response_file # Optional: response file to reconfigure a gem - rbenv_version # Required: Which rbenv version to install the gem to. - user # Which user to install gem to. REQUIRED if you're using rbenv_user_install + jlenv_version # Required: Which jlenv version to install the packageto. + user # Which user to install for. REQUIRED if you're using jlenv_user_install end ``` ## Global -Sets the global ruby version. The name of the resource is the version to set. +Sets the global Julia version. The name of the resource is the version to set. ```ruby -rbenv_global '2.5.1' do - user # Optional: if passed sets the users global version. Leave unset, to set the system global version +jlenv_global '1.1.0' do + user # Optional: Sets the users global version. + # Leave unset, to set the system global version. end ``` -If a user is passed in to this resource it sets the global version for the user, under the users `root_path` (usually `~/.rbenv/version`), otherwise it sets the system global version. +If a user is passed in to this resource it sets the global version for the user, +under the users `root_path` (usually `~/.jlenv/version`), otherwise it sets the +system global version. ## Plugin -Installs a rbenv plugin. +Installs a jlenv plugin. ```ruby -rbenv_plugin 'ruby-build' do +jlenv_plugin 'julia-build' do git_url # Git URL of the plugin git_ref # Git reference of the plugin - user # Optional: if passed installs to the users rbenv. Do not set, to set installs to the system rbenv. + user # Optional: Install to the users jlenv. + # Do not set, to set installs to the system jlenv. end ``` -If user is passed in, the plugin is installed to the users install of rbenv. +If user is passed in, the plugin is installed to the users install of jlenv. ## Rehash ```ruby -rbenv_rehash 'rehash' do - user 'vagrant' # Optional: if passed rehashes the user Ruby otherwise rehashes the system rbenv +jlenv_rehash 'rehash' do + user 'vagrant' # Optional: Rehash the user jlenv otherwise rehash system jlenv end ``` -If user is passed in, the user Ruby is rehashed rather than the system Ruby. +If user is passed in, the user Julia is rehashed rather than the system Julia. -## Ruby +## Julia -Installs a given Ruby version to the system or user location. +Installs a given Julia version to the system or user location. ```ruby -rbenv_ruby '2.5.1' do - user # Optional, but recommended: If passed, the user to install rbenv to - rbenv_action # Optional: the action to perform, 'install' (default), 'uninstall' etc +jlenv_julia '1.1.0' do + user # Optional, but recommended: If passed, the user to install jlenv to + jlenv_action # Optional: Action to perform: + # 'install' (default), 'uninstall' etc. end ``` -Shorter example `rbenv_ruby '2.5.1'` +Shorter example `jlenv_julia '1.1.0'` ## Script -Runs a rbenv aware script. +Runs a jlenv aware script. ```ruby -rbenv_script 'foo' do - rbenv_version #rbenv version to run the script against - environment # Optional: A Hash of environment variables in the form of ({"ENV_VARIABLE" => "VALUE"}). +jlenv_script 'foo' do + jlenv_version #jlenv version to run the script against + environment # Optional: Hash of environment variables in the form of + # ({"ENV_VARIABLE" => "VALUE"}). user # Optional: User to run as group # Optional: Group to run as returns # Optional: Expected return code code # Script code to run end ``` + Note that environment overwrites the entire variable. For example. setting the `$PATH` variable can be done like this: + ```ruby -rbenv_script 'bundle package' do +jlenv_script 'bundle package' do cwd node["bundle_dir"] - environment ({"PATH" => "/usr/local/rbenv/shims:/usr/local/rbenv/bin:#{ENV["PATH"]}"}) + environment ({"PATH" => "/usr/local/jlenv/shims:/usr/local/jlenv/bin:#{ENV["PATH"]}"}) code "bundle package --all" end ``` -Where `#{ENV["PATH"]}` appends the existing PATH to the end of the newly set PATH. +Where `#{ENV["PATH"]}` appends the existing `PATH` to the end of the newly set +`PATH`. ## System_install -Installs rbenv to the system location, by default `/usr/local/rbenv` +Installs jlenv to the system location, by default `/usr/local/jlenv` ```ruby -rbenv_system_install 'foo' do +jlenv_system_install 'foo' do git_url # URL of the plugin repo you want to checkout git_ref # Optional: Git reference to checkout - update_rbenv # Optional: Keeps the git repo up to date + update_jlenv # Optional: Keeps the git repo up to date end ``` ## User_install -Installs rbenv to the user path, making rbenv available to that user only. +Installs jlenv to the user path, making jlenv available to that user only. ```ruby -rbenv_user_install 'vagrant' do - git_url # Optional: Git URL to checkout rbenv from. +jlenv_user_install 'vagrant' do + git_url # Optional: Git URL to checkout jlenv from. git_ref # Optional: Git reference to checkout e.g. 'master' - user # Which user to install rbenv to (also specified in the resources name above) + user # Which user to install jlenv to (also given in the resources name above) end ``` ## System-Wide macOS Installation Note -This cookbook takes advantage of managing profile fragments in an `/etc/profile.d` directory, common on most Unix-flavored platforms. Unfortunately, macOS does not support this idiom out of the box, so you may need to [modify][mac_profile_d] your user profile. +This cookbook takes advantage of managing profile fragments in an +`/etc/profile.d` directory, common on most Unix-flavored platforms. +Unfortunately, macOS does not support this idiom out of the box, so you may +need to [modify][mac_profile_d] your user profile. ## Development -- Source hosted at [GitHub][repo] -- Report issues/Questions/Feature requests on [GitHub Issues][issues] +- Source hosted at [GitHub](https://github.com/jlenv/jlenv-cookbook/) +- Report Issues/Questions/Feature requests on + [GitHub Issues](https://github.com/jlenv/jlenv-cookbook/issues) Pull requests are very welcome! Make sure your patches are well tested. +## Testing + +For local unit tests: + +```bash +delivery local +``` + ## Contributors @@ -172,25 +199,4 @@ Pull requests are very welcome! Make sure your patches are well tested.
Mark Van de Vyver
Mark Van de Vyver

🚇 ⚠️ 💻
-This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) - -### Backers - -Thank you to all our backers! - -![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) - -### Sponsors - -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. - -![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) +This project exists thanks to all the people who contribute. diff --git a/TESTING.md b/TESTING.md index 789e5e0e..9d42d98c 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,5 +1,9 @@ -Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD # Testing Please refer to the [community cookbook documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD). + +In addition, setup [Danger](https://github.com/danger/danger]) +([Ruby](https://danger.systems/ruby/]) +[JavaScript](https://danger.systems/js/), +[Swift](https://danger.systems/swift/), +for [use in CI](https://danger.systems/guides/getting_started.html). diff --git a/appveyor.yml b/appveyor.yml index 32fe8264..746d1f8b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,4 @@ +--- environment: machine_user: vagrant machine_pass: vagrant @@ -11,13 +12,13 @@ branches: # Do not build on tags (GitHub only) skip_tags: true -#faster cloning +# Faster cloning clone_depth: 1 # Install the latest nightly of ChefDK install: - - ps: iex (irm https://omnitruck.chef.io/install.ps1); Install-Project -Project chefdk -channel stable - - ps: 'Get-CimInstance win32_operatingsystem -Property Caption, OSArchitecture, Version | fl Caption, OSArchitecture, Version' + - ps: "iex (irm https://omnitruck.chef.io/install.ps1); Install-Project -Project chefdk -channel stable" + - ps: "Get-CimInstance win32_operatingsystem -Property Caption, OSArchitecture, Version | fl Caption, OSArchitecture, Version" - ps: $PSVersionTable - c:\opscode\chefdk\bin\chef.bat exec ruby --version - ps: secedit /export /cfg $env:temp/export.cfg @@ -36,4 +37,4 @@ test_script: - delivery local all - kitchen verify -deploy: off +deploy: false diff --git a/docs/CONDUCT.md b/docs/CONDUCT.md new file mode 100644 index 00000000..7cca28f8 --- /dev/null +++ b/docs/CONDUCT.md @@ -0,0 +1,4 @@ +# Requested Contributor Conduct + +In the interest of fostering an excellent code base, we try to encourage anyone +to participate in our project. Please do likewise. diff --git a/docs/LICENSE.md b/docs/LICENSE.md new file mode 100644 index 00000000..c4673760 --- /dev/null +++ b/docs/LICENSE.md @@ -0,0 +1,14 @@ +Copyright 2019 Mark Van de Vyver +Copyright 2019 TAQTIQA LLC + +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. diff --git a/docs/README.md b/docs/README.md new file mode 100755 index 00000000..569f3336 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,204 @@ +# Chef Jlenv Cookbook + +[![Cookbook Version](https://img.shields.io/cookbook/v/jlenv-cookbook.svg)](https://supermarket.chef.io/cookbooks/jlenv-cookbook) +[![Build Status](https://img.shields.io/circleci/project/github/jlenv/jlenv-cookbook/master.svg)](https://circleci.com/gh/jlenv/jlenv-cookbook) +[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) +[![CircleCI](https://circleci.com/gh/taqtiqa-mark/jlenv-cookbook.svg?style=svg)](https://circleci.com/gh/taqtiqa-mark/jlenv-cookbook) +[![CodeFactor](https://www.codefactor.io/repository/github/jlenv/jlenv-cookbook/badge)](https://www.codefactor.io/repository/github/jlenv/jlenv-cookbook) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/59d2b1d6ca64492cba22fd99517beaec)](https://www.codacy.com/manual/taqtiqa-mark/jlenv-jlenv-cookbook?utm_source=github.com&utm_medium=referral&utm_content=jlenv/jlenv-cookbook&utm_campaign=Badge_Grade) + +## Description + +Manages [jlenv](https://github.com/jlenv/jlenv) installed Julias. + +## Maintainers + +This cookbook is maintained by volunteers. +[All contributions and bug reports are welcome](./CONTRIBUTING). + +## Requirements + +### Chef + +This cookbook requires Chef 13.0+. + +### Platform + +- Debian derivatives (Ubuntu etc.) +- Fedora +- macOS (not currently tested) +- RHEL derivatives (RHEL, CentOS, Amazon Linux, Oracle, Scientific Linux) +- openSUSE and openSUSE leap +- Windows (not supported) + +## Usage + +Example installations are provided in `test/fixtures/cookbooks/test/recipes/`. + +A `jlenv_user_install` is required to be set so that jlenv knows which version +you want to use, and is installed on the system. + +| **NOTE:** | +| System wide installations of jlenv are discouraged by the jlenv maintainer.| +|---| + +However they are supported by this cookbook, see +[these](https://github.com/rbenv/rbenv/issues/38/) +[two](https://github.com/rbenv/rbenv/issues/306/) issues in the rbenv repository +for the reasons why. + +## Package + +Used to install a package into the selected jlenv environment. + +```ruby +jlenv_package 'pkg_name' do + options # Optional: Options for the packagecommand e.g. '--no-rdoc --no-ri' + source # Optional: source URL/location for gem. + timeout # Optional: Pkg install timeout + version # Optional: Pkg version to install + response_file # Optional: response file to reconfigure a gem + jlenv_version # Required: Which jlenv version to install the packageto. + user # Which user to install for. REQUIRED if you're using jlenv_user_install +end +``` + +## Global + +Sets the global Julia version. The name of the resource is the version to set. + +```ruby +jlenv_global '1.1.0' do + user # Optional: Sets the users global version. + # Leave unset, to set the system global version. +end +``` + +If a user is passed in to this resource it sets the global version for the user, +under the users `root_path` (usually `~/.jlenv/version`), otherwise it sets the +system global version. + +## Plugin + +Installs a jlenv plugin. + +```ruby +jlenv_plugin 'julia-build' do + git_url # Git URL of the plugin + git_ref # Git reference of the plugin + user # Optional: Install to the users jlenv. + # Do not set, to set installs to the system jlenv. +end +``` + +If user is passed in, the plugin is installed to the users install of jlenv. + +## Rehash + +```ruby +jlenv_rehash 'rehash' do + user 'vagrant' # Optional: Rehash the user jlenv otherwise rehash system jlenv +end +``` + +If user is passed in, the user Julia is rehashed rather than the system Julia. + +## Julia + +Installs a given Julia version to the system or user location. + +```ruby +jlenv_julia '1.1.0' do + user # Optional, but recommended: If passed, the user to install jlenv to + jlenv_action # Optional: Action to perform: + # 'install' (default), 'uninstall' etc. +end +``` + +Shorter example `jlenv_julia '1.1.0'` + +## Script + +Runs a jlenv aware script. + +```ruby +jlenv_script 'foo' do + jlenv_version #jlenv version to run the script against + environment # Optional: Hash of environment variables in the form of + # ({"ENV_VARIABLE" => "VALUE"}). + user # Optional: User to run as + group # Optional: Group to run as + returns # Optional: Expected return code + code # Script code to run +end +``` + +Note that environment overwrites the entire variable. +For example. setting the `$PATH` variable can be done like this: + +```ruby +jlenv_script 'bundle package' do + cwd node["bundle_dir"] + environment ({"PATH" => "/usr/local/jlenv/shims:/usr/local/jlenv/bin:#{ENV["PATH"]}"}) + code "bundle package --all" +end +``` + +Where `#{ENV["PATH"]}` appends the existing `PATH` to the end of the newly set +`PATH`. + +## System_install + +Installs jlenv to the system location, by default `/usr/local/jlenv` + +```ruby +jlenv_system_install 'foo' do + git_url # URL of the plugin repo you want to checkout + git_ref # Optional: Git reference to checkout + update_jlenv # Optional: Keeps the git repo up to date +end +``` + +## User_install + +Installs jlenv to the user path, making jlenv available to that user only. + +```ruby +jlenv_user_install 'vagrant' do + git_url # Optional: Git URL to checkout jlenv from. + git_ref # Optional: Git reference to checkout e.g. 'master' + user # Which user to install jlenv to (also given in the resources name above) +end +``` + +## System-Wide macOS Installation Note + +This cookbook takes advantage of managing profile fragments in an +`/etc/profile.d` directory, common on most Unix-flavored platforms. +Unfortunately, macOS does not support this idiom out of the box, so you may +need to [modify][mac_profile_d] your user profile. + +## Development + +- Source hosted at [GitHub](https://github.com/jlenv/jlenv-cookbook/) +- Report Issues/Questions/Feature requests on + [GitHub Issues](https://github.com/jlenv/jlenv-cookbook/issues) + +Pull requests are very welcome! Make sure your patches are well tested. + +## Testing + +For local unit tests: + +```bash +delivery local +``` + +## Contributors + + + +
Mark Van de Vyver
Mark Van de Vyver

🚇 ⚠️ 💻
+ + +This project exists thanks to all the people who contribute. diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 00000000..db103554 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,19 @@ +--- +title: `jlenv` Chef Cookbook +email: mark@taqtiqa.com +description: > # this means to ignore newlines until "baseurl:" + Build, install and manage multiple versions of [Julia].(https://www.julialang.org/). +github_username: jlenv +include_related_posts: true +plugins: + - jekyll-relative-links +relative_links: + enabled: true + collections: true +include: + - README.md + - LICENSE.md + - ISSUE_TEMPLATE.md + - PULL_REQUEST_TEMPLATE.md + - CONTRIBUTING.md + - CONDUCT.md diff --git a/gh-md-toc b/gh-md-toc new file mode 100755 index 00000000..792d6ff5 --- /dev/null +++ b/gh-md-toc @@ -0,0 +1,281 @@ +#!/usr/bin/env bash + +# +# Steps: +# +# 1. Download corresponding html file for some README.md: +# curl -s $1 +# +# 2. Discard rows where no substring 'user-content-' (github's markup): +# awk '/user-content-/ { ... +# +# 3.1 Get last number in each row like ' ... sitemap.js.*<\/h/)+2, RLENGTH-5) +# +# 5. Find anchor and insert it inside "(...)": +# substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) +# + +gh_toc_version="0.6.1" + +gh_user_agent="gh-md-toc v$gh_toc_version" + +# +# Download rendered into html README.md by its url. +# +# +gh_toc_load() { + local gh_url=$1 + + if type curl &>/dev/null; then + curl --user-agent "$gh_user_agent" -s "$gh_url" + elif type wget &>/dev/null; then + wget --user-agent="$gh_user_agent" -qO- "$gh_url" + else + echo "Please, install 'curl' or 'wget' and try again." + exit 1 + fi +} + +# +# Converts local md file into html by GitHub +# +# ➥ curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown +#

Hello world github/linguist#1 cool, and #1!

'" +gh_toc_md2html() { + local gh_file_md=$1 + URL=https://api.github.com/markdown/raw + if [ ! -z "$GH_TOC_TOKEN" ]; then + TOKEN=$GH_TOC_TOKEN + else + TOKEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" + fi + if [ -f "$TOKEN" ]; then + URL="$URL?access_token=$(cat $TOKEN)" + fi + # echo $URL 1>&2 + OUTPUT="$(curl -s --user-agent "$gh_user_agent" \ + --data-binary @"$gh_file_md" -H "Content-Type:text/plain" \ + $URL)" + + if [ "$?" != "0" ]; then + echo "XXNetworkErrorXX" + fi + if [ "$(echo "${OUTPUT}" | awk '/API rate limit exceeded/')" != "" ]; then + echo "XXRateLimitXX" + else + echo "${OUTPUT}" + fi +} + + +# +# Is passed string url +# +gh_is_url() { + case $1 in + https* | http*) + echo "yes";; + *) + echo "no";; + esac +} + +# +# TOC generator +# +gh_toc(){ + local gh_src=$1 + local gh_src_copy=$1 + local gh_ttl_docs=$2 + local need_replace=$3 + + if [ "$gh_src" = "" ]; then + echo "Please, enter URL or local path for a README.md" + exit 1 + fi + + + # Show "TOC" string only if working with one document + if [ "$gh_ttl_docs" = "1" ]; then + + echo "Table of Contents" + echo "=================" + echo "" + gh_src_copy="" + + fi + + if [ "$(gh_is_url "$gh_src")" == "yes" ]; then + gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy" + if [ "${PIPESTATUS[0]}" != "0" ]; then + echo "Could not load remote document." + echo "Please check your url or network connectivity" + exit 1 + fi + if [ "$need_replace" = "yes" ]; then + echo + echo "!! '$gh_src' is not a local file" + echo "!! Can't insert the TOC into it." + echo + fi + else + local rawhtml=$(gh_toc_md2html "$gh_src") + if [ "$rawhtml" == "XXNetworkErrorXX" ]; then + echo "Parsing local markdown file requires access to github API" + echo "Please make sure curl is installed and check your network connectivity" + exit 1 + fi + if [ "$rawhtml" == "XXRateLimitXX" ]; then + echo "Parsing local markdown file requires access to github API" + echo "Error: You exceeded the hourly limit. See: https://developer.github.com/v3/#rate-limiting" + TOKEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" + echo "or place github auth token here: $TOKEN" + exit 1 + fi + local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy"` + echo "$toc" + if [ "$need_replace" = "yes" ]; then + if grep -Fxq "" $gh_src && grep -Fxq "" $gh_src; then + echo "Found markers" + else + echo "You don't have or in your file...exiting" + exit 1 + fi + local ts="<\!--ts-->" + local te="<\!--te-->" + local dt=`date +'%F_%H%M%S'` + local ext=".orig.${dt}" + local toc_path="${gh_src}.toc.${dt}" + local toc_footer="" + # http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html + # clear old TOC + sed -i${ext} "/${ts}/,/${te}/{//!d;}" "$gh_src" + # create toc file + echo "${toc}" > "${toc_path}" + echo -e "\n${toc_footer}\n" >> "$toc_path" + # insert toc file + if [[ "`uname`" == "Darwin" ]]; then + sed -i "" "/${ts}/r ${toc_path}" "$gh_src" + else + sed -i "/${ts}/r ${toc_path}" "$gh_src" + fi + echo + echo "!! TOC was added into: '$gh_src'" + echo "!! Origin version of the file: '${gh_src}${ext}'" + echo "!! TOC added into a separate file: '${toc_path}'" + echo + fi + fi +} + +# +# Grabber of the TOC from rendered html +# +# $1 — a source url of document. +# It's need if TOC is generated for multiple documents. +# +gh_toc_grab() { + # if closed is on the new line, then move it on the prev line + # for example: + # was: The command foo1 + # + # became: The command foo1 + sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' | + # find strings that corresponds to template + grep -E -o '//g' | sed 's/<\/code>//g' | + # now all rows are like: + # ... .*<\/h/)+2, RLENGTH-5) + href = substr($0, match($0, "href=\"[^\"]+?\"")+6, RLENGTH-7) + print sprintf("%*s", level*3, " ") "* [" text "](" gh_url href ")" }' | + sed 'y/+/ /; s/%/\\x/g')" +} + +# +# Returns filename only from full path or url +# +gh_toc_get_filename() { + echo "${1##*/}" +} + +# +# Options hendlers +# +gh_toc_app() { + local need_replace="no" + + if [ "$1" = '--help' ] || [ $# -eq 0 ] ; then + local app_name=$(basename "$0") + echo "GitHub TOC generator ($app_name): $gh_toc_version" + echo "" + echo "Usage:" + echo " $app_name [--insert] src [src] Create TOC for a README file (url or local path)" + echo " $app_name - Create TOC for markdown from STDIN" + echo " $app_name --help Show help" + echo " $app_name --version Show version" + return + fi + + if [ "$1" = '--version' ]; then + echo "$gh_toc_version" + echo + echo "os: `lsb_release -d | cut -f 2`" + echo "kernel: `cat /proc/version`" + echo "shell: `$SHELL --version`" + echo + for tool in curl wget grep awk sed; do + printf "%-5s: " $tool + echo `$tool --version | head -n 1` + done + return + fi + + if [ "$1" = "-" ]; then + if [ -z "$TMPDIR" ]; then + TMPDIR="/tmp" + elif [ -n "$TMPDIR" -a ! -d "$TMPDIR" ]; then + mkdir -p "$TMPDIR" + fi + local gh_tmp_md + gh_tmp_md=$(mktemp $TMPDIR/tmp.XXXXXX) + while read input; do + echo "$input" >> "$gh_tmp_md" + done + gh_toc_md2html "$gh_tmp_md" | gh_toc_grab "" + return + fi + + if [ "$1" = '--insert' ]; then + need_replace="yes" + shift + fi + + for md in "$@" + do + echo "" + gh_toc "$md" "$#" "$need_replace" + done + + echo "" + echo "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)" +} + +# +# Entry point +# +gh_toc_app "$@" diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 45fdb3b8..0cdc272a 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -1,10 +1,12 @@ # -# Cookbook:: ruby_rbenv -# Library:: Chef::Rbenv::ShellHelpers +# Cookbook:: jlenv +# Library:: Chef::Jlenv::ShellHelpers # # Author:: Fletcher Nichol +# Author:: Mark Van de Vyver # # Copyright:: 2011-2017, Fletcher Nichol +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,15 +20,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # +require_relative 'lib/chef/provider/git_ext' class Chef - module Rbenv + module Jlenv module Helpers def wrap_shim_cmd(cmd) - [%(export RBENV_ROOT="#{rbenv_root}"), - %(export PATH="$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH"), - %(export RBENV_VERSION="#{new_resource.rbenv_version}"), - %($RBENV_ROOT/shims/#{cmd}), + [%(export JLENV_ROOT="#{jlenv_root}"), + %(export PATH="$JLENV_ROOT/bin:$JLENV_ROOT/shims:$PATH"), + %(export JLENV_VERSION="#{new_resource.jlenv_version}"), + %($JLENV_ROOT/shims/#{cmd}), ].join(' && ') end @@ -40,29 +43,29 @@ def root_path end end - def which_rbenv + def which_jlenv "(#{new_resource.user || 'system'})" end def binary prefix = new_resource.user ? "sudo -u #{new_resource.user} " : '' - "#{prefix}#{root_path}/versions/#{new_resource.rbenv_version}/bin/gem" + "#{prefix}#{root_path}/versions/#{new_resource.jlenv_version}/bin/gem" end def script_code script = [] - script << %(export RBENV_ROOT="#{root_path}") - script << %(export PATH="${RBENV_ROOT}/bin:$PATH") - script << %{eval "$(rbenv init -)"} - if new_resource.rbenv_version - script << %(export RBENV_VERSION="#{new_resource.rbenv_version}") + script << %(export JLENV_ROOT="#{root_path}") + script << %(export PATH="${JLENV_ROOT}/bin:$PATH") + script << %{eval "$(jlenv init -)"} + if new_resource.jlenv_version + script << %(export JLENV_VERSION="#{new_resource.jlenv_version}") end script << new_resource.code script.join("\n").concat("\n") end def script_environment - script_env = { 'RBENV_ROOT' => root_path } + script_env = { 'JLENV_ROOT' => root_path } script_env.merge!(new_resource.environment) if new_resource.environment @@ -83,7 +86,17 @@ def package_prerequisites when 'rhel', 'fedora', 'amazon' %w(git grep tar) when 'debian', 'suse' - %w(git grep) + case node['platform'] + when 'ubuntu' + case node['platform_version'] + when '18.04' + %w(git grep) + else + %w(git grep) + end + else + %w(git grep) + end when 'mac_os_x', 'gentoo' %w(git) when 'freebsd' @@ -93,7 +106,7 @@ def package_prerequisites end end - def ruby_installed? + def julia_installed? if Array(new_resource.action).include?(:reinstall) return false elsif ::File.directory?(::File.join(root_path, 'versions', new_resource.version)) diff --git a/libraries/lib/chef/provider/git_ext.rb b/libraries/lib/chef/provider/git_ext.rb new file mode 100644 index 00000000..a6b85295 --- /dev/null +++ b/libraries/lib/chef/provider/git_ext.rb @@ -0,0 +1,139 @@ +# +# https://blog.daveallie.com/clean-monkey-patching/ + +module GitExt + + def self.prepended(base) + base.singleton_class.prepend(ClassMethods) + end + + module ClassMethods + # Placeholder + end + + # Resolve SHA values given references such as, (ordered): + # 1. tags first: "refs/tags/" + # 2. then heads: "refs/heads/" + # 3. then revisions: "refs/pulls/v1.0" + # spec tests: + # 1. v1.0^{} i.e. converts from an annotated tag to the tagged SHA (not SHA of tag) + # 2. v1.0 + # 3. v1.0 returns refs/tags/v1.0 before refs/tags/releases/v1.0 + # 4. refs/heads/v1.0 is accepted, etc + # 5. "origin/" raises Chef::Exceptions::InvalidRemoteGitReference + # 6. "junk" raises Chef::Exceptions::UnresolvableGitReference + # 7. "" Returns HEAD SHA + # + # bash implmentation logic: + # git_ref_type() { + # [ -n "$1" ] || die "Missing ref name" + # if git show-ref -q --verify "refs/tags/$1" 2>/dev/null; then + # echo "tag" + # elif git show-ref -q --verify "refs/heads/$1" 2>/dev/null; then + # echo "branch" + # elif git show-ref -q --verify "refs/pulls/$1" 2>/dev/null; then + # echo "revision" + # elif git show-ref -q --verify "refs/remote/$1" 2>/dev/null; then + # echo "remote" + # elif git rev-parse --verify "$1^{commit}" >/dev/null 2>&1; then + # echo "hash" + # else + # echo "unknown" + # fi + # return 0 + # } + + def find_current_revision + logger.trace("#{new_resource} finding current git revision") + if ::File.exist?(::File.join(cwd, ".git")) + # 128 is returned when not in a git repo - no problem. + result = git("rev-parse", "HEAD", + cwd: cwd, + returns: [0, 128], + live_stdout: StringIO.new, + live_stderr: StringIO.new, + live_stream: StringIO.new + ).live_stdout.string.strip + end + sha_hash?(result) ? result : nil + end + + def clone + converge_by("clone from #{repo_url} into #{cwd}") do + remote = new_resource.remote + clone_cmd = ["clone"] + clone_cmd << "-o #{remote}" unless remote == "origin" + clone_cmd << "--depth #{new_resource.depth}" if new_resource.depth + clone_cmd << "--no-single-branch" if new_resource.depth && git_has_single_branch_option? + clone_cmd << "\"#{new_resource.repository}\"" + clone_cmd << "\"#{cwd}\"" + + logger.info "#{new_resource} cloning repo #{repo_url} to #{cwd}" + git(clone_cmd, returns: [0, 128]) + end + target_revision + end + + def target_revision + return '' unless existing_git_clone? + @target_revision ||= + begin + if sha_hash?(new_resource.revision) + @target_revision = new_resource.revision + else + @target_revision = local_resolve_reference + end + end + end + + def local_resolve_reference + @resolved_reference = git_ref(rev_search_pattern) + @resolved_reference + end + + def rev_search_pattern + if ["", "HEAD"].include? new_resource.revision + "HEAD" + else + new_resource.revision + end + end + + def git_ref(reference) + # Raise an error if not valid reference format.... + valid = git_ref_format_valid?(reference) + hash = '' + %w[refs/heads refs/tags packed-refs].each do |prefix| + # 128 is returned when not in a git repo - no problem. + hash = git('show-ref', '--verify', "\"#{prefix}/#{reference}\"", + cwd: cwd, + returns: [0, 128], + live_stdout: StringIO.new, + live_stderr: StringIO.new, + live_stream: StringIO.new + ) + break if hash.exitstatus == 0 + end + # This avoids stdout which is not available where no /dev/tty + ref = hash.exitstatus == 0 ? hash.live_stdout.string : '' + ref.chomp.split(' ').first + end + + def git_ref_format_valid?(reference) + valid = false + result = git('check-ref-format', '--allow-onelevel', reference, returns: [0, 1]) + if result.exitstatus + valid = true + else + git('check-ref-format', reference).exit_status ? valid = true : valid = false + end + unless valid + # For invalid reference formats git cannot return a revision + raise Chef::Exceptions::User, "The given reference '#{reference}' is not a valid Git reference format." + end + valid + end + +end + +Chef::Provider::Git.prepend(GitExt) diff --git a/libraries/package_deps.rb b/libraries/package_deps.rb index 96dfe26f..6a03f782 100644 --- a/libraries/package_deps.rb +++ b/libraries/package_deps.rb @@ -1,53 +1,78 @@ +# frozen_string_literal: true + class Chef - module Rbenv + module Jlenv module PackageDeps - def install_ruby_dependencies + def install_julia_dependencies case ::File.basename(new_resource.version) - when /^jruby-/ - package jruby_package_deps + when /^special-julia-/ + puts 'call another package install method' else + apt_update if node['platform_family'] == 'debian' package_deps.each do |deps| package deps end end - - ensure_java_environment if new_resource.version =~ /^jruby-/ - end - - def ensure_java_environment - resource_collection.find( - 'ruby_block[update-java-alternatives]' - ).run_action(:create) - rescue Chef::Exceptions::ResourceNotFound - # have pity on my soul - Chef::Log.info 'The java cookbook does not appear to in the run_list.' - end - - def jruby_package_deps - case node['platform_family'] - when 'rhel', 'fedora', 'amazon' - %w(make gcc-c++) - when 'debian' - %w(make g++) - when 'freebsd' - %w(alsa-lib bash dejavu expat fixesproto fontconfig freetype2 gettext-runtime giflib indexinfo inputproto java-zoneinfo javavmwrapper kbproto libICE libSM libX11 libXau libXdmcp libXext libXfixes libXi libXrender libXt libXtst libfontenc libpthread-stubs libxcb libxml2 mkfontdir mkfontscale openjdk8 recordproto renderproto xextproto xproto) - end + ensure_java_environment if new_resource.version =~ /^jjulia-/ end def package_deps - case node['platform_family'] + case node['platform'] when 'mac_os_x' - %w(openssl makedepend pkg-config libyaml libffi) + %w[openssl makedepend pkg-config libyaml libffi] when 'rhel', 'fedora', 'amazon' - %w(gcc bzip2 openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel make) + %w[bzip2 gcc-5 g++-5 chkconfig openssl-devel readline-devel zlib-devel + ncurses-devel make] when 'debian' if node['platform_version'].to_i >= 18 - %w(gcc autoconf bison build-essential libssl1.0-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev make) + %w[autoconf bison gcc-5 g++-5 libssl1.0-dev libreadline6-dev zlib1g-dev + libncurses5-dev make] else - %w(gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev make) + %w[autoconf bison gcc-5 g++-5 libssl-dev libreadline6-dev zlib1g-dev + libncurses5-dev make] + end + when 'ubuntu' + case node['platform_version'] + when '18.04' + case node['hostnamectl']['architecture'] + when 'x86-64' + %w[bar bzip2 cmake ccache curl dpkg gawk gcc-5 g++-5 gfortran-5 + libatomic1 libqd-dev libssl1.0.0 make m4 patch perl pkg-config + python-minimal time] + else + %w[bar bzip2 cmake ccache curl dpkg gawk gcc-5 g++-5 gfortran-5 + gcc-5-multilib g++-5-multilib libatomic1 libqd-dev libssl1.0.0 + make m4 patch perl pkg-config python-minimal time binutils + make:i386 libssl-dev:i386 gfortran-5 gfortran-5-multilib] + end + when '16.04' + case node['hostnamectl']['architecture'] + when 'x86-64' + %w[bar bzip2 cmake ccache curl dpkg gawk gcc-5 g++-5 gfortran-5 + libatomic1 libqd-dev libssl1.0.0 make m4 patch perl pkg-config + python-minimal time] + else + %w[bar bzip2 cmake ccache curl dpkg gawk gcc-5 g++-5 gfortran-5 + gcc-5-multilib g++-5-multilib libatomic1 libqd-dev libssl1.0.0 + make m4 patch perl pkg-config python-minimal time binutils + make:i386 libssl-dev:i386 gfortran-5 gfortran-5-multilib] + end + when '14.04' + case node['hostnamectl']['architecture'] + when 'x86-64' + %w[bar bzip2 cmake ccache curl dpkg gawk gcc-5 g++-5 gfortran-5 + libatomic1 libqd-dev libssl1.0.0 make m4 patch perl pkg-config + python-minimal time] + else + %w[bar bzip2 cmake ccache curl dpkg gawk gcc-5 g++-5 gfortran-5 + gcc-5-multilib g++-5-multilib libatomic1 libqd-dev libssl1.0.0 + make m4 patch perl pkg-config python-minimal time binutils + make:i386 libssl-dev:i386 gfortran-5 gfortran-5-multilib] + end end when 'suse' - %w(gcc make automake gdbm-devel libyaml-devel ncurses-devel readline-devel zlib-devel libopenssl-devel ) + %w[gcc-5 g++-5 gfortran-5 make automake ncurses-devel readline-devel + zlib-devel libopenssl-devel update-alternatives] end end end diff --git a/metadata.rb b/metadata.rb index 8be0ceaf..e2a4da9d 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,13 +1,13 @@ -name 'ruby_rbenv' -maintainer 'Sous Chefs' -maintainer_email 'help@sous-chefs.org' -issues_url 'https://github.com/sous-chefs/ruby_rbenv/issues' -source_url 'https://github.com/sous-chefs/ruby_rbenv' +name 'jlenv' +maintainer 'Mark Van de Vyver' +maintainer_email 'mark@taqtiqa.com' +issues_url 'https://github.com/jlenv/jlenv-cookbook/issues' +source_url 'https://github.com/jlenv/jlenv-cookbook' license 'Apache-2.0' -description 'Manages rbenv and installs Rbenv based Rubies' +description 'Manages jlenv and plugins for Julia installations.' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '2.1.2' -chef_version '>= 13.0' +version '0.3.0' +chef_version '>= 14.0' supports 'ubuntu' supports 'linuxmint' diff --git a/policyfiles/base.rb b/policyfiles/base.rb new file mode 100644 index 00000000..b548c30d --- /dev/null +++ b/policyfiles/base.rb @@ -0,0 +1,3 @@ +default_source :supermarket + +cookbook 'resources', path: './test/fixtures/cookbooks/resources' diff --git a/policyfiles/jlenv.rb b/policyfiles/jlenv.rb new file mode 100644 index 00000000..e69de29b diff --git a/recipes/default.rb b/recipes/default.rb new file mode 100644 index 00000000..5e75480f --- /dev/null +++ b/recipes/default.rb @@ -0,0 +1 @@ +require_relative './../libraries/lib/chef/provider/git_ext' \ No newline at end of file diff --git a/resources/global.rb b/resources/global.rb index 50c6d657..1ae9a5a9 100644 --- a/resources/global.rb +++ b/resources/global.rb @@ -1,12 +1,14 @@ # -# Cookbook:: ruby_rbenv +# Cookbook:: jlenv # Resource:: global # # Author:: Fletcher Nichol -# Author:: Dan Webb +# Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2011-2018, Fletcher Nichol # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +23,12 @@ # limitations under the License. # -# Check for the user or system global verison +# Check for the user or system global version # If we pass in a user check that users global -provides :rbenv_global +provides :jlenv_global -property :rbenv_version, String, name_property: true +property :jlenv_version, String, name_property: true property :user, String property :root_path, String, default: lazy { if user @@ -36,12 +38,12 @@ end } -# This sets the Global rbenv version -# e.g. "rbenv global" should return the version we set +# This sets the Global jlenv version +# e.g. "jlenv global" should return the version we set action :create do - rbenv_script "globals #{which_rbenv}" do - code "rbenv global #{new_resource.rbenv_version}" + jlenv_script "globals #{which_jlenv}" do + code "jlenv global #{new_resource.jlenv_version}" user new_resource.user if new_resource.user action :run not_if { current_global_version_correct? } @@ -49,10 +51,10 @@ end action_class do - include Chef::Rbenv::Helpers + include Chef::Jlenv::Helpers def current_global_version_correct? - current_global_version == new_resource.rbenv_version + current_global_version == new_resource.jlenv_version end def current_global_version diff --git a/resources/ruby.rb b/resources/julia.rb similarity index 66% rename from resources/ruby.rb rename to resources/julia.rb index c03df4e4..64616b86 100644 --- a/resources/ruby.rb +++ b/resources/julia.rb @@ -1,12 +1,16 @@ +# frozen_string_literal: true + # -# Cookbook:: ruby_rbenv -# Resource:: ruby +# Cookbook:: jlenv +# Resource:: julia # # Author:: Fletcher Nichol # Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2011-2018, Fletcher Nichol # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,66 +24,65 @@ # See the License for the specific language governing permissions and # limitations under the License. # -provides :rbenv_ruby +provides :jlenv_julia property :version, String, name_property: true property :version_file, String property :user, String property :environment, Hash -property :rbenv_action, String, default: 'install' +property :jlenv_action, String, default: 'install' property :verbose, [true, false], default: false -property :ruby_build_git_url, String, default: 'https://github.com/rbenv/ruby-build.git' +property :julia_build_git_url, String, default: 'https://github.com/jlenv/julia-build.git' action :install do - Chef::Log.fatal('Rubinius not supported by this cookbook') if new_resource.version =~ /rbx/ install_start = Time.now - Chef::Log.info("Building Ruby #{new_resource.version}, this could take a while...") + Chef::Log.info("Building Julia #{new_resource.version}, this could take a while...") - rbenv_plugin 'ruby-build' do - git_url new_resource.ruby_build_git_url + jlenv_plugin 'julia-build' do + git_url new_resource.julia_build_git_url user new_resource.user if new_resource.user end - install_ruby_dependencies + install_julia_dependencies # TODO: ? # patch_command = "--patch < <(curl -sSL #{new_resource.patch_url})" if new_resource.patch_url # patch_command = "--patch < #{new_resource.patch_file}" if new_resource.patch_file - command = %(rbenv #{new_resource.rbenv_action}) - # From `rbenv help uninstall`: + command = %(jlenv #{new_resource.jlenv_action}) + # From `jlenv help uninstall`: # -f Attempt to remove the specified version without prompting # for confirmation. If the version does not exist, do not # display an error message. - command << ' -f' if new_resource.rbenv_action == 'uninstall' + command << ' -f' if new_resource.jlenv_action == 'uninstall' command << " #{new_resource.version}" command << ' --verbose' if new_resource.verbose - rbenv_script "#{command} #{which_rbenv}" do + jlenv_script "#{command} #{which_jlenv}" do code command user new_resource.user if new_resource.user environment new_resource.environment if new_resource.environment action :run live_stream true if new_resource.verbose - not_if { ruby_installed? && new_resource.rbenv_action != 'uninstall' } + not_if { julia_installed? && new_resource.jlenv_action != 'uninstall' } end log_message = new_resource.to_s - log_message << if new_resource.rbenv_action == 'uninstall' + log_message << if new_resource.jlenv_action == 'uninstall' ' uninstalled' else " build time was #{(Time.now - install_start) / 60.0} minutes" end Chef::Log.info(log_message) - # TODO: If there is no more Ruby installed on the system, the `version` file - # of rbenv still contains a version number which results in a warning. See + # TODO: If there is no more Julia installed on the system, the `version` file + # of jlenv still contains a version number which results in a warning. See # this issue and comment for more details: # https://github.com/rbenv/rbenv/pull/848#issuecomment-413857386 end action_class do - include Chef::Rbenv::Helpers - include Chef::Rbenv::PackageDeps + include Chef::Jlenv::Helpers + include Chef::Jlenv::PackageDeps end diff --git a/resources/gem.rb b/resources/pkg.rb similarity index 85% rename from resources/gem.rb rename to resources/pkg.rb index d3f2ad16..5a7969bf 100644 --- a/resources/gem.rb +++ b/resources/pkg.rb @@ -1,12 +1,14 @@ # -# Cookbook:: ruby_rbenv -# Resource:: gem +# Cookbook:: jlenv +# Resource:: pkg # # Author:: Fletcher Nichol -# Author:: Dan Webb +# Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2011-2018, Fletcher Nichol # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,9 +23,9 @@ # limitations under the License. # -provides :rbenv_gem -# Standard Gem Package Options -# https://docs.chef.io/resource_gem_package.html#properties +provides :jlenv_package +# Standard Package Options +# https://docs.chef.io/resource_package.html#properties property :clear_sources, [true, false] property :include_default_source, [true, false], default: true property :ignore_failure, [true, false], default: false @@ -34,16 +36,16 @@ property :version, String property :response_file, String # Only used to reconfigure property :user, String -property :rbenv_version, String, required: true +property :jlenv_version, String, required: true default_action :install action :install do - gem_package new_resource.package_name do + pkg_package new_resource.package_name do clear_sources new_resource.clear_sources if new_resource.clear_sources ignore_failure new_resource.ignore_failure if new_resource.ignore_failure include_default_source new_resource.include_default_source - gem_binary binary + pkg_binary binary options new_resource.options if new_resource.options package_name new_resource.package_name if new_resource.package_name source new_resource.source if new_resource.source @@ -54,11 +56,11 @@ end action :purge do - gem_package new_resource.package_name do + pkg_package new_resource.package_name do clear_sources new_resource.clear_sources if new_resource.clear_sources ignore_failure new_resource.ignore_failure if new_resource.ignore_failure include_default_source new_resource.include_default_source - gem_binary binary + pkg_binary binary options new_resource.options if new_resource.options package_name new_resource.package_name if new_resource.package_name source new_resource.source if new_resource.source @@ -69,11 +71,11 @@ end action :reconfig do - gem_package new_resource.package_name do + pkg_package new_resource.package_name do clear_sources new_resource.clear_sources if new_resource.clear_sources ignore_failure new_resource.ignore_failure if new_resource.ignore_failure include_default_source new_resource.include_default_source - gem_binary binary + pkg_binary binary options new_resource.options if new_resource.options package_name new_resource.package_name if new_resource.package_name source new_resource.source if new_resource.source @@ -85,11 +87,11 @@ end action :remove do - gem_package new_resource.package_name do + pkg_package new_resource.package_name do clear_sources new_resource.clear_sources if new_resource.clear_sources ignore_failure new_resource.ignore_failure if new_resource.ignore_failure include_default_source new_resource.include_default_source - gem_binary binary + pkg_binary binary options new_resource.options if new_resource.options package_name new_resource.package_name if new_resource.package_name source new_resource.source if new_resource.source @@ -100,11 +102,11 @@ end action :upgrade do - gem_package new_resource.package_name do + pkg_package new_resource.package_name do clear_sources new_resource.clear_sources if new_resource.clear_sources ignore_failure new_resource.ignore_failure if new_resource.ignore_failure include_default_source new_resource.include_default_source - gem_binary binary + pkg_binary binary options new_resource.options if new_resource.options package_name new_resource.package_name if new_resource.package_name source new_resource.source if new_resource.source @@ -115,5 +117,5 @@ end action_class do - include Chef::Rbenv::Helpers + include Chef::Jlenv::Helpers end diff --git a/resources/plugin.rb b/resources/plugin.rb index 8b91c3de..be42c234 100644 --- a/resources/plugin.rb +++ b/resources/plugin.rb @@ -1,10 +1,12 @@ # -# Cookbook:: ruby_rbenv +# Cookbook:: jlenv # Resource:: plugin # # Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,25 +20,30 @@ # See the License for the specific language governing permissions and # limitations under the License. # -provides :rbenv_plugin -property :git_url, String, required: true +# Install a plugin to either user or system jlenv. +provides :jlenv_plugin + +property :git_url, String, default: 'https://github.com/jlenv/julia-build.git' property :git_ref, String, default: 'master' +property :plugin, String, name_property: true property :user, String +property :update_jlenv, [true, false], default: true -# https://github.com/rbenv/rbenv/wiki/Plugins +# TODO: +# redirect https://github.com/jlenv/jlenv/wiki/Plugins to github pages action :install do # If we pass in a username, we then to a plugin install to the users home_dir - # See chef_rbenv_script_helpers.rb for root_path + # See chef_jlenv_script_helpers.rb for root_path git "Install #{new_resource.name} plugin" do destination ::File.join(root_path, 'plugins', new_resource.name) repository new_resource.git_url reference new_resource.git_ref user new_resource.user if new_resource.user - action :sync + action :checkout if new_resource.update_jlenv == false end end action_class do - include Chef::Rbenv::Helpers + include Chef::Jlenv::Helpers end diff --git a/resources/rehash.rb b/resources/rehash.rb index a88cf5a6..7ba4dcdb 100644 --- a/resources/rehash.rb +++ b/resources/rehash.rb @@ -1,12 +1,14 @@ # -# Cookbook:: ruby_rbenv +# Cookbook:: jlenv # Resource:: rehash # # Author:: Fletcher Nichol -# Author:: Dan Webb +# Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2011-2018, Fletcher Nichol # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,18 +22,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # -provides :rbenv_rehash +provides :jlenv_rehash property :user, String action :run do - rbenv_script "rbenv rehash #{which_rbenv}" do - code %(rbenv rehash) + jlenv_script "jlenv rehash #{which_jlenv}" do + code %(jlenv rehash) user new_resource.user if new_resource.user action :run end end action_class do - include Chef::Rbenv::Helpers + include Chef::Jlenv::Helpers end diff --git a/resources/script.rb b/resources/script.rb index 6fb5c964..aab37167 100644 --- a/resources/script.rb +++ b/resources/script.rb @@ -1,12 +1,14 @@ # -# Cookbook:: ruby_rbenv +# Cookbook:: jlenv # Resource:: script # # Author:: Fletcher Nichol -# Author:: Dan Webb +# Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2011-2018, Fletcher Nichol # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,9 +22,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # -provides :rbenv_script +provides :jlenv_script -property :rbenv_version, String +property :jlenv_version, String property :code, String property :creates, String property :cwd, String @@ -51,5 +53,5 @@ end action_class do - include Chef::Rbenv::Helpers + include Chef::Jlenv::Helpers end diff --git a/resources/system_install.rb b/resources/system_install.rb index e7d475c3..6546712d 100644 --- a/resources/system_install.rb +++ b/resources/system_install.rb @@ -1,10 +1,12 @@ # -# Cookbook:: ruby_rbenv +# Cookbook:: jlenv # Resource:: system_install # # Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,13 +21,14 @@ # limitations under the License. # -# Install rbenv to a system wide location -provides :rbenv_system_install +# Install jlenv to a system wide location +provides :jlenv_system_install -property :git_url, String, default: 'https://github.com/rbenv/rbenv.git' +property :git_url, String, default: 'https://github.com/jlenv/jlenv.git' property :git_ref, String, default: 'master' -property :global_prefix, String, default: '/usr/local/rbenv' -property :update_rbenv, [true, false], default: true +property :git_username, String, default: 'root' +property :global_prefix, String, default: '/usr/local/jlenv' +property :update_jlenv, [true, false], default: true action :install do node.run_state['root_path'] ||= {} @@ -38,9 +41,9 @@ mode '0755' end - template '/etc/profile.d/rbenv.sh' do - cookbook 'ruby_rbenv' - source 'rbenv.sh.erb' + template '/etc/profile.d/jlenv.sh' do + cookbook 'jlenv' + source 'jlenv.sh.erb' owner 'root' mode '0755' variables(global_prefix: new_resource.global_prefix) @@ -49,9 +52,10 @@ git new_resource.global_prefix do repository new_resource.git_url reference new_resource.git_ref - action :checkout if new_resource.update_rbenv == false - notifies :run, 'ruby_block[Add rbenv to PATH]', :immediately - notifies :run, 'bash[Initialize system rbenv]', :immediately + action :checkout if new_resource.update_jlenv == false + #notifies :run, 'bash[Initialize global git username]', :immediately + notifies :run, 'ruby_block[Add jlenv to PATH]', :immediately + notifies :run, 'bash[Initialize system jlenv]', :immediately end directory "#{new_resource.global_prefix}/plugins" do @@ -59,21 +63,31 @@ mode '0755' end - # Initialize rbenv - ruby_block 'Add rbenv to PATH' do + # Initialize jlenv + ruby_block 'Add jlenv to PATH' do block do ENV['PATH'] = "#{new_resource.global_prefix}/shims:#{new_resource.global_prefix}/bin:#{ENV['PATH']}" end action :nothing end - bash 'Initialize system rbenv' do - code %(PATH="#{new_resource.global_prefix}/bin:$PATH" rbenv init -) - environment('RBENV_ROOT' => new_resource.global_prefix) + # Git within dokken encounters the problem that /dev/tty is not available. + # See also: https://stackoverflow.com/a/57458443/152860 + bash 'Initialize global git username' do + code <<-EOH + su -l #{node['current_user']} -c 'git config --global user.name #{new_resource.git_username||node['current_user']}' + EOH + flags "-x" + action :nothing + end + + bash 'Initialize system jlenv' do + code %(PATH="#{new_resource.global_prefix}/bin:$PATH" jlenv init -) + environment('JLENV_ROOT' => new_resource.global_prefix) action :nothing end end action_class do - include Chef::Rbenv::Helpers + include Chef::Jlenv::Helpers end diff --git a/resources/user_install.rb b/resources/user_install.rb index 27a192a5..9e58c109 100644 --- a/resources/user_install.rb +++ b/resources/user_install.rb @@ -1,10 +1,12 @@ # -# Cookbook:: ruby_rbenv +# Cookbook:: jlenv # Resource:: user_install # # Author:: Dan Webb +# Author:: Mark Van de Vyver # # Copyright:: 2017-2018, Dan Webb +# Copyright:: 2019, Mark Van de Vyver # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,18 +21,19 @@ # limitations under the License. # -# Install rbenv to a user location -provides :rbenv_user_install +# Install jlenv to a user location +provides :jlenv_user_install -property :git_url, String, default: 'https://github.com/rbenv/rbenv.git' +property :git_url, String, default: 'https://github.com/jlenv/jlenv.git' property :git_ref, String, default: 'master' property :user, String, name_property: true property :group, String, default: lazy { user } property :home_dir, String, default: lazy { ::File.expand_path("~#{user}") } -property :user_prefix, String, default: lazy { ::File.join(home_dir, '.rbenv') } -property :update_rbenv, [true, false], default: true +property :user_prefix, String, default: lazy { ::File.join(home_dir, '.jlenv') } +property :update_jlenv, [true, false], default: true action :install do + package package_prerequisites node.run_state['root_path'] ||= {} @@ -38,9 +41,9 @@ system_prefix = node.run_state['root_path']['system'] - template '/etc/profile.d/rbenv.sh' do - cookbook 'ruby_rbenv' - source 'rbenv.sh.erb' + template '/etc/profile.d/jlenv.sh' do + cookbook 'jlenv' + source 'jlenv.sh.erb' variables(global_prefix: system_prefix) if system_prefix owner 'root' mode '0755' @@ -49,10 +52,10 @@ git new_resource.user_prefix do repository new_resource.git_url reference new_resource.git_ref - action :checkout if new_resource.update_rbenv == false + action :checkout if new_resource.update_jlenv == false user new_resource.user group new_resource.group - notifies :run, 'ruby_block[Add rbenv to PATH]', :immediately + notifies :run, 'ruby_block[Add jlenv to PATH]', :immediately end %w(plugins shims versions).each do |d| @@ -60,20 +63,21 @@ owner new_resource.user group new_resource.group mode '0755' + recursive false end end - # Initialize rbenv - ruby_block 'Add rbenv to PATH' do + # Initialize jlenv + ruby_block 'Add jlenv to PATH' do block do ENV['PATH'] = "#{new_resource.user_prefix}/shims:#{new_resource.user_prefix}/bin:#{ENV['PATH']}" end action :nothing end - bash "Initialize user #{new_resource.user} rbenv" do - code %(PATH="#{new_resource.user_prefix}/bin:$PATH" rbenv init -) - environment('RBENV_ROOT' => new_resource.user_prefix) + bash "Initialize user #{new_resource.user} jlenv" do + code %(PATH="#{new_resource.user_prefix}/bin:$PATH" jlenv init -) + environment('JLENV_ROOT' => new_resource.user_prefix) action :nothing subscribes :run, "git[#{new_resource.user_prefix}]", :immediately # Subscribe because it's easier to find the resource ;) @@ -81,5 +85,5 @@ end action_class do - include Chef::Rbenv::Helpers + include Chef::Jlenv::Helpers end diff --git a/templates/jlenv.sh.erb b/templates/jlenv.sh.erb new file mode 100644 index 00000000..6ee29e65 --- /dev/null +++ b/templates/jlenv.sh.erb @@ -0,0 +1,15 @@ +# Generated by Chef for <%= node['fqdn'] %> +# Local modifications will be overridden + +# prefer a user jlenv over a system wide install +if [ -s "${HOME}/.jlenv/bin" ]; then + jlenv_root="${HOME}/.jlenv" +elif [ -s "<%= @global_prefix %>" ]; then + jlenv_root="<%= @global_prefix %>" +fi +export JLENV_ROOT="$jlenv_root" + +if [ -n "$JLENV_ROOT" ]; then + export PATH="${JLENV_ROOT}/bin:$PATH" + eval "$(jlenv init -)" +fi diff --git a/templates/rbenv.sh.erb b/templates/rbenv.sh.erb deleted file mode 100644 index e17020d0..00000000 --- a/templates/rbenv.sh.erb +++ /dev/null @@ -1,15 +0,0 @@ -# Generated by Chef for <%= node['fqdn'] %> -# Local modifications will be overridden - -# prefer a user rbenv over a system wide install -if [ -s "${HOME}/.rbenv/bin" ]; then - rbenv_root="${HOME}/.rbenv" -elif [ -s "<%= @global_prefix %>" ]; then - rbenv_root="<%= @global_prefix %>" - export RBENV_ROOT="$rbenv_root" -fi - -if [ -n "$rbenv_root" ]; then - export PATH="${rbenv_root}/bin:$PATH" - eval "$(rbenv init -)" -fi diff --git a/test/fixtures/cookbooks/issues/Policyfile.rb b/test/fixtures/cookbooks/issues/Policyfile.rb new file mode 100644 index 00000000..87f797e9 --- /dev/null +++ b/test/fixtures/cookbooks/issues/Policyfile.rb @@ -0,0 +1,9 @@ +name 'issues' + +run_list 'issues::default' + +default_source :chef_repo, '../../../../../' +default_source :chef_repo, '../' + +cookbook 'issues' +cookbook 'shared' diff --git a/test/fixtures/cookbooks/issues/README.md b/test/fixtures/cookbooks/issues/README.md new file mode 100644 index 00000000..cc01991f --- /dev/null +++ b/test/fixtures/cookbooks/issues/README.md @@ -0,0 +1,6 @@ +# Issues Integration Cookbook + +The **Resources cookbook** exercise resource default behaviour. +The **Recipes cookbook** exercise resource non-default behaviour. +The **Issues cookbook** exercise past broken or incorrect behaviour i.e. +regression tests. diff --git a/test/fixtures/cookbooks/issues/metadata.rb b/test/fixtures/cookbooks/issues/metadata.rb new file mode 100644 index 00000000..9149b321 --- /dev/null +++ b/test/fixtures/cookbooks/issues/metadata.rb @@ -0,0 +1,7 @@ +name 'issues' +description 'A cookbook that exercises past broken or incorrect behaviour - regression tests.' +version '0.99.2' + +depends 'shared' + +recipe 'issues::default', 'Provides an example for documentation purposes.' diff --git a/test/fixtures/cookbooks/issues/recipes/custom_group_install.rb b/test/fixtures/cookbooks/issues/recipes/custom_group_install.rb new file mode 100644 index 00000000..07855920 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/custom_group_install.rb @@ -0,0 +1,29 @@ +# Install jlenv and makes it avilable to the selected user +version = '1.0.1' + +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +group 'new-group' do + members 'vagrant' +end + +# Keeps the jlenv install upto date +jlenv_user_install 'vagrant' do + user 'vagrant' + group 'new-group' +end + +# Install plugin to build Julia +jlenv_plugin 'julia-build' do + git_url 'https://github.com/jlenv/julia-build.git' + user 'vagrant' +end + +jlenv_julia '1.0.1' do + user 'vagrant' +end + +jlenv_global version do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/issues/recipes/default.rb b/test/fixtures/cookbooks/issues/recipes/default.rb new file mode 100644 index 00000000..63d452c3 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/default.rb @@ -0,0 +1,4 @@ +# recipe file to satisfy Policyfile build. + +# Ensure test setup +include_recipe 'shared::default' diff --git a/test/fixtures/cookbooks/issues/recipes/global.rb b/test/fixtures/cookbooks/issues/recipes/global.rb new file mode 100644 index 00000000..39b40f17 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/global.rb @@ -0,0 +1,14 @@ + +# Spec resource usage with defaults. + +# Ensure Vagrant user exists on test environment +include_recipe 'test::default' + +global_version = '1.0.3' + +# Install Jlenv Globally. +# TODO: Remove this step by installing the given version if not installed. +jlenv_system_install 'system' + +# Set that Julia version as the global Julia +jlenv_global global_version diff --git a/test/fixtures/cookbooks/issues/recipes/julia_uninstall.rb b/test/fixtures/cookbooks/issues/recipes/julia_uninstall.rb new file mode 100644 index 00000000..7c709ea8 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/julia_uninstall.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +system_version = '1.0.1' + +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +# System Install +jlenv_system_install 'system' + +# Install system wide Julia +jlenv_julia system_version + +# Set System global version +jlenv_global system_version + +# Uninstall Julia +jlenv_julia system_version do + jlenv_action 'uninstall' +end diff --git a/test/fixtures/cookbooks/issues/recipes/pkg.rb b/test/fixtures/cookbooks/issues/recipes/pkg.rb new file mode 100644 index 00000000..46a36a74 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/pkg.rb @@ -0,0 +1,129 @@ +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +# System Install +jlenv_system_install 'system' +# Install several Julias to a system wide location +jlenv_julia '1.0.4' do + verbose true +end + +jlenv_julia '1.1.0' do + verbose true +end + +# Set System global version +jlenv_global '1.0.4' + +##################################################################### +# +# JuliaRegistries/General Hosted Repository +# +##################################################################### + +# Default is latest from default registry to global Julia +jlenv_pkg 'DataFrames' + +jlenv_pkg 'DataFrames' do + action :remove +end + +# Registry add by version numbers +jlenv_pkg 'DataFrames' do + version '0.15.2' + jlenv_version '1.1.0' + action :add +end + +# Registry remove action +jlenv_pkg 'DataFrames' do + version '0.15.2' + jlenv_version '1.0.4' + action :remove +end + +# Registry by UUID numbers +jlenv_pkg 'DataFrames' do + uuid 'a93c6f00-e57d-5684-b7b6-d8193f3e46c0' + jlenv_version '1.0.4' +end + +# Registry by branch name +jlenv_pkg 'DataFrames' do + branch 'master' + jlenv_version '1.1.0' +end + +# Registry hash +jlenv_pkg 'DataFrames' do + hash '279baa63' + jlenv_version '1.1.0' +end + +# Registry version +jlenv_pkg 'General Registry Data Frames' do + name 'DataFrames' + version '0.15.1' + jlenv_version '1.1.0' +end + +# Registry nomination +jlenv_pkg 'DataFrames' do + registry 'https://github.com/JuliaRegistries/General' + version '0.15.2' + jlenv_version '1.1.0' +end + +##################################################################### +# +# Git Hosted Repository +# +##################################################################### + +# Remote git branch. +jlenv_pkg 'Free Text' do + repo 'https://github.com/JuliaData/DataFrames.jl' + branch 'master' + jlenv_version '1.1.0' +end + +# Remote git version. +jlenv_pkg 'Free Text' do + url 'https://github.com/JuliaData/DataFrames.jl' + version '0.18.2' + jlenv_version '1.1.0' +end + +# Remote git version. +jlenv_pkg 'Free Text' do + url 'https://github.com/JuliaData/DataFrames.jl' + hash '279baa6358fd5e944deccab88434f69c74cfc722' + jlenv_version '1.1.0' +end + +# Local (bare) git branch +jlenv_pkg 'Free Text' do + repo 'file:///src/DataFrames.jl.git' + branch 'master' + jlenv_version '1.1.0' +end + +# Local (bare) git hash +jlenv_pkg 'Bare repository' do + repo 'file:///src/DataFrames.jl.git' + hash '3891a62fd843662af9f78f25bdd415530b9b9c1e' + jlenv_version '1.1.0' +end + +# Install latest for specific user +jlenv_user_install 'vagrant' + +# Install a Julia to a user directory +jlenv_julia '1.1.0' do + user 'vagrant' +end + +# Set the vagrant global version +jlenv_global '1.1.0' do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/issues/recipes/plugin.rb b/test/fixtures/cookbooks/issues/recipes/plugin.rb new file mode 100644 index 00000000..0476dab6 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/plugin.rb @@ -0,0 +1,28 @@ +version = '1.0.1' + +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +jlenv_user_install 'vagrant' + +jlenv_system_install 'system' + +jlenv_julia version do + install_julia_build false + user 'vagrant' +end + +jlenv_global version do + user 'vagrant' +end + +jlenv_plugin 'julia-build' do + git_url 'https://github.com/jlenv/julia-build.git' + user 'vagrant' +end + +# This should get installed to the system_install +jlenv_plugin 'julia-build' do + git_url 'git@github.com:jlenv/julia-build.git' + git_ref 'bb86c68' +end diff --git a/test/fixtures/cookbooks/issues/recipes/rehash.rb b/test/fixtures/cookbooks/issues/recipes/rehash.rb new file mode 100644 index 00000000..31560f04 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/rehash.rb @@ -0,0 +1 @@ +jlenv_rehash 'defaultness' diff --git a/test/fixtures/cookbooks/issues/recipes/script.rb b/test/fixtures/cookbooks/issues/recipes/script.rb new file mode 100644 index 00000000..ca816fc2 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/script.rb @@ -0,0 +1,4 @@ +# Make is Julia's build orchestration +jlenv_script 'not-much' do + code 'make nadda' +end diff --git a/test/fixtures/cookbooks/issues/recipes/system_install.rb b/test/fixtures/cookbooks/issues/recipes/system_install.rb new file mode 100644 index 00000000..46a6a37c --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/system_install.rb @@ -0,0 +1,8 @@ +# Install Jlenv to the system path e.g. /usr/local/jlenv + +# Ensure Vagrant user exists on test environment +include_recipe 'test::default' + +jlenv_system_install 'system' do + update_jlenv false +end diff --git a/test/fixtures/cookbooks/issues/recipes/user_install.rb b/test/fixtures/cookbooks/issues/recipes/user_install.rb new file mode 100644 index 00000000..91fd0a15 --- /dev/null +++ b/test/fixtures/cookbooks/issues/recipes/user_install.rb @@ -0,0 +1,22 @@ +# Install jlenv and makes it avilable to the selected user + +# Ensure Vagrant user exists on test environment +include_recipe 'test::default' + +version = '1.0.1' + +# Keeps the jlenv install upto date +jlenv_user_install 'vagrant' + +jlenv_plugin 'julia-build' do + git_url 'https://github.com/jlenv/julia-build.git' + user 'vagrant' +end + +jlenv_julia '1.0.4' do + user 'vagrant' +end + +jlenv_global version do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/test/recipes/dokken.rb b/test/fixtures/cookbooks/issues/recipes/vagrant.rb similarity index 66% rename from test/fixtures/cookbooks/test/recipes/dokken.rb rename to test/fixtures/cookbooks/issues/recipes/vagrant.rb index 4c225ee4..3860f53a 100644 --- a/test/fixtures/cookbooks/test/recipes/dokken.rb +++ b/test/fixtures/cookbooks/issues/recipes/vagrant.rb @@ -1,4 +1,5 @@ -# Make sure Vagrant user is on the box. This should fix the dokken user install +# Make sure Vagrant user is on the box. +# This should fix the dokken user install. user 'vagrant' group 'vagrant' do diff --git a/test/fixtures/cookbooks/recipes/Policyfile.rb b/test/fixtures/cookbooks/recipes/Policyfile.rb new file mode 100644 index 00000000..fa19ddb5 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/Policyfile.rb @@ -0,0 +1,16 @@ +name 'recipes' + +run_list 'recipes::system_install', + 'recipes::user_install', + 'recipes::global' + +# default_source :chef_repo, "../../../../../" +# default_source :chef_repo, "../" + +# cookbook 'recipes' +# cookbook 'shared' +default_source :chef_repo, './../' + +cookbook 'recipes' +cookbook 'shared' +cookbook 'jlenv', path: './../../../../' diff --git a/test/fixtures/cookbooks/recipes/README.md b/test/fixtures/cookbooks/recipes/README.md new file mode 100644 index 00000000..f8124679 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/README.md @@ -0,0 +1,6 @@ +# Recipes Integration Cookbook + +The **Resources cookbook** exercise resource default behaviour. +The **Recipes cookbook** exercise resource non-default behaviour. +The **Issues cookbook** exercise past broken or incorrect behaviour i.e. +regression tests. diff --git a/test/fixtures/cookbooks/recipes/metadata.rb b/test/fixtures/cookbooks/recipes/metadata.rb new file mode 100644 index 00000000..64eff822 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/metadata.rb @@ -0,0 +1,7 @@ +name 'recipes' +description 'A cookbook that exercises non-default behaviour.' +version '0.9.2' + +depends 'shared' + +recipe 'recipes::default', 'Provides an example for documentation purposes.' diff --git a/test/fixtures/cookbooks/recipes/recipes/custom_group_install.rb b/test/fixtures/cookbooks/recipes/recipes/custom_group_install.rb new file mode 100644 index 00000000..07855920 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/custom_group_install.rb @@ -0,0 +1,29 @@ +# Install jlenv and makes it avilable to the selected user +version = '1.0.1' + +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +group 'new-group' do + members 'vagrant' +end + +# Keeps the jlenv install upto date +jlenv_user_install 'vagrant' do + user 'vagrant' + group 'new-group' +end + +# Install plugin to build Julia +jlenv_plugin 'julia-build' do + git_url 'https://github.com/jlenv/julia-build.git' + user 'vagrant' +end + +jlenv_julia '1.0.1' do + user 'vagrant' +end + +jlenv_global version do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/recipes/recipes/default.rb b/test/fixtures/cookbooks/recipes/recipes/default.rb new file mode 100644 index 00000000..63d452c3 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/default.rb @@ -0,0 +1,4 @@ +# recipe file to satisfy Policyfile build. + +# Ensure test setup +include_recipe 'shared::default' diff --git a/test/fixtures/cookbooks/recipes/recipes/global.rb b/test/fixtures/cookbooks/recipes/recipes/global.rb new file mode 100644 index 00000000..39b40f17 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/global.rb @@ -0,0 +1,14 @@ + +# Spec resource usage with defaults. + +# Ensure Vagrant user exists on test environment +include_recipe 'test::default' + +global_version = '1.0.3' + +# Install Jlenv Globally. +# TODO: Remove this step by installing the given version if not installed. +jlenv_system_install 'system' + +# Set that Julia version as the global Julia +jlenv_global global_version diff --git a/test/fixtures/cookbooks/recipes/recipes/julia_uninstall.rb b/test/fixtures/cookbooks/recipes/recipes/julia_uninstall.rb new file mode 100644 index 00000000..7c709ea8 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/julia_uninstall.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +system_version = '1.0.1' + +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +# System Install +jlenv_system_install 'system' + +# Install system wide Julia +jlenv_julia system_version + +# Set System global version +jlenv_global system_version + +# Uninstall Julia +jlenv_julia system_version do + jlenv_action 'uninstall' +end diff --git a/test/fixtures/cookbooks/recipes/recipes/pkg.rb b/test/fixtures/cookbooks/recipes/recipes/pkg.rb new file mode 100644 index 00000000..46a36a74 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/pkg.rb @@ -0,0 +1,129 @@ +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +# System Install +jlenv_system_install 'system' +# Install several Julias to a system wide location +jlenv_julia '1.0.4' do + verbose true +end + +jlenv_julia '1.1.0' do + verbose true +end + +# Set System global version +jlenv_global '1.0.4' + +##################################################################### +# +# JuliaRegistries/General Hosted Repository +# +##################################################################### + +# Default is latest from default registry to global Julia +jlenv_pkg 'DataFrames' + +jlenv_pkg 'DataFrames' do + action :remove +end + +# Registry add by version numbers +jlenv_pkg 'DataFrames' do + version '0.15.2' + jlenv_version '1.1.0' + action :add +end + +# Registry remove action +jlenv_pkg 'DataFrames' do + version '0.15.2' + jlenv_version '1.0.4' + action :remove +end + +# Registry by UUID numbers +jlenv_pkg 'DataFrames' do + uuid 'a93c6f00-e57d-5684-b7b6-d8193f3e46c0' + jlenv_version '1.0.4' +end + +# Registry by branch name +jlenv_pkg 'DataFrames' do + branch 'master' + jlenv_version '1.1.0' +end + +# Registry hash +jlenv_pkg 'DataFrames' do + hash '279baa63' + jlenv_version '1.1.0' +end + +# Registry version +jlenv_pkg 'General Registry Data Frames' do + name 'DataFrames' + version '0.15.1' + jlenv_version '1.1.0' +end + +# Registry nomination +jlenv_pkg 'DataFrames' do + registry 'https://github.com/JuliaRegistries/General' + version '0.15.2' + jlenv_version '1.1.0' +end + +##################################################################### +# +# Git Hosted Repository +# +##################################################################### + +# Remote git branch. +jlenv_pkg 'Free Text' do + repo 'https://github.com/JuliaData/DataFrames.jl' + branch 'master' + jlenv_version '1.1.0' +end + +# Remote git version. +jlenv_pkg 'Free Text' do + url 'https://github.com/JuliaData/DataFrames.jl' + version '0.18.2' + jlenv_version '1.1.0' +end + +# Remote git version. +jlenv_pkg 'Free Text' do + url 'https://github.com/JuliaData/DataFrames.jl' + hash '279baa6358fd5e944deccab88434f69c74cfc722' + jlenv_version '1.1.0' +end + +# Local (bare) git branch +jlenv_pkg 'Free Text' do + repo 'file:///src/DataFrames.jl.git' + branch 'master' + jlenv_version '1.1.0' +end + +# Local (bare) git hash +jlenv_pkg 'Bare repository' do + repo 'file:///src/DataFrames.jl.git' + hash '3891a62fd843662af9f78f25bdd415530b9b9c1e' + jlenv_version '1.1.0' +end + +# Install latest for specific user +jlenv_user_install 'vagrant' + +# Install a Julia to a user directory +jlenv_julia '1.1.0' do + user 'vagrant' +end + +# Set the vagrant global version +jlenv_global '1.1.0' do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/recipes/recipes/plugin.rb b/test/fixtures/cookbooks/recipes/recipes/plugin.rb new file mode 100644 index 00000000..0476dab6 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/plugin.rb @@ -0,0 +1,28 @@ +version = '1.0.1' + +# Make sure that Vagarant user is on the box for dokken +include_recipe 'test::dokken' + +jlenv_user_install 'vagrant' + +jlenv_system_install 'system' + +jlenv_julia version do + install_julia_build false + user 'vagrant' +end + +jlenv_global version do + user 'vagrant' +end + +jlenv_plugin 'julia-build' do + git_url 'https://github.com/jlenv/julia-build.git' + user 'vagrant' +end + +# This should get installed to the system_install +jlenv_plugin 'julia-build' do + git_url 'git@github.com:jlenv/julia-build.git' + git_ref 'bb86c68' +end diff --git a/test/fixtures/cookbooks/recipes/recipes/rehash.rb b/test/fixtures/cookbooks/recipes/recipes/rehash.rb new file mode 100644 index 00000000..31560f04 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/rehash.rb @@ -0,0 +1 @@ +jlenv_rehash 'defaultness' diff --git a/test/fixtures/cookbooks/recipes/recipes/script.rb b/test/fixtures/cookbooks/recipes/recipes/script.rb new file mode 100644 index 00000000..ca816fc2 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/script.rb @@ -0,0 +1,4 @@ +# Make is Julia's build orchestration +jlenv_script 'not-much' do + code 'make nadda' +end diff --git a/test/fixtures/cookbooks/recipes/recipes/system_install.rb b/test/fixtures/cookbooks/recipes/recipes/system_install.rb new file mode 100644 index 00000000..46a6a37c --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/system_install.rb @@ -0,0 +1,8 @@ +# Install Jlenv to the system path e.g. /usr/local/jlenv + +# Ensure Vagrant user exists on test environment +include_recipe 'test::default' + +jlenv_system_install 'system' do + update_jlenv false +end diff --git a/test/fixtures/cookbooks/recipes/recipes/user_install.rb b/test/fixtures/cookbooks/recipes/recipes/user_install.rb new file mode 100644 index 00000000..91fd0a15 --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/user_install.rb @@ -0,0 +1,22 @@ +# Install jlenv and makes it avilable to the selected user + +# Ensure Vagrant user exists on test environment +include_recipe 'test::default' + +version = '1.0.1' + +# Keeps the jlenv install upto date +jlenv_user_install 'vagrant' + +jlenv_plugin 'julia-build' do + git_url 'https://github.com/jlenv/julia-build.git' + user 'vagrant' +end + +jlenv_julia '1.0.4' do + user 'vagrant' +end + +jlenv_global version do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/recipes/recipes/vagrant.rb b/test/fixtures/cookbooks/recipes/recipes/vagrant.rb new file mode 100644 index 00000000..3860f53a --- /dev/null +++ b/test/fixtures/cookbooks/recipes/recipes/vagrant.rb @@ -0,0 +1,13 @@ +# Make sure Vagrant user is on the box. +# This should fix the dokken user install. +user 'vagrant' + +group 'vagrant' do + members 'vagrant' +end + +directory '/home/vagrant' do + owner 'vagrant' + group 'vagrant' + not_if { platform?('windows') } +end diff --git a/test/fixtures/cookbooks/resources/Policyfile.rb b/test/fixtures/cookbooks/resources/Policyfile.rb new file mode 100644 index 00000000..e3d8eb45 --- /dev/null +++ b/test/fixtures/cookbooks/resources/Policyfile.rb @@ -0,0 +1,11 @@ +name 'resources' + +run_list 'resources::system_install', + 'resources::user_install', + 'resources::plugin' + +default_source :chef_repo, './../' + +cookbook 'resources' +cookbook 'shared' +cookbook 'jlenv', path: './../../../../' diff --git a/test/fixtures/cookbooks/resources/README.md b/test/fixtures/cookbooks/resources/README.md new file mode 100644 index 00000000..ecb0979e --- /dev/null +++ b/test/fixtures/cookbooks/resources/README.md @@ -0,0 +1,6 @@ +# Resources Integration Cookbook + +The **Resources cookbook** exercise resource default behaviour. +The **Recipes cookbook** exercise resource non-default behaviour. +The **Issues cookbook** exercise past broken or incorrect behaviour i.e. +regression tests. diff --git a/test/fixtures/cookbooks/resources/global.pf.rb b/test/fixtures/cookbooks/resources/global.pf.rb new file mode 100644 index 00000000..15be74d5 --- /dev/null +++ b/test/fixtures/cookbooks/resources/global.pf.rb @@ -0,0 +1,9 @@ +name 'resources' + +run_list 'resources::global' + +default_source :chef_repo, "../../../../../" +default_source :chef_repo, "../" + +cookbook 'resources' +cookbook 'shared' diff --git a/test/fixtures/cookbooks/resources/metadata.rb b/test/fixtures/cookbooks/resources/metadata.rb new file mode 100644 index 00000000..d7deb875 --- /dev/null +++ b/test/fixtures/cookbooks/resources/metadata.rb @@ -0,0 +1,7 @@ +name 'resources' +description 'A cookbook that exercises default behaviour.' +version '0.9.3' + +depends 'shared' + +recipe 'resources::default', 'Provides an example for documentation purposes.' diff --git a/test/fixtures/cookbooks/resources/recipes/custom_group_install.rb b/test/fixtures/cookbooks/resources/recipes/custom_group_install.rb new file mode 100644 index 00000000..f0bf2664 --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/custom_group_install.rb @@ -0,0 +1,29 @@ +# Install jlenv and makes it avilable to the selected user +version = '1.0.1' + +# Ensure test setup +include_recipe 'shared::default' + +group 'new-group' do + members 'vagrant' +end + +# Keeps the jlenv install upto date +jlenv_user_install 'vagrant' do + user 'vagrant' + group 'new-group' +end + +# Install plugin to build Julia +jlenv_plugin 'julia-build' do + git_url 'https://github.com/jlenv/julia-build.git' + user 'vagrant' +end + +jlenv_julia '1.0.1' do + user 'vagrant' +end + +jlenv_global version do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/resources/recipes/default.rb b/test/fixtures/cookbooks/resources/recipes/default.rb new file mode 100644 index 00000000..63d452c3 --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/default.rb @@ -0,0 +1,4 @@ +# recipe file to satisfy Policyfile build. + +# Ensure test setup +include_recipe 'shared::default' diff --git a/test/fixtures/cookbooks/resources/recipes/global.rb b/test/fixtures/cookbooks/resources/recipes/global.rb new file mode 100644 index 00000000..fa44460f --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/global.rb @@ -0,0 +1,17 @@ +# Spec resource usage with defaults. + +# Ensure test setup +include_recipe 'shared::default' + +global_version = 'v1.0.3' + +# Install Jlenv Globally. +# TODO: Remove this step by installing the given version if not installed. +jlenv_system_install 'system' + +jlenv_julia global_version do + verbose true +end + +# Set that Julia version as the global Julia +jlenv_global global_version diff --git a/test/fixtures/cookbooks/resources/recipes/julia_uninstall.rb b/test/fixtures/cookbooks/resources/recipes/julia_uninstall.rb new file mode 100644 index 00000000..827c0cc3 --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/julia_uninstall.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +system_version = '1.0.1' + +# Ensure test setup +include_recipe 'shared::default' + +# System Install +jlenv_system_install 'system' + +# Install system wide Julia +jlenv_julia system_version + +# Set System global version +jlenv_global system_version + +# Uninstall Julia +jlenv_julia system_version do + jlenv_action 'uninstall' +end diff --git a/test/fixtures/cookbooks/resources/recipes/pkg.rb b/test/fixtures/cookbooks/resources/recipes/pkg.rb new file mode 100644 index 00000000..f9a75a2b --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/pkg.rb @@ -0,0 +1,129 @@ +# Ensure test setup +include_recipe 'shared::default' + +# System Install +jlenv_system_install 'system' +# Install several Julias to a system wide location +jlenv_julia '1.0.4' do + verbose true +end + +jlenv_julia '1.1.0' do + verbose true +end + +# Set System global version +jlenv_global '1.0.4' + +##################################################################### +# +# JuliaRegistries/General Hosted Repository +# +##################################################################### + +# Default is latest from default registry to global Julia +jlenv_pkg 'DataFrames' + +jlenv_pkg 'DataFrames' do + action :remove +end + +# Registry add by version numbers +jlenv_pkg 'DataFrames' do + version '0.15.2' + jlenv_version '1.1.0' + action :add +end + +# Registry remove action +jlenv_pkg 'DataFrames' do + version '0.15.2' + jlenv_version '1.0.4' + action :remove +end + +# Registry by UUID numbers +jlenv_pkg 'DataFrames' do + uuid 'a93c6f00-e57d-5684-b7b6-d8193f3e46c0' + jlenv_version '1.0.4' +end + +# Registry by branch name +jlenv_pkg 'DataFrames' do + branch 'master' + jlenv_version '1.1.0' +end + +# Registry hash +jlenv_pkg 'DataFrames' do + hash '279baa63' + jlenv_version '1.1.0' +end + +# Registry version +jlenv_pkg 'General Registry Data Frames' do + name 'DataFrames' + version '0.15.1' + jlenv_version '1.1.0' +end + +# Registry nomination +jlenv_pkg 'DataFrames' do + registry 'https://github.com/JuliaRegistries/General' + version '0.15.2' + jlenv_version '1.1.0' +end + +##################################################################### +# +# Git Hosted Repository +# +##################################################################### + +# Remote git branch. +jlenv_pkg 'Free Text' do + repo 'https://github.com/JuliaData/DataFrames.jl' + branch 'master' + jlenv_version '1.1.0' +end + +# Remote git version. +jlenv_pkg 'Free Text' do + url 'https://github.com/JuliaData/DataFrames.jl' + version '0.18.2' + jlenv_version '1.1.0' +end + +# Remote git version. +jlenv_pkg 'Free Text' do + url 'https://github.com/JuliaData/DataFrames.jl' + hash '279baa6358fd5e944deccab88434f69c74cfc722' + jlenv_version '1.1.0' +end + +# Local (bare) git branch +jlenv_pkg 'Free Text' do + repo 'file:///src/DataFrames.jl.git' + branch 'master' + jlenv_version '1.1.0' +end + +# Local (bare) git hash +jlenv_pkg 'Bare repository' do + repo 'file:///src/DataFrames.jl.git' + hash '3891a62fd843662af9f78f25bdd415530b9b9c1e' + jlenv_version '1.1.0' +end + +# Install latest for specific user +jlenv_user_install 'vagrant' + +# Install a Julia to a user directory +jlenv_julia '1.1.0' do + user 'vagrant' +end + +# Set the vagrant global version +jlenv_global '1.1.0' do + user 'vagrant' +end diff --git a/test/fixtures/cookbooks/resources/recipes/plugin.rb b/test/fixtures/cookbooks/resources/recipes/plugin.rb new file mode 100644 index 00000000..8fd03002 --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/plugin.rb @@ -0,0 +1,11 @@ + +# Ensure test setup +include_recipe 'shared::default' + +# Julia build plugin should get installed to the user's jlenv. +jlenv_plugin 'julia-build' do + user 'vagrant' +end + +# Julia build plugin should get installed to the system_install. +jlenv_plugin 'julia-build' diff --git a/test/fixtures/cookbooks/resources/recipes/rehash.rb b/test/fixtures/cookbooks/resources/recipes/rehash.rb new file mode 100644 index 00000000..31560f04 --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/rehash.rb @@ -0,0 +1 @@ +jlenv_rehash 'defaultness' diff --git a/test/fixtures/cookbooks/resources/recipes/script.rb b/test/fixtures/cookbooks/resources/recipes/script.rb new file mode 100644 index 00000000..ca816fc2 --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/script.rb @@ -0,0 +1,4 @@ +# Make is Julia's build orchestration +jlenv_script 'not-much' do + code 'make nadda' +end diff --git a/test/fixtures/cookbooks/resources/recipes/system_install.rb b/test/fixtures/cookbooks/resources/recipes/system_install.rb new file mode 100644 index 00000000..75e637af --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/system_install.rb @@ -0,0 +1,11 @@ + + +# Install Jlenv to the system path e.g. /usr/local/jlenv + +# Ensure test setup +include_recipe 'shared::default' + +jlenv_system_install 'system' + +# Resources should be idempotent +jlenv_system_install 'system' diff --git a/test/fixtures/cookbooks/resources/recipes/user_install.rb b/test/fixtures/cookbooks/resources/recipes/user_install.rb new file mode 100644 index 00000000..7debf8a9 --- /dev/null +++ b/test/fixtures/cookbooks/resources/recipes/user_install.rb @@ -0,0 +1,15 @@ +# Install jlenv and make it avilable to the selected user + +# Ensure test setup +include_recipe 'shared::default' + +# Keeps the jlenv install upto date +jlenv_user_install 'vagrant' + +# Issue: https://github.com/jlenv/jlenv-cookbook/issues/2 +# +# User installs are independent. +#jlenv_user_install 'jovyan' + +# User installs are idempotent. +jlenv_user_install 'vagrant' diff --git a/test/fixtures/cookbooks/resources/system_install.pf.rb b/test/fixtures/cookbooks/resources/system_install.pf.rb new file mode 100644 index 00000000..cd408b61 --- /dev/null +++ b/test/fixtures/cookbooks/resources/system_install.pf.rb @@ -0,0 +1,8 @@ +name 'resources' + +run_list 'resources::system_install' + +default_source :chef_repo, './../' + +cookbook 'resources' +cookbook 'jlenv', path: './../../../../' \ No newline at end of file diff --git a/test/fixtures/cookbooks/shared/Policyfile.rb b/test/fixtures/cookbooks/shared/Policyfile.rb new file mode 100644 index 00000000..f4c6bca3 --- /dev/null +++ b/test/fixtures/cookbooks/shared/Policyfile.rb @@ -0,0 +1,9 @@ +name 'shared' + +run_list 'shared::default' + +# default_source :chef_repo, './../../../../' +default_source :chef_repo, './../' + +cookbook 'shared' +cookbook 'jlenv', path: './../../../../' diff --git a/test/fixtures/cookbooks/shared/metadata.rb b/test/fixtures/cookbooks/shared/metadata.rb new file mode 100644 index 00000000..fde835ac --- /dev/null +++ b/test/fixtures/cookbooks/shared/metadata.rb @@ -0,0 +1,6 @@ +name 'shared' +version '0.9.4' + +depends 'jlenv' + +recipe 'shared::default', 'Provides an example for documentation purposes.' diff --git a/test/fixtures/cookbooks/shared/recipes/default.rb b/test/fixtures/cookbooks/shared/recipes/default.rb new file mode 100644 index 00000000..3a39925c --- /dev/null +++ b/test/fixtures/cookbooks/shared/recipes/default.rb @@ -0,0 +1,2 @@ +# Ensure test setup +include_recipe 'shared::vagrant' diff --git a/test/fixtures/cookbooks/shared/recipes/vagrant.rb b/test/fixtures/cookbooks/shared/recipes/vagrant.rb new file mode 100644 index 00000000..3860f53a --- /dev/null +++ b/test/fixtures/cookbooks/shared/recipes/vagrant.rb @@ -0,0 +1,13 @@ +# Make sure Vagrant user is on the box. +# This should fix the dokken user install. +user 'vagrant' + +group 'vagrant' do + members 'vagrant' +end + +directory '/home/vagrant' do + owner 'vagrant' + group 'vagrant' + not_if { platform?('windows') } +end diff --git a/test/fixtures/cookbooks/test/metadata.rb b/test/fixtures/cookbooks/test/metadata.rb deleted file mode 100644 index 6832f9a7..00000000 --- a/test/fixtures/cookbooks/test/metadata.rb +++ /dev/null @@ -1,4 +0,0 @@ -name 'test' -version '0.99.0' - -depends 'ruby_rbenv' diff --git a/test/fixtures/cookbooks/test/recipes/custom_group_install.rb b/test/fixtures/cookbooks/test/recipes/custom_group_install.rb deleted file mode 100644 index a8ed4c7f..00000000 --- a/test/fixtures/cookbooks/test/recipes/custom_group_install.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Install rbenv and makes it avilable to the selected user -version = '2.4.1' - -# Make sure that Vagarant user is on the box for dokken -include_recipe 'test::dokken' - -group 'new-group' do - members 'vagrant' -end - -# Keeps the rbenv install upto date -rbenv_user_install 'vagrant' do - user 'vagrant' - group 'new-group' -end - -rbenv_plugin 'ruby-build' do - git_url 'https://github.com/rbenv/ruby-build.git' - user 'vagrant' -end - -rbenv_ruby '2.4.1' do - user 'vagrant' -end - -rbenv_global version do - user 'vagrant' -end diff --git a/test/fixtures/cookbooks/test/recipes/gem.rb b/test/fixtures/cookbooks/test/recipes/gem.rb deleted file mode 100644 index 21acbc3e..00000000 --- a/test/fixtures/cookbooks/test/recipes/gem.rb +++ /dev/null @@ -1,53 +0,0 @@ -# Make sure that Vagarant user is on the box for dokken -include_recipe 'test::dokken' - -# System Install -rbenv_system_install 'system' -# Install several Rubies to a system wide location -rbenv_ruby '2.4.1' do - verbose true -end - -rbenv_ruby '2.3.1' do - verbose true -end - -# Set System global version -rbenv_global '2.4.1' - -rbenv_gem 'mail' do - version '2.6.5' - options '--no-rdoc --no-ri' - rbenv_version '2.3.1' -end - -rbenv_gem 'mail' do - version '2.6.5' - options '--no-rdoc --no-ri' - rbenv_version '2.4.1' -end - -rbenv_gem 'mail' do - version '2.6.5' - rbenv_version '2.4.1' - action :remove -end - -# User Install -rbenv_user_install 'vagrant' - -# Install a Ruby to a user directory -rbenv_ruby '2.3.1' do - user 'vagrant' -end - -# Set the vagrant global version -rbenv_global '2.3.1' do - user 'vagrant' -end - -rbenv_gem 'bundler' do - version '1.15.4' - user 'vagrant' - rbenv_version '2.3.1' -end diff --git a/test/fixtures/cookbooks/test/recipes/global.rb b/test/fixtures/cookbooks/test/recipes/global.rb deleted file mode 100644 index 152a2c4d..00000000 --- a/test/fixtures/cookbooks/test/recipes/global.rb +++ /dev/null @@ -1,14 +0,0 @@ -global_version = '2.4.1' - -# Install Rbenv Globally -rbenv_system_install 'system' - -rbenv_ruby global_version do - verbose true -end - -# Make sure that Vagarant user is on the box for dokken -include_recipe 'test::dokken' - -# Set that Ruby as the global Ruby -rbenv_global global_version diff --git a/test/fixtures/cookbooks/test/recipes/plugin.rb b/test/fixtures/cookbooks/test/recipes/plugin.rb deleted file mode 100644 index 1bdb6fd0..00000000 --- a/test/fixtures/cookbooks/test/recipes/plugin.rb +++ /dev/null @@ -1,28 +0,0 @@ -version = '2.4.1' - -# Make sure that Vagarant user is on the box for dokken -include_recipe 'test::dokken' - -rbenv_user_install 'vagrant' - -rbenv_system_install 'system' - -rbenv_ruby version do - install_ruby_build false - user 'vagrant' -end - -rbenv_global version do - user 'vagrant' -end - -rbenv_plugin 'ruby-build' do - git_url 'https://github.com/rbenv/ruby-build.git' - user 'vagrant' -end - -# This should get installed to the system_install -rbenv_plugin 'user-gems' do - git_url 'git@github.com:mislav/rbenv-user-gems.git' - git_ref 'v1.0.1' -end diff --git a/test/fixtures/cookbooks/test/recipes/rehash.rb b/test/fixtures/cookbooks/test/recipes/rehash.rb deleted file mode 100644 index e7596e3e..00000000 --- a/test/fixtures/cookbooks/test/recipes/rehash.rb +++ /dev/null @@ -1 +0,0 @@ -rbenv_rehash 'defaultness' diff --git a/test/fixtures/cookbooks/test/recipes/ruby_uninstall.rb b/test/fixtures/cookbooks/test/recipes/ruby_uninstall.rb deleted file mode 100644 index c6f32216..00000000 --- a/test/fixtures/cookbooks/test/recipes/ruby_uninstall.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -system_version = '2.5.1' - -# Make sure that Vagarant user is on the box for dokken -include_recipe 'test::dokken' - -# System Install -rbenv_system_install 'system' - -# Install system wide Ruby -rbenv_ruby system_version - -# Set System global version -rbenv_global system_version - -# Uninstall Ruby -rbenv_ruby system_version do - rbenv_action 'uninstall' -end diff --git a/test/fixtures/cookbooks/test/recipes/script.rb b/test/fixtures/cookbooks/test/recipes/script.rb deleted file mode 100644 index 67619d85..00000000 --- a/test/fixtures/cookbooks/test/recipes/script.rb +++ /dev/null @@ -1,3 +0,0 @@ -rbenv_script 'not-much' do - code 'rake nadda' -end diff --git a/test/fixtures/cookbooks/test/recipes/system_install.rb b/test/fixtures/cookbooks/test/recipes/system_install.rb deleted file mode 100644 index 1d62923e..00000000 --- a/test/fixtures/cookbooks/test/recipes/system_install.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Install Rbenv to the system path e.g. /usr/local/rbenv -rbenv_system_install 'system' do - update_rbenv false -end diff --git a/test/fixtures/cookbooks/test/recipes/user_install.rb b/test/fixtures/cookbooks/test/recipes/user_install.rb deleted file mode 100644 index e2eac8f9..00000000 --- a/test/fixtures/cookbooks/test/recipes/user_install.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Install rbenv and makes it avilable to the selected user -version = '2.4.1' - -# Make sure that Vagarant user is on the box for dokken -include_recipe 'test::dokken' - -# Keeps the rbenv install upto date -rbenv_user_install 'vagrant' - -rbenv_plugin 'ruby-build' do - git_url 'https://github.com/rbenv/ruby-build.git' - user 'vagrant' -end - -rbenv_ruby '2.4.1' do - user 'vagrant' -end - -rbenv_global version do - user 'vagrant' -end diff --git a/test/integration/custom_group_install/controls/default.rb b/test/integration/custom_group_install/controls/default.rb deleted file mode 100644 index d2451feb..00000000 --- a/test/integration/custom_group_install/controls/default.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -global_ruby = '2.4.1' - -control 'Rbenv should be installed' do - title 'Rbenv should be installed to the users home directory' - - desc 'Rbenv should be installed' - describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/rbenv.sh && rbenv global"') do - its('exit_status') { should eq 0 } - its('stdout') { should include(global_ruby) } - end - - describe file('/home/vagrant/.rbenv/versions') do - it { should exist } - it { should be_writable.by_user('vagrant') } - its('group') { should eq 'new-group' } - end - - describe file('/home/vagrant/.rbenv') do - it { should exist } - it { should be_writable.by_user('vagrant') } - its('group') { should eq 'new-group' } - end -end - -control 'ruby-build plugin should be installed' do - title 'ruby-build should be installed to the users home directory' - describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/rbenv.sh && rbenv install -l"') do - its('exit_status') { should eq 0 } - its('stdout') { should include('2.3.4') } - its('stdout') { should include(global_ruby) } - end -end - -control 'Global Ruby' do - title 'Rbenv should be installed globally' - - desc "Can set global Ruby version to #{global_ruby}" - describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/rbenv.sh && rbenv versions --bare"') do - its('exit_status') { should eq 0 } - its('stdout') { should include(global_ruby) } - end -end diff --git a/test/integration/custom_group_install/inspec.yml b/test/integration/custom_group_install/inspec.yml deleted file mode 100644 index a82659e5..00000000 --- a/test/integration/custom_group_install/inspec.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: rbenv -title: rbenv profile -maintainer: Sous Chefs -copyright: Webb Agile Solutions Ltd. -license: Apache-2.0 -summary: Verifies rbenv is installed correctly for a user & group -version: 1.0.0 -supports: - - os-family: linux diff --git a/test/integration/gem/controls/gem_install.rb b/test/integration/gem/controls/gem_install.rb deleted file mode 100644 index 12ec7964..00000000 --- a/test/integration/gem/controls/gem_install.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true -global_ruby = '2.4.1' - -control 'Global Gem Install' do - title 'Should install Mail Gem globally' - - desc "Can set global Ruby version to #{global_ruby}" - describe bash('source /etc/profile.d/rbenv.sh && rbenv versions --bare') do - its('exit_status') { should eq 0 } - its('stdout') { should include(global_ruby) } - end - - desc '2.3.1 Gem should have mail installed' - describe bash('/usr/local/rbenv/versions/2.3.1/bin/gem list --local mail') do - its('exit_status') { should eq 0 } - its('stdout') { should include('2.6.5') } - its('stdout') { should_not include('2.6.6') } - end - - desc '2.4.1 Gem should not have any mail version installed' - describe bash('/usr/local/rbenv/versions/2.4.1/bin/gem list --local') do - its('exit_status') { should eq 0 } - its('stdout') { should_not include('2.6.5') } - its('stdout') { should_not include('2.6.6') } - end - - desc 'gem home should be rbenv in an rbenv directory' - describe bash('source /etc/profile.d/rbenv.sh && gem env home') do - its('exit_status') { should eq 0 } - its('stdout') { should include("/usr/local/rbenv/versions/#{global_ruby}/lib/ruby/gems/2.4.0") } - end -end - -control 'User Gem Install' do - title 'Should install Bundler Gem to a user home' - - desc 'Gemspec file should have correct ownership' - describe file('/home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/bundler-1.15.4.gemspec') do - it { should exist } - it { should be_owned_by 'vagrant' } - end -end diff --git a/test/integration/gem/inspec.yml b/test/integration/gem/inspec.yml deleted file mode 100644 index a2e3c8bf..00000000 --- a/test/integration/gem/inspec.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: rbenv -title: rbenv profile -maintainer: Sous Chefs -copyright: Webb Agile Solutions Ltd. -license: Apache-2.0 -summary: Verifies gems install correctly to the correct Ruby versions -version: 1.0.0 -supports: - - os-family: linux diff --git a/test/integration/global/controls/global_install.rb b/test/integration/global/controls/global_install.rb deleted file mode 100644 index a1a96cab..00000000 --- a/test/integration/global/controls/global_install.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true -global_ruby = '2.4.1' - -control 'Rbenv should be installed' do - title 'Rbenv should be installed globally' - - desc "Can set global Ruby version to #{global_ruby}" - describe bash('source /etc/profile.d/rbenv.sh && rbenv versions --bare') do - its('exit_status') { should eq 0 } - its('stdout') { should include(global_ruby) } - end -end diff --git a/test/integration/global/inspec.yml b/test/integration/global/inspec.yml deleted file mode 100644 index 348bf277..00000000 --- a/test/integration/global/inspec.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: rbenv -title: rbenv profile -maintainer: Sous Chefs -copyright: Webb Agile Solutions Ltd. -license: Apache-2.0 -summary: Verifies rbenv correctly sets the global Ruby version -version: 1.0.0 -supports: - - os-family: linux diff --git a/test/integration/issues/.gitkeep b/test/integration/issues/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/integration/recipes/custom_group_install/controls/default.rb b/test/integration/recipes/custom_group_install/controls/default.rb new file mode 100644 index 00000000..bd8350d7 --- /dev/null +++ b/test/integration/recipes/custom_group_install/controls/default.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +global_julia = '1.0.1' + +control 'Jlenv should be installed' do + title 'Jlenv should be installed to the users home directory' + + desc 'Jlenv should be installed' + describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/jlenv.sh && jlenv global"') do + its('exit_status') { should eq 0 } + its('stdout') { should include(global_julia) } + end + + describe file('/home/vagrant/.jlenv/versions') do + it { should exist } + it { should be_writable.by_user('vagrant') } + its('group') { should eq 'new-group' } + end + + describe file('/home/vagrant/.jlenv') do + it { should exist } + it { should be_writable.by_user('vagrant') } + its('group') { should eq 'new-group' } + end +end + +control 'julia-build plugin should be installed' do + title 'julia-build should be installed to the users home directory' + describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/jlenv.sh && jlenv install -l"') do + its('exit_status') { should eq 0 } + its('stdout') { should include('2.3.4') } + its('stdout') { should include(global_julia) } + end +end + +control 'Global Julia' do + title 'Jlenv should be installed globally' + + desc "Can set global Julia version to #{global_julia}" + describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/jlenv.sh && jlenv versions --bare"') do + its('exit_status') { should eq 0 } + its('stdout') { should include(global_julia) } + end +end diff --git a/test/integration/recipes/custom_group_install/inspec.yml b/test/integration/recipes/custom_group_install/inspec.yml new file mode 100644 index 00000000..27dea8ef --- /dev/null +++ b/test/integration/recipes/custom_group_install/inspec.yml @@ -0,0 +1,10 @@ +--- +name: jlenv +title: jlenv profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +license: Apache-2.0 +summary: Verifies jlenv is installed correctly for a user & group +version: 1.0.0 +supports: + - os-family: linux diff --git a/test/integration/resources/controls/cookbook.rb b/test/integration/resources/controls/cookbook.rb new file mode 100644 index 00000000..9c3e7f96 --- /dev/null +++ b/test/integration/resources/controls/cookbook.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +title 'Jlenv Resource Cookbook Audit Controls' + +include_controls 'system_install' +include_controls 'user_install' diff --git a/test/integration/resources/inspec.yml b/test/integration/resources/inspec.yml new file mode 100644 index 00000000..de1a2e0a --- /dev/null +++ b/test/integration/resources/inspec.yml @@ -0,0 +1,17 @@ +--- +name: jlenv +title: jlenv resource defaults wrapper profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +copyright_email: admin@taqtiqa.com +license: Apache-2.0 +summary: Verifies jlenv resources correctly functions with defaults. +version: 0.1.0 +inspec_version: "~> 3.0" +supports: + - os-family: linux +depends: + - name: system_install + path: test/integration/resources/system_install + - name: user_install + path: test/integration/resources/user_install diff --git a/test/integration/resources/julia/controls/julia.rb b/test/integration/resources/julia/controls/julia.rb new file mode 100644 index 00000000..493c8516 --- /dev/null +++ b/test/integration/resources/julia/controls/julia.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +title 'Jlenv System Install Resource' + +control 'Jlenv system install' do + title 'Jlenv should be installed system wide' + + desc 'Jlenv should be installed and run successfully' + describe bash('source /etc/profile.d/jlenv.sh && jlenv versions --bare') do + its('exit_status') { should eq 0 } + end +end diff --git a/test/integration/resources/julia/inspec.yml b/test/integration/resources/julia/inspec.yml new file mode 100644 index 00000000..7115a526 --- /dev/null +++ b/test/integration/resources/julia/inspec.yml @@ -0,0 +1,10 @@ +--- +name: jlenv +title: jlenv julia resource profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +license: Apache-2.0 +summary: Verifies jlenv julia resource correctly functions with defaults. +version: 0.1.0 +supports: + - os-family: linux diff --git a/test/integration/resources/julia_uninstall/controls/julia_uninstall.rb b/test/integration/resources/julia_uninstall/controls/julia_uninstall.rb new file mode 100644 index 00000000..0a6f778c --- /dev/null +++ b/test/integration/resources/julia_uninstall/controls/julia_uninstall.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +global_system_julia = '1.1.0' + +control 'Julia uninstall' do + title 'Julia should be uninstalled' + + desc "#{global_system_julia} should be uninstalled" + describe bash('source /etc/profile.d/jlenv.sh && jlenv versions --bare') do + its('exit_status') { should eq 0 } + its('stdout') { should_not match(/#{Regexp.quote(global_system_julia)}/) } + end +end diff --git a/test/integration/resources/julia_uninstall/inspec.yml b/test/integration/resources/julia_uninstall/inspec.yml new file mode 100644 index 00000000..d50bd803 --- /dev/null +++ b/test/integration/resources/julia_uninstall/inspec.yml @@ -0,0 +1,9 @@ +--- +name: jlenv +title: jlenv julia_uninstall resourse profile +maintainer: Taqtiqa LLC +license: Apache-2.0 +summary: Verifies jlenv julia_uninstall resource correctly functions with defaults. +version: 1.0.0 +supports: + - os-family: linux diff --git a/test/integration/resources/plugin/controls/plugin.rb b/test/integration/resources/plugin/controls/plugin.rb new file mode 100644 index 00000000..b81b4a19 --- /dev/null +++ b/test/integration/resources/plugin/controls/plugin.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +title 'Jlenv Plugin Resource Defaults' + +control 'julia-build plugin should be installed' do + title 'julia-build should be installed to the users home directory' + + desc 'Jlenv should be installed and run successfully' + describe bash('source /etc/profile.d/jlenv.sh && jlenv versions --bare') do + its('exit_status') { should eq 0 } + end + + desc 'Julia build versions available can now be listed.' + describe bash("sudo -H -u #{julia_user} bash -c 'source /etc/profile.d/jlenv.sh && jlenv install -l'") do + its('exit_status') { should eq 0 } + its('stdout') { should include(user_julia_version) } + its('stderr') { should eq '' } + end +end diff --git a/test/integration/resources/plugin/inspec.yml b/test/integration/resources/plugin/inspec.yml new file mode 100644 index 00000000..e0646d36 --- /dev/null +++ b/test/integration/resources/plugin/inspec.yml @@ -0,0 +1,10 @@ +--- +name: jlenv +title: jlenv plugin resource profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +license: Apache-2.0 +summary: Verifies jlenv plugin resource correctly functions with defaults. +version: 0.1.0 +supports: + - os-family: linux diff --git a/test/integration/resources/rehash/controls/rehash.rb b/test/integration/resources/rehash/controls/rehash.rb new file mode 100644 index 00000000..493c8516 --- /dev/null +++ b/test/integration/resources/rehash/controls/rehash.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +title 'Jlenv System Install Resource' + +control 'Jlenv system install' do + title 'Jlenv should be installed system wide' + + desc 'Jlenv should be installed and run successfully' + describe bash('source /etc/profile.d/jlenv.sh && jlenv versions --bare') do + its('exit_status') { should eq 0 } + end +end diff --git a/test/integration/resources/rehash/inspec.yml b/test/integration/resources/rehash/inspec.yml new file mode 100644 index 00000000..cb329b04 --- /dev/null +++ b/test/integration/resources/rehash/inspec.yml @@ -0,0 +1,10 @@ +--- +name: jlenv +title: jlenv rehash resource profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +license: Apache-2.0 +summary: Verifies jlenv rehash resource is installed correctly system wide. +version: 0.1.0 +supports: + - os-family: linux diff --git a/test/integration/resources/script/controls/script.rb b/test/integration/resources/script/controls/script.rb new file mode 100644 index 00000000..493c8516 --- /dev/null +++ b/test/integration/resources/script/controls/script.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +title 'Jlenv System Install Resource' + +control 'Jlenv system install' do + title 'Jlenv should be installed system wide' + + desc 'Jlenv should be installed and run successfully' + describe bash('source /etc/profile.d/jlenv.sh && jlenv versions --bare') do + its('exit_status') { should eq 0 } + end +end diff --git a/test/integration/resources/script/inspec.yml b/test/integration/resources/script/inspec.yml new file mode 100644 index 00000000..38c60a5e --- /dev/null +++ b/test/integration/resources/script/inspec.yml @@ -0,0 +1,10 @@ +--- +name: jlenv +title: jlenv script resource profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +license: Apache-2.0 +summary: Verifies jlenv script resource correctly functions with defaults. +version: 0.1.0 +supports: + - os-family: linux diff --git a/test/integration/resources/system_install/controls/global_install.rb b/test/integration/resources/system_install/controls/global_install.rb new file mode 100644 index 00000000..3e0e0fe7 --- /dev/null +++ b/test/integration/resources/system_install/controls/global_install.rb @@ -0,0 +1,148 @@ +# frozen_string_literal: true + +title 'Jlenv System Install Resource' + +# Default user in resources is jovyan i.e. Jupyter assumption +julia_users ||= yaml(content: inspec.profile.file('users.yml'))['users'] +julia_user ||= 'vagrant' +global_julia_version ||= julia_users[julia_user]['version'] + +jlenv_global = command("sudo -H -u #{julia_user} bash -c 'source /etc/profile.d/jlenv.sh && jlenv global'") + +# frozen_string_literal: true + +control 'Jlenv system install' do + title 'Jlenv should be installed system wide' + + desc 'Jlenv should be installed and run successfully' + describe bash('source /etc/profile.d/jlenv.sh && jlenv versions --bare') do + its('exit_status') { should eq 0 } + end +end + +control 'Jlenv system path' do + title 'Jlenv should be installed in the system wide location' + + describe file('/usr/local/jlenv') do + it { should exist } + it { should be_directory } + end + + # Issue: https://github.com/jlenv/jlenv-cookbook/issues/3 + # Issue: https://github.com/jlenv/jlenv-cookbook/issues/4 + # + describe file('/etc/profile.d/jlenv.sh') do + its('type') { should eq :file } + its('group') { should eq 'root' } + its('owner') { should eq 'root' } + its('mode') { should cmp '0755' } + it { should be_executable.by('others') } + it { should_not be_writable.by('others') } + end + +end + +control 'Global Installations' do + impact 0.6 + title 'Jlenv should be installed under the .... directory.' + desc 'Always specify environment variables, folders and permissions.' + desc 'Rationale:', 'This ensures that there are no unexpected scripts run.' # Requires InSpec >=2.3.4 + tag 'julia', 'jlenv' + #ref 'NSA-RH6-STIG - Section 3.5.2.1', url: 'https://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf' + + # before :all do + # command("sudo -H -u #{julia_user} bash -c 'source /etc/profile.d/jlenv.sh && jlenv global'") + # end + + # The following nested describe is blocked by inspec issue #630: + # + # + # Workarounds not yet known. + # Best practice to audit os_env(...) generated by user scripts not known. + # + # describe jlenv_global do + # env_vars = %w( + # HOME + # PATH + # ) + # + # env_vars.each do |e| + # describe os_env(e) do + # its('content') { should_not eq nil } + # its('content') { should_not eq '' } + # its('split'){ should_not eq '' } + # its('split'){ should_not eq '.' } + # end + # end + # end + + describe bash('source /etc/profile.d/jlenv.sh && jlenv versions --bare') do + its('exit_status') { should eq 0 } + its('stdout') { should include(global_julia_version ) } + end + + describe jlenv_global do + its('exit_status') { should eq 0 } + its('stdout') { should include('system') } + its('stdout') { should_not include(global_julia_version ) } + its('stderr') { should eq '' } + end + + %w(plugins shims versions).each do |d| + describe directory("/home/#{julia_user}/.jlenv/#{d}") do + its('type') { should eq :directory } + its('mode') { should cmp '0755' } + it { should be_writable.by_user(julia_user) } + end + end + + # Issue: https://github.com/jlenv/jlenv-cookbook/issues/3 + # Refactor this control to verify the user install script has had no + # (unintended/specified) side effect on the system install (and vice versa). + describe file('/etc/profile.d/jlenv.sh') do + it { should_not be_writable.by_user(julia_user) } + it { should be_executable.by('others') } + it { should be_executable.by_user(julia_user) } + end + + describe directory("/home/#{julia_user}/.jlenv/.git") do + its('type') { should eq :directory } + its('mode') { should cmp '0755' } + it { should be_writable.by_user(julia_user) } + end + + describe os_env('PATH', 'target') do + its('split') { should_not include('') } + its('split') { should_not include('.') } + its('split') { should include("/home/#{julia_user}/.jlenv/shims") } + end +end + +control 'Global Installations' do + title 'Jlenv should be installed globally' + + desc "Can set global Julia version toglobal}" + jlenv_versions = command("sudo -H -u #{julia_user} bash -c 'source /etc/profile.d/jlenv.sh && jlenv versions --bare'") + describe jlenv_versions do + its('exit_status') { should eq 0 } + its('stdout') { should_not include(global_julia_version) } + its('stderr') { should eq '' } + end + + jlenv_env_vars = %w( + JLENV_DEBUG + JLENV_DIR + JLENV_HOOK_PATH + JLENV_ROOT + JLENV_VERSION + ) + + jlenv_env_vars.each do |e| + describe os_env(e) do + its('content') { should eq nil } + its('content') { should_not eq '' } + its('split'){ should_not eq '' } + its('split'){ should_not eq '.' } + end + end +end diff --git a/test/integration/resources/system_install/files/users.yml b/test/integration/resources/system_install/files/users.yml new file mode 100644 index 00000000..f4546a57 --- /dev/null +++ b/test/integration/resources/system_install/files/users.yml @@ -0,0 +1,13 @@ +users: + jovyan: + group: jovyan + version: '1.0.5' + ubuntu: + group: ubuntu + version: '1.2.0' + vagrant: + group: vagrant + version: '1.0.2' + root: + group: root + version: '1.0.0' diff --git a/test/integration/resources/system_install/inspec.yml b/test/integration/resources/system_install/inspec.yml new file mode 100644 index 00000000..83edebb3 --- /dev/null +++ b/test/integration/resources/system_install/inspec.yml @@ -0,0 +1,12 @@ +--- +name: jlenv +title: jlenv global resource profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +copyright_email: admin@taqtiqa.com +license: Apache-2.0 +summary: Verifies jlenv global resource correctly functions with defaults. +version: 0.1.0 +inspec_version: "~> 2.1" +supports: + - os-family: linux diff --git a/test/integration/resources/user_install/controls/user_install.rb b/test/integration/resources/user_install/controls/user_install.rb new file mode 100644 index 00000000..9b66fbfd --- /dev/null +++ b/test/integration/resources/user_install/controls/user_install.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +title 'Jlenv User Install Resource' + +# Default user in resources is jovyan i.e. Jupyter assumption +julia_users ||= yaml(content: inspec.profile.file('users.yml'))['users'] +julia_user ||= 'vagrant' +user_julia_version ||= julia_users[julia_user]['version'] + +jlenv_global = command("sudo -H -u #{julia_user} bash -c 'source /etc/profile.d/jlenv.sh && jlenv global'") + +control 'User Installations' do + impact 0.6 + title 'Jlenv should be installed under the users home directory.' + desc 'Always specify environment variables, folders and permissions.' + desc 'Rationale:', 'This ensures that there are no unexpected scripts run.' # Requires InSpec >=2.3.4 + tag 'julia', 'jlenv' + #ref 'NSA-RH6-STIG - Section 3.5.2.1', url: 'https://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf' + + # before :all do + # command("sudo -H -u #{julia_user} bash -c 'source /etc/profile.d/jlenv.sh && jlenv global'") + # end + + # The following nested describe is blocked by inspec issue #630: + # + # + # Workarounds not yet known. + # Best practice to audit os_env(...) generated by user scripts not known. + # + # describe jlenv_global do + # env_vars = %w( + # HOME + # PATH + # ) + # + # env_vars.each do |e| + # describe os_env(e) do + # its('content') { should_not eq nil } + # its('content') { should_not eq '' } + # its('split'){ should_not eq '' } + # its('split'){ should_not eq '.' } + # end + # end + # end + + describe jlenv_global do + its('exit_status') { should eq 0 } + its('stdout') { should include('system') } + its('stdout') { should_not include(user_julia_version) } + its('stderr') { should eq '' } + end + + %w(plugins shims versions).each do |d| + describe directory("/home/#{julia_user}/.jlenv/#{d}") do + its('type') { should eq :directory } + its('mode') { should cmp '0755' } + it { should be_writable.by_user(julia_user) } + end + end + + # Issue: https://github.com/jlenv/jlenv-cookbook/issues/3 + # Refactor this control to verify the user install script has had no + # (unintended/specified) side effect on the system install (and vice versa). + describe file('/etc/profile.d/jlenv.sh') do + it { should_not be_writable.by_user(julia_user) } + it { should be_executable.by('others') } + it { should be_executable.by_user(julia_user) } + end + + describe directory("/home/#{julia_user}/.jlenv/.git") do + its('type') { should eq :directory } + its('mode') { should cmp '0755' } + it { should be_writable.by_user(julia_user) } + end + + describe os_env('PATH', 'target') do + its('split') { should_not include('') } + its('split') { should_not include('.') } + its('split') { should include("/home/#{julia_user}/.jlenv/shims") } + end +end + +control 'User Installations' do + title 'Jlenv should be installed locally' + + desc "Can set user-space Julia version to #{user_julia_version}" + jlenv_versions = command("sudo -H -u #{julia_user} bash -c 'source /etc/profile.d/jlenv.sh && jlenv versions --bare'") + describe jlenv_versions do + its('exit_status') { should eq 0 } + its('stdout') { should_not include(user_julia_version) } + its('stderr') { should eq '' } + end + + jlenv_env_vars = %w( + JLENV_DEBUG + JLENV_DIR + JLENV_HOOK_PATH + JLENV_ROOT + JLENV_VERSION + ) + + jlenv_env_vars.each do |e| + describe os_env(e) do + its('content') { should eq nil } + its('content') { should_not eq '' } + its('split'){ should_not eq '' } + its('split'){ should_not eq '.' } + end + end +end diff --git a/test/integration/resources/user_install/files/users.yml b/test/integration/resources/user_install/files/users.yml new file mode 100644 index 00000000..f4546a57 --- /dev/null +++ b/test/integration/resources/user_install/files/users.yml @@ -0,0 +1,13 @@ +users: + jovyan: + group: jovyan + version: '1.0.5' + ubuntu: + group: ubuntu + version: '1.2.0' + vagrant: + group: vagrant + version: '1.0.2' + root: + group: root + version: '1.0.0' diff --git a/test/integration/resources/user_install/inspec.yml b/test/integration/resources/user_install/inspec.yml new file mode 100644 index 00000000..9dd9ed6f --- /dev/null +++ b/test/integration/resources/user_install/inspec.yml @@ -0,0 +1,10 @@ +--- +name: jlenv +title: jlenv julia resource profile +maintainer: Taqtiqa LLC +copyright: Taqtiqa LLC +license: Apache-2.0 +summary: Verifies jlenv user_install resource correctly functions with defaults. +version: 1.0.0 +supports: + - os-family: linux diff --git a/test/integration/ruby_uninstall/controls/ruby_uninstall.rb b/test/integration/ruby_uninstall/controls/ruby_uninstall.rb deleted file mode 100644 index d6371d31..00000000 --- a/test/integration/ruby_uninstall/controls/ruby_uninstall.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -global_system_ruby = '2.5.1' - -control 'Ruby uninstall' do - title 'Ruby should be uninstalled' - - desc "#{global_system_ruby} should be uninstalled" - describe bash('source /etc/profile.d/rbenv.sh && rbenv versions --bare') do - its('exit_status') { should eq 0 } - its('stdout') { should_not match(/#{Regexp.quote(global_system_ruby)}/) } - end -end diff --git a/test/integration/ruby_uninstall/inspec.yml b/test/integration/ruby_uninstall/inspec.yml deleted file mode 100644 index 4ed195d7..00000000 --- a/test/integration/ruby_uninstall/inspec.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: rbenv -title: rbenv profile -maintainer: Sous Chefs -license: Apache-2.0 -summary: Verifies that Rubies can be uninstalled -version: 1.0.0 -supports: - - os-family: linux diff --git a/test/integration/system_install/controls/system_install.rb b/test/integration/system_install/controls/system_install.rb deleted file mode 100644 index 0b418885..00000000 --- a/test/integration/system_install/controls/system_install.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -control 'Rbenv system install' do - title 'Rbenv should be installed system wide' - - desc 'Rbenv should be installed and run successfully' - describe bash('source /etc/profile.d/rbenv.sh && rbenv versions --bare') do - its('exit_status') { should eq 0 } - end -end - -control 'Rbenv system path' do - title 'Rbenv should be installed in the system wide location' - - describe file('/usr/local/rbenv') do - it { should exist } - it { should be_directory } - end -end diff --git a/test/integration/system_install/inspec.yml b/test/integration/system_install/inspec.yml deleted file mode 100644 index 2476593d..00000000 --- a/test/integration/system_install/inspec.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: rbenv -title: rbenv profile -maintainer: Sous Chefs -copyright: Webb Agile Solutions Ltd. -license: Apache-2.0 -summary: Verifies rbenv is installed correctly system wide -version: 1.0.0 -supports: - - os-family: linux diff --git a/test/integration/user_install/controls/user_install.rb b/test/integration/user_install/controls/user_install.rb deleted file mode 100644 index 88c5aab1..00000000 --- a/test/integration/user_install/controls/user_install.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -global_ruby = '2.4.1' - -control 'Rbenv should be installed' do - title 'Rbenv should be installed to the users home directory' - - desc 'Rbenv should be installed' - describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/rbenv.sh && rbenv global"') do - its('exit_status') { should eq 0 } - its('stdout') { should include(global_ruby) } - end - - describe file('/home/vagrant/.rbenv/versions') do - it { should exist } - it { should be_writable.by_user('vagrant') } - end -end - -control 'ruby-build plugin should be installed' do - title 'ruby-build should be installed to the users home directory' - describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/rbenv.sh && rbenv install -l"') do - its('exit_status') { should eq 0 } - its('stdout') { should include('2.3.4') } - its('stdout') { should include(global_ruby) } - end -end - -control 'Global Ruby' do - title 'Rbenv should be installed globally' - - desc "Can set global Ruby version to #{global_ruby}" - describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/rbenv.sh && rbenv versions --bare"') do - its('exit_status') { should eq 0 } - its('stdout') { should include(global_ruby) } - end -end diff --git a/test/integration/user_install/inspec.yml b/test/integration/user_install/inspec.yml deleted file mode 100644 index 354eed0b..00000000 --- a/test/integration/user_install/inspec.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: rbenv -title: rbenv profile -maintainer: Sous Chefs -copyright: Webb Agile Solutions Ltd. -license: Apache-2.0 -summary: Verifies rbenv is installed correctly for a user -version: 1.0.0 -supports: - - os-family: linux diff --git a/test/spec/recipes/default_spec.rb b/test/spec/recipes/default_spec.rb new file mode 100644 index 00000000..2aa77593 --- /dev/null +++ b/test/spec/recipes/default_spec.rb @@ -0,0 +1,13 @@ +require_relative '../recipes_spec_helper' + +describe 'jlenv::default' do + + let(:chef_run) do + ChefSpec::SoloRunner.new.converge(described_recipe) + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + +end diff --git a/test/spec/recipes/system_install_spec.rb b/test/spec/recipes/system_install_spec.rb new file mode 100644 index 00000000..ebba144d --- /dev/null +++ b/test/spec/recipes/system_install_spec.rb @@ -0,0 +1,11 @@ +require_relative '../recipes_spec_helper' + +describe 'recipes::system_install' do + let(:chef_run) do + ChefSpec::SoloRunner.new.converge(described_recipe) + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end +end diff --git a/test/spec/recipes_spec_helper.rb b/test/spec/recipes_spec_helper.rb new file mode 100644 index 00000000..68b16ec8 --- /dev/null +++ b/test/spec/recipes_spec_helper.rb @@ -0,0 +1,11 @@ +require 'chefspec' +require 'chefspec/policyfile' + +RSpec.configure do |config| + config.mock_with :rspec do |mocks| + mocks.syntax = :expect + end + config.platform = 'ubuntu' + config.version = '18.04' + config.policyfile_path = File.join(Dir.pwd, 'test', 'fixtures', 'cookbooks', 'recipes', 'Policyfile.rb') +end diff --git a/test/spec/resources/plugin_spec.rb b/test/spec/resources/plugin_spec.rb new file mode 100644 index 00000000..3de69ba3 --- /dev/null +++ b/test/spec/resources/plugin_spec.rb @@ -0,0 +1,9 @@ +require_relative '../resources_spec_helper' + +describe 'resources::plugin' do + let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end +end diff --git a/test/spec/resources/user_install_spec.rb b/test/spec/resources/user_install_spec.rb new file mode 100644 index 00000000..9356b64f --- /dev/null +++ b/test/spec/resources/user_install_spec.rb @@ -0,0 +1,9 @@ +require_relative '../resources_spec_helper' + +describe 'resources::user_install' do + let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end +end diff --git a/test/spec/resources_spec_helper.rb b/test/spec/resources_spec_helper.rb new file mode 100644 index 00000000..6225e04b --- /dev/null +++ b/test/spec/resources_spec_helper.rb @@ -0,0 +1,11 @@ +require 'chefspec' +require 'chefspec/policyfile' + +RSpec.configure do |config| + config.mock_with :rspec do |mocks| + mocks.syntax = :expect + end + config.platform = 'ubuntu' + config.version = '18.04' + config.policyfile_path = File.join(Dir.pwd, 'test', 'fixtures', 'cookbooks', 'resources', 'Policyfile.rb') +end diff --git a/test/unit/default_spec.rb b/test/unit/default_spec.rb deleted file mode 100644 index f0ec1437..00000000 --- a/test/unit/default_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'chefspec' -require 'chefspec/berkshelf' - -describe 'ruby_rbenv::default' do - let(:chef_run) do - ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end -end diff --git a/test/unit/system_install_spec.rb b/test/unit/system_install_spec.rb deleted file mode 100644 index e8876dcb..00000000 --- a/test/unit/system_install_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'chefspec' -require 'chefspec/berkshelf' - -describe 'ruby_rbenv::system_install' do - let(:chef_run) do - ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end -end diff --git a/test/unit/system_spec.rb b/test/unit/system_spec.rb deleted file mode 100644 index 075f681a..00000000 --- a/test/unit/system_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'chefspec' -require 'chefspec/berkshelf' - -describe 'ruby_rbenv::system' do - let(:chef_run) do - ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end -end diff --git a/test/unit/user_install_spec.rb b/test/unit/user_install_spec.rb deleted file mode 100644 index fb4fdc25..00000000 --- a/test/unit/user_install_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'chefspec' -require 'chefspec/berkshelf' - -describe 'ruby_rbenv::user_install' do - let(:chef_run) do - ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end -end diff --git a/test/unit/user_spec.rb b/test/unit/user_spec.rb deleted file mode 100644 index e5b3c2a6..00000000 --- a/test/unit/user_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'chefspec' -require 'chefspec/berkshelf' - -describe 'ruby_rbenv::user' do - let(:chef_run) do - ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end -end