diff --git a/data/common/common.yaml b/data/common/common.yaml --- a/data/common/common.yaml +++ b/data/common/common.yaml @@ -2523,6 +2523,11 @@ - swh.loader.mercurial.tasks.LoadMercurial - swh.loader.mercurial.tasks.LoadArchiveMercurial +swh::deploy::worker::opam::root_directory: /tmp/opam/ +swh::deploy::worker::opam::instances: + opam: https://opam.ocaml.org + ocamlbench-repo: https://github.com/OCamlPro/ocamlbench-repo.git + swh::deploy::worker::loader_opam::config_file: "%{hiera('swh::conf_directory')}/loader_opam.yml" swh::deploy::worker::loader_opam::concurrency: 1 swh::deploy::worker::loader_opam::private_tmp: true diff --git a/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp b/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp --- a/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp +++ b/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp @@ -17,4 +17,55 @@ Package[$packages], ], } + + $opam_instances = lookup('swh::deploy::worker::opam::instances') + + $opam_root = lookup('swh::deploy::worker::opam::root_directory') + file {$opam_root: + ensure => 'directory', + owner => $user, + group => $group, + recurse => true, + mode => '0644', + } + + $binary_cmd = "/usr/bin/opam" + + each ( $opam_instances ) | $instance, $instance_url | { + $opam_manage_shared_state = "opam-manage-shared-state" + $opam_manage_service_name = "${$opam_manage_shared_state}-${instance}" + $opam_manage_shared_state_timer_name = "${opam_manage_service_name}.timer" + + # update the instance repository if present + $update_command = "${binary_cmd} repo --all --root ${opam_root} | grep ${instance_url} && ${binary_cmd} update --root ${opam_root}" + # common suffix command for the opam commands + $command_suffix = "--root ${opam_root} ${instance} ${instance_url}" + if $instance == "opam" { + # Install the default rootdir for the main opam instance + $install_command = "${binary_cmd} init --reinit --bare --no-setup ${command_suffix}" + } else { + # Other instances will just be added to the main opam root directory + $install_command = "${binary_cmd} repository add ${command_suffix}" + } + + # Either update the instance if present or install/add that new instance + $opam_command = "( ${update_command} ) || ${install_command}" + + # Template uses variables + # - $user + # - $group + # - $opam_root + # - $opam_manage_service_name + # - $command + ::systemd::timer { $opam_manage_shared_state_timer_name: + timer_content => template("profile/swh/deploy/loader_opam/${opam_manage_shared_state}.timer.erb"), + service_content => template("profile/swh/deploy/loader_opam/${opam_manage_shared_state}.service.erb"), + enable => true, + require => [ + Package[$packages], + File[$opam_root], + ], + } + } + } diff --git a/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.service.erb b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.service.erb new file mode 100644 --- /dev/null +++ b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.service.erb @@ -0,0 +1,17 @@ +# Opam manage shared state unit file +# Managed by puppet class profile::swh::deploy::worker::loader_opam +# Changes will be overwritten + +[Unit] +Description=Software Heritage Manage OPAM shared state (<%= @instance %>) +Requires=network.target +After=network.target + +[Service] +User=<%= @user %> +Group=<%= @group %> +Type=simple +ExecStart=<%= @opam_command %> + +[Install] +WantedBy=multi-user.target diff --git a/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.timer.erb b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.timer.erb new file mode 100644 --- /dev/null +++ b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.timer.erb @@ -0,0 +1,11 @@ +[Install] +WantedBy=timers.target + +[Timer] +OnCalendar=daily +AccuracySec=4h +Persistent=true +Unit=<%= @opam_manage_service_name %>.service + +[Unit] +Description=Software Heritage Manage OPAM shared state (<%= @instance %>) timer