Skip to content

Commit

Permalink
Merge pull request #29 from thmttch/vagrant-nbserver-fixes
Browse files Browse the repository at this point in the history
0.7.2: notebook fixes, miscellaneous cleanup
  • Loading branch information
thmttch authored Dec 10, 2017
2 parents fee8fe2 + 5488f62 commit 5b7a467
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 23 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# CHANGELOG

## 0.7.2

**This is a backwards-INCOMPATIBLE release**

- Catch up with ipython -> jupyter rebranding: renamed everything to juptyer.
This includes directories, attributes, and other backwards-incompatible
changes.
- More fixes to release process: don't include unnecessary files during berkshelf
vendoring and release
- Vagrant and notebook server fixes
- you can use attributes to set the notebook server's security token. _Be
careful with this config!_ It is disabled in the quickstart Vagrant setup
for convenience, and remains _enabled by default_.
- Foodcritic fixes; resolves:
- FC017: LWRP does not notify when updated: anaconda/providers/nbservice.rb:21
- FC017: LWRP does not notify when updated: anaconda/providers/package.rb:21
- FC017: LWRP does not notify when updated: anaconda/providers/package.rb:58
- FC059: LWRP provider does not declare use_inline_resources: anaconda/providers/nbservice.rb:1
- FC059: LWRP provider does not declare use_inline_resources: anaconda/providers/package.rb:1
- FC048: Prefer Mixlib::ShellOut: ./providers/nbservice.rb:12
- FC048: Prefer Mixlib::ShellOut: ./providers/package.rb:12

## 0.7.1

**This cookbook is now up for adoption! See CONTRIBUTING.md for details.**
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ installer itself.
conda 4.3.30
```

It includes a Jupyter (IPython) notebook server accessible at <http://33.33.33.123:8888>
It includes a Jupyter notebook server accessible at
<http://33.33.33.123:8888>. **Token authentication is disabled in the
quickstart Vagrant setup.**

Lastly, to use it in a cookbook:

Expand Down Expand Up @@ -158,7 +160,7 @@ The `anaconda_nbservice` will run a Jupyter notebook server as a runit service:
ip '*'
port '8888'

install_dir '/opt/ipython/server'
install_dir '/opt/jupyter/server'

service_action [ :enable, :start ]
end
Expand All @@ -169,8 +171,8 @@ your own run service template:

```ruby
anaconda_nbservice 'server-with-custom-template' do
user ipython_user
group ipython_group
user jupyter_user
group jupyter_group

install_dir install_dir

Expand Down
3 changes: 2 additions & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ To run the full test suite:
- check for style issues with Foodcritic

```bash
$> foodcritic
# run on the project root dir
$> foodcritic .
```
14 changes: 12 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Vagrant.configure('2') do |config|

# dev optimization: anaconda installers are big, so put it in the guest's
# chef cache if it's available on the host
#
# TODO: need to increase the virtualbox disk space for the installers, eg
# https://unix.stackexchange.com/questions/176687/set-storage-size-on-creation-of-vm-virtualbox
config.trigger.before :provision, :stdout => true do
run_remote <<-SCRIPT
VAGRANT_MOUNT=/vagrant/docker/container/installers
Expand All @@ -45,8 +48,14 @@ Vagrant.configure('2') do |config|

