podmanrunner/manifests/runner.pp

110 lines
3.2 KiB
ObjectPascal
Raw Normal View History

# Class for forgeo action runner.
class podmanrunner::runner (
Integer $replicas = 2,
)
{
2024-02-06 10:03:33 +00:00
$userpostfix='runner'
2024-01-25 20:23:17 +00:00
$runnerdata = lookup("runners",undef,undef,undef)
package { 'podman':
ensure => installed,
provider => apt,
}
package { 'systemd-container':
ensure => installed,
provider => apt,
}
package { 'python3-dotenv':
ensure => installed,
provider => apt,
}
file { "/usr/local/bin/podman-compose":
ensure => file,
mode => '0555',
source => 'puppet:///modules/podmanrunner/podman-compose-1.0.6',
owner => "root",
group => "root",
}
2024-02-06 10:03:33 +00:00
if $aaa {
2024-02-06 10:03:33 +00:00
$runnerdata.each |$user| {
2024-02-06 10:03:33 +00:00
user { "${user}${}":
ensure => present,
2024-02-06 10:03:33 +00:00
home => "/opt/${user}${userpostfix}",
shell => '/usr/sbin/nologin',
managehome => true,
}
2024-02-06 10:03:33 +00:00
file { "/opt/${user}${userpostfix}/docker-compose.yaml":
ensure => file,
content => template('podmanrunner/docker-compose.yaml.erb'),
2024-02-06 10:03:33 +00:00
owner => "${user}${userpostfix}",
group => "${user}${userpostfix}",
2024-01-23 21:03:05 +00:00
mode => '0400',
}
2024-01-23 21:03:05 +00:00
2024-02-06 10:03:33 +00:00
file { "/opt/${user}${userpostfix}/runnerimage":
2024-01-23 21:03:05 +00:00
ensure => directory,
mode => '0700',
2024-02-06 10:03:33 +00:00
owner => "${user}${userpostfix}",
group => "${user}${userpostfix}",
2024-01-23 21:03:05 +00:00
}
2024-02-06 10:03:33 +00:00
file { "/opt/${user}${userpostfix}/runnerimage/Containerfile":
2024-01-23 21:03:05 +00:00
ensure => file,
content => template('podmanrunner/runnerimage-Containerfile.erb'),
2024-02-06 10:03:33 +00:00
owner => "${user}${userpostfix}",
group => "${user}${userpostfix}",
2024-01-23 21:03:05 +00:00
mode => '0400',
}
2024-02-06 10:03:33 +00:00
unless find_file("/opt/${user}${userpostfix}/runnerdata") {
file { "/opt/${user}${userpostfix}/runnerdata":
ensure => directory,
mode => '0700',
2024-02-06 10:03:33 +00:00
owner => "${user}${userpostfix}",
group => "${user}${userpostfix}",
}
}
2024-02-06 10:03:33 +00:00
file { "/opt/${user}${userpostfix}/runnerdata/config.yml":
ensure => file,
source => 'puppet:///modules/podmanrunner/forgejo-runner-config.yml',
2024-02-06 10:03:33 +00:00
owner => "${user}${userpostfix}",
group => "${user}${userpostfix}",
mode => '0400',
}
# Make sure the podman user can read the /data dir
2024-02-06 10:03:33 +00:00
exec { "make-${user}${userpostfix}-own-runnerdata":
command => "systemd-run --wait --user --machine=${user}${userpostfix}@ /bin/bash -c 'podman unshare chown 1000:1000 /opt/${user}${userpostfix}/runnerdata'",
path => '/usr/bin:/usr/sbin:/bin',
provider => shell,
logoutput => false,
2024-02-06 10:03:33 +00:00
unless => "systemd-run --wait --user --machine=${user}${userpostfix}@ /bin/bash -c 'podman unshare stat --format %u /opt/${user}${userpostfix}/runnerdata | grep ^1000$ && podman unshare stat --format %g /opt/${user}${userpostfix}/runnerdata | grep ^1000$'",
}
2024-02-06 10:03:33 +00:00
exec { "enable-${user}${userpostfix}-linger":
command => "loginctl enable-linger ${user}${userpostfix}",
path => '/usr/bin:/usr/sbin:/bin',
provider => shell,
logoutput => false,
2024-02-06 10:03:33 +00:00
unless => "test -f /var/lib/systemd/linger/${user}${userpostfix}",
}
}
2024-01-25 20:30:09 +00:00
2024-02-06 10:03:33 +00:00
if $runnerdata and $runnerdata["${user}${userpostfix}"] and 'url' in $runnerdata["${user}${userpostfix}"] {
notify {"runnercontent${userpostfix}":
message => $runnerdata["${user}${userpostfix}"]
2024-01-25 20:30:09 +00:00
}
}
2024-01-18 15:27:32 +00:00
}
}