OSDN Git Service

add the bubbleupnp-server cookbook. bubbleupnp-server-0.1.0
authorwhitestar <whitestar@users.osdn.me>
Sun, 24 Feb 2019 07:51:17 +0000 (16:51 +0900)
committerwhitestar <whitestar@users.osdn.me>
Sun, 24 Feb 2019 07:51:17 +0000 (16:51 +0900)
25 files changed:
cookbooks/bubbleupnp-server/.foodcritic [new file with mode: 0644]
cookbooks/bubbleupnp-server/.rubocop.yml [new file with mode: 0644]
cookbooks/bubbleupnp-server/Berksfile [new file with mode: 0644]
cookbooks/bubbleupnp-server/CHANGELOG.md [new file with mode: 0644]
cookbooks/bubbleupnp-server/Gemfile [new file with mode: 0644]
cookbooks/bubbleupnp-server/Gemfile.lock [new file with mode: 0644]
cookbooks/bubbleupnp-server/README.md [new file with mode: 0644]
cookbooks/bubbleupnp-server/Rakefile [new file with mode: 0644]
cookbooks/bubbleupnp-server/attributes/default.rb [new file with mode: 0644]
cookbooks/bubbleupnp-server/chefignore [new file with mode: 0644]
cookbooks/bubbleupnp-server/concourse.yml [new file with mode: 0644]
cookbooks/bubbleupnp-server/fly-vars.local.yml [new file with mode: 0644]
cookbooks/bubbleupnp-server/fly-vars.yml [new file with mode: 0644]
cookbooks/bubbleupnp-server/metadata.rb [new file with mode: 0644]
cookbooks/bubbleupnp-server/recipes/default.rb [new file with mode: 0644]
cookbooks/bubbleupnp-server/recipes/docker-compose.rb [new file with mode: 0644]
cookbooks/bubbleupnp-server/spec/recipes/default_spec.rb [new file with mode: 0644]
cookbooks/bubbleupnp-server/spec/spec_helper.rb [new file with mode: 0644]
cookbooks/bubbleupnp-server/templates/default/etc/cron.d/bubbleupnp-server-local [new file with mode: 0644]
cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/.env [new file with mode: 0644]
cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/Dockerfile [new file with mode: 0644]
cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/Dockerfile.armhf [new file with mode: 0644]
cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/docker-compose.yml [new file with mode: 0644]
cookbooks/bubbleupnp-server/version [new file with mode: 0644]
roles/bubbleupnp-server-on-docker.rb [new file with mode: 0644]

