OSDN Git Service

add backup cron configuration.
[metasearch/grid-chef-repo.git] / cookbooks / bubbleupnp-server / recipes / docker-compose.rb
1 #
2 # Cookbook Name:: bubbleupnp-server
3 # Recipe:: docker-compose
4 #
5 # Copyright 2019-2022, whitestar
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 doc_url = 'https://github.com/wdstar/docker-bubbleupnpserver'
21
22 include_recipe 'platform_utils::kernel_user_namespace'
23 include_recipe 'docker-grid::compose'
24
25 app_dir = node['bubbleupnp-server']['docker-compose']['app_dir']
26 data_dir = node['bubbleupnp-server']['docker-compose']['data_dir']
27 dot_env = node['bubbleupnp-server']['docker-compose']['dot_env']
28
29 file_owner = 'root'
30 file_group = 'root'
31 workdir = '/usr/share/bubbleupnpserver'
32 if dot_env['VER'] > '0.9-5' || dot_env['VER'] == 'latest'
33   file_owner = 'bubbleupnpserver'
34   file_group = 'users'
35   workdir = '/opt/bubbleupnpserver'
36 end
37
38 [
39   app_dir,
40   "#{data_dir}/cache",
41   "#{data_dir}/Playlists",
42 ].each {|dir|
43   resources(directory: dir) rescue directory dir do
44     owner 'root'
45     group 'root'
46     mode '0755'
47     recursive true
48   end
49 }
50
51 config_srvs = node['bubbleupnp-server']['docker-compose']['config']['services']
52 override_config_srvs = node.override['bubbleupnp-server']['docker-compose']['config']['services']
53 force_override_config_srvs = node.force_override['bubbleupnp-server']['docker-compose']['config']['services']
54 envs = {}
55 vols = config_srvs['bubbleupnp-server']['volumes'].to_a
56
57 # Note: the official image already contains the following volume definitions.
58 if dot_env['REGISTRY'] != 'bubblesoftapps'
59   # bind mounting
60   vols.push("#{data_dir}/configuration.xml:#{workdir}/configuration.xml:rw")
61   vols.push("#{data_dir}/cache:#{workdir}/cache:rw")
62   vols.push("#{data_dir}/Playlists:#{workdir}/Playlists:rw")
63 end
64
65 # merge environment hash
66 force_override_config_srvs['bubbleupnp-server']['environment'] = envs unless envs.empty?
67 # reset volumes array.
68 override_config_srvs['bubbleupnp-server']['volumes'] = vols unless vols.empty?
69
70 file "#{data_dir}/configuration.xml" do
71   owner 'root'
72   group 'root'
73   mode '0644'
74   action :touch
75 end
76
77 [
78   '.env',
79   'docker-compose.yml',
80 ].each {|conf_file|
81   template "#{app_dir}/#{conf_file}" do
82     source "opt/docker-compose/app/bubbleupnp-server/#{conf_file}"
83     owner 'root'
84     group 'root'
85     mode '0644'
86   end
87 }
88
89 [
90   'backup.sh',
91   'restore.sh',
92 ].each {|conf_file|
93   template "#{app_dir}/#{conf_file}" do
94     source "opt/docker-compose/app/bubbleupnp-server/#{conf_file}"
95     owner 'root'
96     group 'root'
97     mode '0755'
98     variables(
99       file_owner: file_owner,
100       file_group: file_group,
101       workdir: workdir
102     )
103   end
104 }
105
106 dockerfile_tpl = 'Dockerfile'
107 dockerfile_tpl = 'Dockerfile.armhf' if node['kernel']['machine'] == 'armv7l'
108 template "#{app_dir}/Dockerfile" do
109   source "opt/docker-compose/app/bubbleupnp-server/#{dockerfile_tpl}"
110   owner 'root'
111   group 'root'
112   mode '0644'
113   variables(
114     workdir: workdir
115   )
116 end
117
118 # autopilot
119 srv = 'bubbleupnp-server'
120 template "/etc/cron.d/#{srv}-local" do
121   source  "etc/cron.d/#{srv}-local"
122   owner 'root'
123   group 'root'
124   mode '0644'
125   action :delete unless node['bubbleupnp-server']['docker-compose']['autopilot']['enabled']
126 end
127
128 log 'bubbleupnp-server docker-compose post install message' do
129   message <<-"EOM"
130 Note: You must execute the following command manually.
131   See #{doc_url}
132   * Start:
133     $ cd #{app_dir}
134     $ docker-compose up -d
135   * Stop
136     $ docker-compose down
137 EOM
138 end