129 lines
3.5 KiB
Ruby
129 lines
3.5 KiB
Ruby
#
|
|
# Cookbook:: esh_piped
|
|
# Recipe:: compose
|
|
#
|
|
# Copyright:: 2022, https://easyself.host
|
|
#
|
|
# 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.
|
|
|
|
directory '/opt/piped' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0755'
|
|
action :create
|
|
end
|
|
|
|
directory '/opt/piped/config' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0755'
|
|
action :create
|
|
end
|
|
|
|
template '/opt/piped/config/config.properties' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0400'
|
|
variables proxy_hostname: node['esh']['piped']['config']['proxy_hostname'],
|
|
captcha_api_key: node['esh']['piped']['config']['captcha_api_key'],
|
|
backend_hostname: node['esh']['piped']['config']['backend_hostname'],
|
|
frontend_hostname: node['esh']['piped']['config']['frontend_hostname'],
|
|
postgresql_password: node['esh']['piped']['config']['postgresql_password']
|
|
action :create
|
|
end
|
|
|
|
cookbook_file '/opt/piped/config/nginx.conf' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0444'
|
|
action :create
|
|
end
|
|
|
|
template '/opt/piped/config/pipedapi.conf' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0444'
|
|
variables backend_hostname: node['esh']['piped']['config']['backend_hostname']
|
|
action :create
|
|
end
|
|
|
|
template '/opt/piped/config/pipedproxy.conf' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0444'
|
|
variables proxy_hostname: node['esh']['piped']['config']['proxy_hostname']
|
|
action :create
|
|
end
|
|
|
|
template '/opt/piped/config/pipedfrontend.conf' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0444'
|
|
variables frontend_hostname: node['esh']['piped']['config']['frontend_hostname']
|
|
action :create
|
|
end
|
|
|
|
cookbook_file '/opt/piped/config/ytproxy.conf' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0444'
|
|
action :create
|
|
end
|
|
|
|
template '/opt/piped/docker-compose.yml' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0400'
|
|
variables backend_hostname: node['esh']['piped']['config']['backend_hostname'],
|
|
postgresql_password: node['esh']['piped']['config']['postgresql_password']
|
|
action :create
|
|
end
|
|
|
|
execute 'docker compose pull' do
|
|
command 'docker compose pull --quiet'
|
|
cwd '/opt/piped'
|
|
live_stream true
|
|
action :run
|
|
end
|
|
|
|
systemd_unit 'piped.service' do
|
|
content <<~EOU
|
|
[Unit]
|
|
Description=piped via docker compose
|
|
Requires=docker.service
|
|
After=docker.service
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
RemainAfterExit=true
|
|
WorkingDirectory=/opt/piped
|
|
ExecStart=/usr/bin/docker compose up -d
|
|
ExecStop=/usr/bin/docker compose down
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOU
|
|
action [:create, :enable]
|
|
subscribes :restart, 'template[/opt/piped/config/config.properties]', :delayed
|
|
subscribes :restart, 'file[/opt/piped/config/nginx.conf]', :delayed
|
|
subscribes :restart, 'template[/opt/piped/config/pipedapi.conf]', :delayed
|
|
subscribes :restart, 'template[/opt/piped/config/pipedproxy.conf]', :delayed
|
|
subscribes :restart, 'template[/opt/piped/config/pipedfrontend.conf]', :delayed
|
|
subscribes :restart, 'file[/opt/piped/config/ytproxy.conf]', :delayed
|
|
subscribes :restart, 'template[/opt/piped/docker-compose.yml]', :delayed
|
|
end
|
|
|
|
service 'piped' do
|
|
action :nothing
|
|
subscribes :start, 'execute[docker compose pull]', :delayed
|
|
end
|