diff --git a/cookbooks/bubbleupnp-server/.foodcritic b/cookbooks/bubbleupnp-server/.foodcritic
new file mode 100644 (file)
index 0000000..f83b06c
--- /dev/null
@@ -0,0 +1,2 @@
+~FC001
+~FC019
diff --git a/cookbooks/bubbleupnp-server/.rubocop.yml b/cookbooks/bubbleupnp-server/.rubocop.yml
new file mode 100644 (file)
index 0000000..4de4294
--- /dev/null
@@ -0,0 +1,53 @@
+AllCops:
+  Exclude:
+    - vendor/**/*
+
+AlignParameters:
+  Enabled: false
+LineLength:
+  Enabled: false
+Lint/UnusedBlockArgument:
+  Enabled: false
+Metrics/AbcSize:
+  Enabled: false
+Style/BlockComments:
+  Enabled: false
+Style/BlockDelimiters:
+  Enabled: false
+Style/ExtraSpacing:
+  Enabled: false
+Style/FileName:
+  Enabled: false
+Style/LeadingCommentSpace:
+  Enabled: false
+Style/RescueModifier:
+  Enabled: false
+Style/SpaceAroundOperators:
+  Enabled: false
+Style/SpaceBeforeFirstArg:
+  Enabled: false
+Style/SpaceInsideBlockBraces:
+  Enabled: false
+Style/SpaceInsidePercentLiteralDelimiters:
+  Enabled: false
+Style/TrailingCommaInLiteral:
+  EnforcedStyleForMultiline: consistent_comma
+Style/WordArray:
+  Enabled: false
+
+#Lint/ShadowingOuterLocalVariable:
+#  Enabled: false
+#Metrics/MethodLength:
+#  Max: 10
+#Metrics/ModuleLength:
+#  Max: 100
+#Metrics/CyclomaticComplexity:
+#  Max: 6
+#Metrics/PerceivedComplexity:
+#  Max: 7
+#Style/AccessorMethodName:
+#  Enabled: false
+#Style/MultilineOperationIndentation:
+#  Enabled: false
+#Style/PerlBackrefs:
+#  Enabled: false
diff --git a/cookbooks/bubbleupnp-server/Berksfile b/cookbooks/bubbleupnp-server/Berksfile
new file mode 100644 (file)
index 0000000..4ed8bef
--- /dev/null
@@ -0,0 +1,19 @@
+#
+# Copyright 2019 whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+source 'https://supermarket.chef.io'
+
+metadata
diff --git a/cookbooks/bubbleupnp-server/CHANGELOG.md b/cookbooks/bubbleupnp-server/CHANGELOG.md
new file mode 100644 (file)
index 0000000..ff123cc
--- /dev/null
@@ -0,0 +1,5 @@
+# bubbleupnp-server CHANGELOG
+
+0.1.0
+-----
+- Initial release of bubbleupnp-server
diff --git a/cookbooks/bubbleupnp-server/Gemfile b/cookbooks/bubbleupnp-server/Gemfile
new file mode 100644 (file)
index 0000000..ad84be7
--- /dev/null
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# with Chef DK
+gem 'stove'
diff --git a/cookbooks/bubbleupnp-server/Gemfile.lock b/cookbooks/bubbleupnp-server/Gemfile.lock
new file mode 100644 (file)
index 0000000..6fb9a3b
--- /dev/null
@@ -0,0 +1,22 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    chef-api (0.8.0)
+      logify (~> 0.1)
+      mime-types
+    logify (0.2.0)
+    mime-types (3.2.2)
+      mime-types-data (~> 3.2015)
+    mime-types-data (3.2018.0812)
+    stove (6.0.0)
+      chef-api (~> 0.5)
+      logify (~> 0.2)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  stove
+
+BUNDLED WITH
+   1.16.0
diff --git a/cookbooks/bubbleupnp-server/README.md b/cookbooks/bubbleupnp-server/README.md
new file mode 100644 (file)
index 0000000..bad7458
--- /dev/null
@@ -0,0 +1,105 @@
+bubbleupnp-server Cookbook
+==========================
+
+This cookbook sets up a BubbleUPnP Server by Docker-compose.
+You can build BubbleUPnP Server Docker image too.
+
+## Contents
+
+- [Requirements](#requirements)
+    - [platforms](#platforms)
+    - [packages](#packages)
+- [Attributes](#attributes)
+- [Usage](#usage)
+    - [Recipes](#recipes)
+        - [bubbleupnp-server::default](#bubbleupnp-serverdefault)
+        - [bubbleupnp-server::docker-compose](#bubbleupnp-serverdocker-compose)
+    - [Role Examples](#role-examples)
+- [License and Authors](#license-and-authors)
+
+## Requirements
+
+### platforms
+
+- Debian >= 9.0
+- Ubuntu >= 16.04
+- CentOS,RHEL >= 7.3
+
+### packages
+- none.
+
+## Attributes
+
+|Key|Type|Description, example|Default|
+|:--|:--|:--|:--|
+|`['bubbleupnp-server']['Dockerfile']['FROM']`|String|Base image in the `Dockerfile`.|See `attributes/default.rb`|
+|`['bubbleupnp-server']['docker-compose']['autopilot']`|Hash|Autopilot configurations.|See `attributes/default.rb`|
+|`['bubbleupnp-server']['docker-compose']['app_dir']`|String||`"#{node['docker-grid']['compose']['app_dir']}/bubbleupnp-server"`|
+|`['bubbleupnp-server']['docker-compose']['data_dir']`|String||`"#{node['bubbleupnp-server']['docker-compose']['app_dir']}/data"`|
+|`['bubbleupnp-server']['docker-compose']['dot_env']`|Hash|`.env` configurations.|See `attributes/default.rb`|
+|`['bubbleupnp-server']['docker-compose']['config']`|Hash|`docker-compose.yml` configurations.|See `attributes/default.rb`|
+
+## Usage
+
+### Recipes
+
+#### bubbleupnp-server::default
+
+This recipe does nothing.
+
+#### bubbleupnp-server::docker-compose
+
+This recipe generates a `docker-compose.yml` for the BubbleUPnP Server.
+
+### Role Examples
+
+- `roles/bubbleupnp-server-on-docker.rb`
+
+```ruby
+name 'bubbleupnp-server-on-docker'
+description 'BubbleUPnP Server on Docker'
+
+run_list(
+  # see https://osdn.net/projects/metasearch/scm/git/grid-chef-repo/blobs/master/roles/docker-new-repo.rb
+  'role[docker]',
+  'recipe[bubbleupnp-server::docker-compose]',
+)
+
+#env_run_lists
+
+#default_attributes
+
+override_attributes(
+  'bubbleupnp-server' => {
+    'docker-compose' => {
+      'config' => {
+        'services' => {
+          'bubbleupnp-server' => {
+            'restart' => 'no',
+          },
+        },
+      },
+    },
+  },
+)
+```
+
+## License and Authors
+
+- Author:: whitestar at osdn.jp
+
+```text
+Copyright 2019, whitestar
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+```
diff --git a/cookbooks/bubbleupnp-server/Rakefile b/cookbooks/bubbleupnp-server/Rakefile
new file mode 100644 (file)
index 0000000..1ba86c6
--- /dev/null
@@ -0,0 +1,95 @@
+require 'rspec/core/rake_task'
+require 'rubocop/rake_task'
+require 'foodcritic'
+require 'stove/rake_task'
+
+tpl_cookbook = '00cookbook'
+cookbook_name = File.basename(Dir.pwd)
+
+desc 'Initialize project'
+task :init do
+  next if cookbook_name == tpl_cookbook
+
+  [
+    '.foodcritic',
+    '.rubocop.yml',
+    'Berksfile',
+    'chefignore',
+    'concourse.yml',
+    'fly-vars.yml',
+    'fly-vars.local.yml',
+    'Gemfile',
+    'Gemfile.lock',
+    'version',
+  ].each {|conf|
+    sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf)
+  }
+
+  ruby [
+    %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'),
+    '-i fly-vars.local.yml',
+  ].join(' ')
+end
+
+desc 'Update project'
+task :update do
+  next if cookbook_name == tpl_cookbook
+
+  [
+    'Rakefile',
+    'chefignore',
+    'concourse.yml',
+    'fly-vars.yml',
+    'Gemfile',
+    'Gemfile.lock',
+  ].each {|conf|
+    sh "cp ../#{tpl_cookbook}/#{conf} ./"
+  }
+end
+
+desc 'fly set-pipeline'
+task :'set-pipeline' do
+  sh [
+    "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml",
+    '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml',
+  ].join(' ')
+end
+desc 'rake set-pipeline alias'
+task sp: 'set-pipeline'
+
+namespace :style do
+  desc 'Run Ruby style checks'
+  RuboCop::RakeTask.new(:ruby) do |t|
+    t.options = [
+      '--auto-gen-config',  # creates .rubocop_todo.yml
+    ]
+  end
+
+  desc 'Run Chef style checks'
+  FoodCritic::Rake::LintTask.new(:chef) do |t|
+    t.options = {
+      fail_tags: ['any'],
+    }
+  end
+end
+
+desc 'Run all style checks'
+task style: ['style:chef', 'style:ruby']
+
+desc 'Run ChefSpec examples'
+RSpec::Core::RakeTask.new(:spec)
+
+desc 'Publish cookbook'
+Stove::RakeTask.new(:publish) do |t|
+  t.stove_opts = [
+    # `--username` and `--key` are set in ~/.stove typically.
+    #'--username', 'somebody',
+    #'--key', '~/chef/chef.io.example.com/somebody.pem',
+    #'--endpoint', 'https://supermarket.io.example.com/api/v1',  # default: supermarket.chef.io
+    #'--no-ssl-verify',
+    '--no-git',
+    '--log-level', 'info',
+  ]
+end
+
+task default: ['style', 'spec']
diff --git a/cookbooks/bubbleupnp-server/attributes/default.rb b/cookbooks/bubbleupnp-server/attributes/default.rb
new file mode 100644 (file)
index 0000000..54aeaa2
--- /dev/null
@@ -0,0 +1,87 @@
+#
+# Cookbook Name:: bubbleupnp-server
+# Attributes:: default
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+ver = '0.9-5'
+image_name = nil
+base_image = nil
+site_url = nil
+pkg = nil
+
+case node['kernel']['machine']
+when 'x86_64'
+  image_name = 'bubbleupnpserver'
+  base_image = 'openjdk:8-jre-slim'
+  site_url = 'https://launchpad.net/~bubbleguuum/+archive/bubbleupnpserver/+files'
+  pkg = "bubbleupnpserver_#{ver}_all.deb"
+when 'armv7l'
+  image_name = 'bubbleupnpserver-armhf'
+  base_image = 'arm32v7/openjdk:8-jre'
+  site_url = 'https://launchpad.net/~bubbleguuum/+archive/bubbleupnpserver/+files'
+  pkg = "bubbleupnpserver_#{ver}_all.deb"
+end
+
+default['bubbleupnp-server']['Dockerfile'] = {
+  'FROM' => base_image,
+}
+
+default['bubbleupnp-server']['docker-compose']['autopilot'] = {
+  'enabled' => false,
+  'log_dir' => '/var/log',
+  'wait_time' => '180s',
+  'docker-compose_opts' => '--no-ansi',
+  #'docker-compose_opts' => '',  # for the old docker-compose
+}
+default['bubbleupnp-server']['docker-compose']['app_dir'] = "#{node['docker-grid']['compose']['app_dir']}/bubbleupnp-server"
+default['bubbleupnp-server']['docker-compose']['data_dir'] = "#{node['bubbleupnp-server']['docker-compose']['app_dir']}/data"
+
+default['bubbleupnp-server']['docker-compose']['dot_env'] = {
+  'NAME' => image_name,
+  'VER' => ver,
+  'site_url' => site_url,
+  'pkg' => pkg,
+  'REGISTRY' => 'whitestar',
+}
+
+force_override['bubbleupnp-server']['docker-compose']['config_format_version'] = '2'
+version_2_config = {
+  # Version 2 docker-compose format
+  'version' => '2',
+  'services' => {
+    'bubbleupnp-server' => {
+      'build' => {
+        'context' => './',
+        'args' => {
+          'site_url' => '${site_url}',
+          'pkg' => '${pkg}',
+        },
+      },
+      'image' => '${REGISTRY}/${NAME}:${VER}',
+      'restart' => 'always',
+      'network_mode' => 'host',
+      'volumes' => [
+        # These volumes will be set by the bubbleupnp-server::docker-compose recipe automatically.
+        #"#{node['bubbleupnp-server']['docker-compose']['data_dir']}/configuration.xml:/usr/share/bubbleupnpserver/configuration.xml:rw",
+        #"#{node['bubbleupnp-server']['docker-compose']['data_dir']}/cache:/usr/share/bubbleupnpserver/cache:rw",
+        #"#{node['bubbleupnp-server']['docker-compose']['data_dir']}/Playlists:/usr/share/bubbleupnpserver/Playlists:rw",
+      ],
+    },
+  },
+}
+
+default['bubbleupnp-server']['docker-compose']['config'] = version_2_config
diff --git a/cookbooks/bubbleupnp-server/chefignore b/cookbooks/bubbleupnp-server/chefignore
new file mode 100644 (file)
index 0000000..10e314a
--- /dev/null
@@ -0,0 +1,20 @@
+# Put files/directories that should be ignored in this file.
+# Lines that start with '# ' are comments.
+
+Berksfile.lock
+
+# concourse
+concourse.yml
+fly-vars.yml
+fly-vars.local.yml
+
+# emacs
+*~
+
+.rubocop_todo.yml
+
+# vim
+*.sw[a-z]
+
+# subversion
+*/.svn/*
diff --git a/cookbooks/bubbleupnp-server/concourse.yml b/cookbooks/bubbleupnp-server/concourse.yml
new file mode 100644 (file)
index 0000000..d373185
--- /dev/null
@@ -0,0 +1,101 @@
+---
+resources:
+- name: src-git
+  type: git
+  source:
+    uri: ((git-id-osdn))@git.osdn.net:/gitroot/metasearch/grid-chef-repo.git
+    branch: master
+    paths:
+    - cookbooks/((cookbook-name))
+    private_key: ((git-private-key))
+    git_user: ((git-user-osdn))
+  #check_every: 1h  # default: 1m
+- name: chefdk-cache
+  type: docker-image
+  source:
+    repository: chef/chefdk
+    tag: ((chefdk-version))
+    # ((param)) style: fly >= 3.2.0
+    registry_mirror: https://((registry-mirror-domain))  # e.g. https://registry.docker.example.com:5000
+    ca_certs:
+    - domain: ((registry-mirror-domain))  # e.g. registry.docker.example.com:5000
+      cert: ((docker-reg-ca-cert))
+  check_every: 6h  # default: 1m
+
+jobs:
+- name: test-cookbook
+  plan:
+  - aggregate:
+    - get: src-git
+      params:
+        depth: 5
+      trigger: true
+    - get: chefdk-cache
+  - task: ci-build
+    image: chefdk-cache
+    params:
+      http_proxy: ((http-proxy))  # e.g. http://proxy.example.com:3128
+      #HTTP_PROXY: ((http-proxy))
+    config:
+      platform: linux
+      #image_resource:
+      #  type: docker-image
+      #  source:
+      #    repository: chef/chefdk
+      #    tag: ((chefdk-version))
+          # NG, setting disable
+          #registry_mirror: https://((registry-mirror-domain))
+          #ca_certs:
+          #- domain: ((registry-mirror-domain))
+          #  cert: ((docker-reg-ca-cert))
+      inputs:
+      - name: src-git
+      run:
+        #dir: ./src-git/cookbooks/((cookbook-name))
+        #path: rake
+        path: /bin/bash
+        args:
+        - -c
+        - |
+          cd ./src-git/cookbooks/((cookbook-name))
+          bundle config --local silence_root_warning 1
+          bundle install
+          rake
+- name: publish-cookbook
+  plan:
+  - aggregate:
+    - get: src-git
+      params:
+        depth: 5
+      trigger: false
+      passed: [test-cookbook]
+    - get: chefdk-cache
+      passed: [test-cookbook]
+  - task: publish
+    image: chefdk-cache
+    params:
+      http_proxy: ((http-proxy))
+      chef_username: ((chef-username))
+      chef_client_key: ((chef-client-key))
+    config:
+      platform: linux
+      inputs:
+      - name: src-git
+      run:
+        path: /bin/bash
+        args:
+        - -c
+        - |
+          echo '{"username":"((chef-username))","key":"/root/chef-client-key.pem"}' > /root/.stove
+          echo "$chef_client_key"  > /root/chef-client-key.pem
+          cd ./src-git/cookbooks/((cookbook-name))
+          bundle config --local silence_root_warning 1
+          bundle install
+          rake publish
+  - put: src-git
+    params:
+      repository: src-git
+      tag_prefix: ((cookbook-name))-
+      tag: src-git/cookbooks/((cookbook-name))/version
+      only_tag: true
+      annotate: src-git/cookbooks/((cookbook-name))/version
diff --git a/cookbooks/bubbleupnp-server/fly-vars.local.yml b/cookbooks/bubbleupnp-server/fly-vars.local.yml
new file mode 100644 (file)
index 0000000..6af9d54
--- /dev/null
@@ -0,0 +1,2 @@
+---
+cookbook-name: bubbleupnp-server
diff --git a/cookbooks/bubbleupnp-server/fly-vars.yml b/cookbooks/bubbleupnp-server/fly-vars.yml
new file mode 100644 (file)
index 0000000..76f2fcd
--- /dev/null
@@ -0,0 +1,2 @@
+---
+chefdk-version: 1.6.11
diff --git a/cookbooks/bubbleupnp-server/metadata.rb b/cookbooks/bubbleupnp-server/metadata.rb
new file mode 100644 (file)
index 0000000..0bc293e
--- /dev/null
@@ -0,0 +1,19 @@
+name             'bubbleupnp-server'
+maintainer       'whitestar'
+maintainer_email ''
+license          'Apache 2.0'
+description      'Installs/Configures bubbleupnp-server'
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version          IO.read(File.join(File.dirname(__FILE__), 'version')).chomp
+source_url       'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git'
+issues_url       'https://osdn.jp/projects/metasearch/ticket'
+
+chef_version     '>= 12'
+%w( centos redhat ).each do |os|
+  supports os, '>= 7.0'
+end
+supports 'debian', '>= 9.0'
+supports 'ubuntu', '>= 16.04'
+
+depends 'docker-grid', '>= 0.4.0'
+depends 'platform_utils', '>= 0.4.4'
diff --git a/cookbooks/bubbleupnp-server/recipes/default.rb b/cookbooks/bubbleupnp-server/recipes/default.rb
new file mode 100644 (file)
index 0000000..413ba5e
--- /dev/null
@@ -0,0 +1,18 @@
+#
+# Cookbook Name:: bubbleupnp-server
+# Recipe:: default
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
diff --git a/cookbooks/bubbleupnp-server/recipes/docker-compose.rb b/cookbooks/bubbleupnp-server/recipes/docker-compose.rb
new file mode 100644 (file)
index 0000000..3cad48d
--- /dev/null
@@ -0,0 +1,104 @@
+#
+# Cookbook Name:: bubbleupnp-server
+# Recipe:: docker-compose
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+doc_url = 'https://github.com/wdstar/docker-bubbleupnpserver'
+
+include_recipe 'platform_utils::kernel_user_namespace'
+include_recipe 'docker-grid::compose'
+
+app_dir = node['bubbleupnp-server']['docker-compose']['app_dir']
+data_dir = node['bubbleupnp-server']['docker-compose']['data_dir']
+
+[
+  app_dir,
+  "#{data_dir}/cache",
+  "#{data_dir}/Playlists",
+].each {|dir|
+  resources(directory: dir) rescue directory dir do
+    owner 'root'
+    group 'root'
+    mode '0755'
+    recursive true
+  end
+}
+
+config_srvs = node['bubbleupnp-server']['docker-compose']['config']['services']
+override_config_srvs = node.override['bubbleupnp-server']['docker-compose']['config']['services']
+force_override_config_srvs = node.force_override['bubbleupnp-server']['docker-compose']['config']['services']
+envs = {}
+vols = config_srvs['bubbleupnp-server']['volumes'].to_a
+
+vols.push("#{data_dir}/configuration.xml:/usr/share/bubbleupnpserver/configuration.xml:rw")
+vols.push("#{data_dir}/cache:/usr/share/bubbleupnpserver/cache:rw")
+vols.push("#{data_dir}/Playlists:/usr/share/bubbleupnpserver/Playlists:rw")
+
+# merge environment hash
+force_override_config_srvs['bubbleupnp-server']['environment'] = envs unless envs.empty?
+# reset volumes array.
+override_config_srvs['bubbleupnp-server']['volumes'] = vols unless vols.empty?
+
+file "#{data_dir}/configuration.xml" do
+  owner 'root'
+  group 'root'
+  mode '0644'
+  action :touch
+end
+
+[
+  '.env',
+  'docker-compose.yml',
+].each {|conf_file|
+  template "#{app_dir}/#{conf_file}" do
+    source "opt/docker-compose/app/bubbleupnp-server/#{conf_file}"
+    owner 'root'
+    group 'root'
+    mode '0644'
+  end
+}
+
+dockerfile_tpl = 'Dockerfile'
+dockerfile_tpl = 'Dockerfile.armhf' if node['kernel']['machine'] == 'armv7l'
+template "#{app_dir}/Dockerfile" do
+  source "opt/docker-compose/app/bubbleupnp-server/#{dockerfile_tpl}"
+  owner 'root'
+  group 'root'
+  mode '0644'
+end
+
+# autopilot
+srv = 'bubbleupnp-server'
+template "/etc/cron.d/#{srv}-local" do
+  source  "etc/cron.d/#{srv}-local"
+  owner 'root'
+  group 'root'
+  mode '0644'
+  action :delete unless node['bubbleupnp-server']['docker-compose']['autopilot']['enabled']
+end
+
+log 'bubbleupnp-server docker-compose post install message' do
+  message <<-"EOM"
+Note: You must execute the following command manually.
+  See #{doc_url}
+  * Start:
+    $ cd #{app_dir}
+    $ docker-compose up -d
+  * Stop
+    $ docker-compose down
+EOM
+end
diff --git a/cookbooks/bubbleupnp-server/spec/recipes/default_spec.rb b/cookbooks/bubbleupnp-server/spec/recipes/default_spec.rb
new file mode 100644 (file)
index 0000000..4fd19d3
--- /dev/null
@@ -0,0 +1,9 @@
+require_relative '../spec_helper'
+
+describe 'bubbleupnp-server::default' do
+  let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
+
+  #it 'does something' do
+  #  expect(chef_run).to do_something('...')
+  #end
+end
diff --git a/cookbooks/bubbleupnp-server/spec/spec_helper.rb b/cookbooks/bubbleupnp-server/spec/spec_helper.rb
new file mode 100644 (file)
index 0000000..1995e2b
--- /dev/null
@@ -0,0 +1,25 @@
+# Added by ChefSpec
+require 'chefspec'
+
+# Uncomment to use ChefSpec's Berkshelf extension
+# require 'chefspec/berkshelf'
+
+RSpec.configure do |config|
+  # Specify the path for Chef Solo to find cookbooks
+  # config.cookbook_path = '/var/cookbooks'
+
+  # Specify the path for Chef Solo to find roles
+  # config.role_path = '/var/roles'
+
+  # Specify the Chef log_level (default: :warn)
+  # config.log_level = :debug
+
+  # Specify the path to a local JSON file with Ohai data
+  # config.path = 'ohai.json'
+
+  # Specify the operating platform to mock Ohai data from
+  # config.platform = 'ubuntu'
+
+  # Specify the operating version to mock Ohai data from
+  # config.version = '12.04'
+end
diff --git a/cookbooks/bubbleupnp-server/templates/default/etc/cron.d/bubbleupnp-server-local b/cookbooks/bubbleupnp-server/templates/default/etc/cron.d/bubbleupnp-server-local
new file mode 100644 (file)
index 0000000..1c862f1
--- /dev/null
@@ -0,0 +1,16 @@
+<%
+name = 'bubbleupnp-server'
+
+conf = node['bubbleupnp-server']['docker-compose']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+wait_time = conf['wait_time']
+
+opts = conf['docker-compose_opts']
+-%>
+PATH=/usr/bin:/bin:/usr/local/bin
+DATE_F='+%Y-%m-%d %H:%M:%S %z'
+LOG=<%= log %>
+APP_HOME=<%= node['bubbleupnp-server']['docker-compose']['app_dir'] %>
+OPTS='<%= opts %>'
+
+@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && cd $APP_HOME && docker-compose $OPTS down >> $LOG 2>&1 && docker-compose $OPTS up -d >> $LOG 2>&1 && docker-compose ps >> $LOG 2>&1
diff --git a/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/.env b/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/.env
new file mode 100644 (file)
index 0000000..f221d1c
--- /dev/null
@@ -0,0 +1,9 @@
+<%
+dot_env = node['bubbleupnp-server']['docker-compose']['dot_env']
+-%>
+# for docker-compose.yml
+NAME=<%= dot_env['NAME'] %>
+VER=<%= dot_env['VER'] %>
+site_url=<%= dot_env['site_url'] %>
+pkg=<%= dot_env['pkg'] %>
+REGISTRY=<%= dot_env['REGISTRY'] %>
diff --git a/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/Dockerfile b/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/Dockerfile
new file mode 100644 (file)
index 0000000..7370795
--- /dev/null
@@ -0,0 +1,16 @@
+FROM <%= node['bubbleupnp-server']['Dockerfile']['FROM'] %>
+
+ARG site_url=https://launchpad.net/~bubbleguuum/+archive/bubbleupnpserver/+files
+ARG pkg=bubbleupnpserver_0.9-5_all.deb
+
+RUN apt-get update -y && \
+    apt-get install -y --no-install-recommends wget ffmpeg && \
+    wget ${site_url}/${pkg} && \
+    dpkg -i $pkg && \
+    apt-get autoremove -y && \
+    apt-get clean && \
+    rm -rf /var/lib/apt/lists/*
+
+EXPOSE 58050/tcp 58051/tcp 1900/udp
+
+ENTRYPOINT [ "/usr/share/bubbleupnpserver/launch.sh" ]
diff --git a/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/Dockerfile.armhf b/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/Dockerfile.armhf
new file mode 100644 (file)
index 0000000..826141f
--- /dev/null
@@ -0,0 +1,21 @@
+FROM <%= node['bubbleupnp-server']['Dockerfile']['FROM'] %>
+# Note: Getting different architectures in slim images
+#   see https://github.com/docker-library/openjdk/issues/278
+#FROM arm32v7/openjdk:8-jre-slim
+
+ARG site_url=https://launchpad.net/~bubbleguuum/+archive/bubbleupnpserver/+files
+ARG pkg=bubbleupnpserver_0.9-5_all.deb
+
+RUN apt-get update -y && \
+    apt-get install -y --no-install-recommends wget && \
+    wget -O - http://ipkg.nslu2-linux.org/optware-ng/bootstrap/buildroot-armeabihf-bootstrap.sh | sh && \
+    /opt/bin/ipkg install ffmpeg && \
+    wget ${site_url}/${pkg} && \
+    dpkg -i $pkg && \
+    apt-get autoremove -y && \
+    apt-get clean && \
+    rm -rf /var/lib/apt/lists/*
+
+EXPOSE 58050/tcp 58051/tcp 1900/udp
+
+ENTRYPOINT [ "/usr/share/bubbleupnpserver/launch.sh" ]
diff --git a/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/docker-compose.yml b/cookbooks/bubbleupnp-server/templates/default/opt/docker-compose/app/bubbleupnp-server/docker-compose.yml
new file mode 100644 (file)
index 0000000..0971894
--- /dev/null
@@ -0,0 +1,5 @@
+<%
+require 'yaml'
+yaml_str = node['bubbleupnp-server']['docker-compose']['config'].to_hash.to_yaml
+-%>
+<%= yaml_str %>
diff --git a/cookbooks/bubbleupnp-server/version b/cookbooks/bubbleupnp-server/version
new file mode 100644 (file)
index 0000000..6e8bf73
--- /dev/null
@@ -0,0 +1 @@
+0.1.0
diff --git a/roles/bubbleupnp-server-on-docker.rb b/roles/bubbleupnp-server-on-docker.rb
new file mode 100644 (file)
index 0000000..233ad0e
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name 'bubbleupnp-server-on-docker'
+description 'bubbleupnp Server on Docker'
+
+run_list(
+  'role[docker]',
+  'recipe[bubbleupnp-server::docker-compose]',
+)
+
+#env_run_lists
+
+default_attributes(
+)
+
+override_attributes(
+)