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_photoprism/recipes/compose.rb

70 lines
1.9 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/photoprism' do
owner 'photoprism'
group 'photoprism'
mode '0755'
action :create
end
template '/opt/photoprism/docker-compose.yml' do
owner 'photoprism'
group 'photoprism'
mode '0400'
variables environment: node['esh']['photoprism']['environment'],
volumes: node['esh']['photoprism']['volumes'],
mariadb_volumes: node['esh']['photoprism']['mariadb']['volumes'],
mariadb_password: node['esh']['photoprism']['mariadb']['password'],
mariadb_root_password: node['esh']['photoprism']['mariadb']['root_password']
action :create
end
execute 'docker compose pull' do
command 'docker compose pull --quiet'
cwd '/opt/photoprism'
live_stream true
action :run
end
systemd_unit 'photoprism.service' do
content <<~EOU
[Unit]
Description=photoprism via docker compose
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/opt/photoprism
ExecStart=/usr/bin/docker compose up --detach
ExecStop=/usr/bin/docker compose down
[Install]
WantedBy=multi-user.target
EOU
action [:create, :enable]
subscribes :restart, 'template[/opt/photoprism/docker-compose.yml]', :delayed
end
service 'photoprism' do
action :nothing
subscribes :start, 'execute[docker compose pull]', :delayed
end