config.vm.provision :chef_solo do |chef|
chef.json = {
:anaconda => {
:accept_license => 'yes',
'anaconda' => {
'accept_license' => 'yes',
'notebook' => {
# set an empty security token, which effectively disables this
# security feature; this is for the quickstart Vagrant image ONLY!
'use_provided_token' => true,
'token' => '',
}
}
}

Expand All @@ -58,6 +67,7 @@ Vagrant.configure('2') do |config|

chef.custom_config_path = 'vagrant-solo.rb'
#chef.log_level = :debug
#chef.verbose_logging = true
end
end

Expand Down
6 changes: 5 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@
'port' => 8888,
'owner' => node['anaconda']['owner'],
'group' => node['anaconda']['group'],
'install_dir' => '/opt/ipython/server',
'install_dir' => '/opt/jupyter/server',
# the default is to NOT set the security token, to ensure that a secure key
# is chosen and set
'use_provided_token' => false,
'token' => '',
}
8 changes: 6 additions & 2 deletions chefignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ test/*
features/*
Guardfile
Procfile
*.log

# SCM #
#######
Expand All @@ -76,8 +77,8 @@ tmp

# Cookbooks #
#############
CONTRIBUTING
CHANGELOG*
#CONTRIBUTING
#CHANGELOG*

# Strainer #
############
Expand All @@ -89,6 +90,7 @@ Strainerfile
# Vagrant #
###########
.vagrant
vagrant-solo.rb
Vagrantfile

# Travis #
Expand All @@ -97,3 +99,5 @@ Vagrantfile

# local anaconda installers should not be part of the cookbook
Anaconda*-*-Linux-*.sh
# install scripts don't need to be in the cookbook
script
24 changes: 15 additions & 9 deletions providers/nbservice.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use_inline_resources

def whyrun_supported?
true
end

def cmd_ipython
"#{node['anaconda']['install_root']}/#{node['anaconda']['version']}/bin/ipython"
def cmd_jupyter
"#{node['anaconda']['install_root']}/#{node['anaconda']['version']}/bin/jupyter"
end

def is_installed?(package_name)
`"#{cmd_conda}" list`.include?(package_name)
Mixlib::ShellOut.new("#{cmd_conda} list").run_command.stdout.include?(package_name)
end

def log_opts(node)
Expand All @@ -26,15 +28,17 @@ def log_opts(node)
owner = r.owner || node['anaconda']['notebook']['owner']
group = r.group || node['anaconda']['notebook']['group']
install_dir = r.install_dir || node['anaconda']['notebook']['install_dir']
use_provided_token = r.use_provided_token || node['anaconda']['notebook']['use_provided_token']
token = r.token || node['anaconda']['notebook']['token']

directory install_dir do
owner owner
group group
recursive true
end

ipython_dir = "#{install_dir}/.ipython"
directory ipython_dir do
jupyter_dir = "#{install_dir}/.juptyer"
directory jupyter_dir do
owner owner
group group
recursive true
Expand All @@ -46,20 +50,22 @@ def log_opts(node)
service_action = r.service_action || [ :enable, :start ]

template_cookbook = r.template_cookbook || 'anaconda'
run_template_name = r.run_template_name || 'ipython-notebook'
run_template_name = r.run_template_name || 'jupyter-notebook'
run_template_opts = r.run_template_opts || {
:owner => owner,
:cmd_ipython => cmd_ipython(),
:cmd_jupyter => cmd_jupyter(),
:notebook_dir => install_dir,
:ipython_dir => ipython_dir,
:jupyter_dir => jupyter_dir,
:ip => ip,
:port => port,
:use_provided_token => use_provided_token,
:token => token,
:pythonpath => pythonpath,
:pythonstartup => pythonstartup,
:files_to_source => files_to_source,
}

runit_service "ipython-notebook-#{r.name}" do
runit_service "jupyter-notebook-#{r.name}" do
options(run_template_opts)
default_logger true
run_template_name run_template_name
Expand Down
4 changes: 3 additions & 1 deletion providers/package.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use_inline_resources

def whyrun_supported?
true
end
Expand All @@ -7,7 +9,7 @@ def cmd_conda
end

def is_installed?(package_name)
`"#{cmd_conda}" list`.include?(package_name)
Mixlib::ShellOut.new("#{cmd_conda} list").run_command.stdout.include?(package_name)
end

def log_opts(node)
Expand Down
2 changes: 2 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
group node['anaconda']['group']
user node['anaconda']['owner'] do
gid node['anaconda']['group']
home node['anaconda']['home']
manage_home true
end

version = node['anaconda']['version']
Expand Down
2 changes: 2 additions & 0 deletions recipes/notebook_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@

install_dir node['anaconda']['notebook']['install_dir']

token node['anaconda']['notebook']['token']

service_action [ :enable, :start ]
end
3 changes: 3 additions & 0 deletions resources/nbservice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

attribute :install_dir, :kind_of => String

attribute :use_provided_token, :kind_of => [TrueClass, FalseClass]
attribute :token, :kind_of => String

# if you really need it
attribute :pythonpath, :kind_of => Array
attribute :pythonstartup, :kind_of => String
Expand Down
2 changes: 1 addition & 1 deletion script/release-config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# https://blog.chef.io/2015/03/16/using-chef-supermarket-a-guided-tour/
node_name 'thmttch'
# this might not work with a relative path, and obviously is not checked in!
client_key 'script/release-key.pem'
client_key '~/.ssh/chef-supermarket-release-key.pem'
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pushd <%= @options[:notebook_dir] %>
exec 2>&1
exec \
<%= "chpst -u #{@options[:owner]}" if @options[:owner] %> \
<%= @options[:cmd_ipython] %> notebook \
--ipython-dir=<%= @options[:ipython_dir] %> \
<%= @options[:cmd_jupyter] %> notebook \
--ip=<%= @options[:ip] %> \
--port=<%= @options[:port] %> \
<%= "--NotebookApp.token='#{@options[:token]}'" if @options[:use_provided_token] %> \
--no-browser

0 comments on commit 5b7a467

Please sign in to comment.