This repository has been archived on 2025-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
esh/esh_archivebox/recipes/compose.rb

105 lines
2.5 KiB
Ruby
Raw Permalink Normal View History

2025-02-15 00:56:26 +09:00
#
# Cookbook:: esh_photoprism
# 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/archivebox' do
owner 'root'
group 'root'
mode '0700'
action :create
end
template '/opt/archivebox/docker-compose.yml' do
owner 'root'
group 'root'
mode '0400'
variables volume_data: "/var/lib/#{node['hostname']}-data"
action :create
end
execute 'docker compose pull' do
command 'docker compose pull'
cwd '/opt/archivebox'
live_stream true
action :run
end
apt_package 'expect'
file '/tmp/archivebox-init.expect' do
content <<~EOT
#!/usr/bin/expect -f
set timeout -1
cd /opt/archivebox
spawn /usr/bin/docker compose run archivebox init --setup
expect "Username"
send -- "#{node['esh']['archivebox']['username']}\\r"
expect "Email address:"
send -- "#{node['esh']['archivebox']['email']}\\r"
expect "Password:"
send -- "#{node['esh']['archivebox']['password']}\\r"
expect "Password (again):"
send -- "#{node['esh']['archivebox']['password']}\\r"
expect eof
EOT
owner 'root'
group 'root'
mode '0400'
not_if { ::File.exist?("/var/lib/#{node['hostname']}-data/index.sqlite3")}
notifies :run, 'execute[init archivebox configuration]', :immediately
action :create
end
execute 'init archivebox configuration' do
command 'expect -f /tmp/archivebox-init.expect'
live_stream true
action :nothing
end
systemd_unit 'archivebox.service' do
content <<~EOU
[Unit]
Description=archivebox via docker compose
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/opt/archivebox
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/archivebox/docker-compose.yml]', :delayed
end
service 'archivebox' do
action :nothing
subscribes :start, 'execute[docker compose pull]', :delayed
end