2024-01-18 06:52:38 +00:00
|
|
|
# Class for forgeo action runner.
|
2024-01-18 08:19:55 +00:00
|
|
|
class podmanrunner::runner (
|
|
|
|
Integer $replicas = 2,
|
|
|
|
)
|
2024-01-18 06:52:38 +00:00
|
|
|
{
|
2024-02-06 10:03:33 +00:00
|
|
|
$userpostfix='runner'
|
2024-01-25 20:23:17 +00:00
|
|
|
$runnerdata = lookup("runners",undef,undef,undef)
|
2024-01-18 14:39:26 +00:00
|
|
|
package { 'podman':
|
|
|
|
ensure => installed,
|
|
|
|
provider => apt,
|
|
|
|
}
|
2024-01-18 21:25:44 +00:00
|
|
|
|
|
|
|
package { 'systemd-container':
|
|
|
|
ensure => installed,
|
|
|
|
provider => apt,
|
|
|
|
}
|
|
|
|
|
2024-01-24 14:20:10 +00:00
|
|
|
package { 'python3-dotenv':
|
|
|
|
ensure => installed,
|
|
|
|
provider => apt,
|
|
|
|
}
|
|
|
|
|
2024-01-24 14:27:53 +00:00
|
|
|
file { "/usr/local/bin/podman-compose":
|
|
|
|
ensure => file,
|
|
|
|
mode => '0555',
|
2024-01-24 15:25:22 +00:00
|
|
|
source => 'puppet:///modules/podmanrunner/podman-compose-1.0.6',
|
2024-01-24 14:27:53 +00:00
|
|
|
owner => "root",
|
|
|
|
group => "root",
|
|
|
|
}
|
|
|
|
|
2024-02-06 13:19:58 +00:00
|
|
|
$runnerdata.each |$user,$userdata| {
|
2024-01-24 14:27:53 +00:00
|
|
|
|
2024-02-06 21:09:52 +00:00
|
|
|
$sdrun = "systemd-run --wait --user --machine=${user}${userpostfix}@"
|
|
|
|
user { "${user}${userpostfix}":
|
2024-01-19 08:33:10 +00:00
|
|
|
ensure => present,
|
2024-02-06 10:03:33 +00:00
|
|
|
home => "/opt/${user}${userpostfix}",
|
2024-01-19 08:33:10 +00:00
|
|
|
shell => '/usr/sbin/nologin',
|
|
|
|
managehome => true,
|
|
|
|
}
|
|
|
|
|
2024-02-06 10:03:33 +00:00
|
|
|
file { "/opt/${user}${userpostfix}/docker-compose.yaml":
|
2024-01-19 08:33:10 +00:00
|
|
|
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-19 08:33:10 +00:00
|
|
|
}
|
|
|
|
|
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":
|
2024-01-24 16:17:28 +00:00
|
|
|
ensure => directory,
|
|
|
|
mode => '0700',
|
2024-02-06 10:03:33 +00:00
|
|
|
owner => "${user}${userpostfix}",
|
|
|
|
group => "${user}${userpostfix}",
|
2024-01-24 16:17:28 +00:00
|
|
|
}
|
2024-01-24 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 13:19:58 +00:00
|
|
|
unless find_file("/opt/${user}${userpostfix}/runnerdata/config.yml") {
|
|
|
|
file { "/opt/${user}${userpostfix}/runnerdata/config.yml":
|
|
|
|
ensure => file,
|
|
|
|
source => 'puppet:///modules/podmanrunner/forgejo-runner-config.yml',
|
|
|
|
owner => "${user}${userpostfix}",
|
|
|
|
group => "${user}${userpostfix}",
|
|
|
|
mode => '0400',
|
|
|
|
}
|
2024-01-24 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure the podman user can read the /data dir
|
2024-02-06 10:03:33 +00:00
|
|
|
exec { "make-${user}${userpostfix}-own-runnerdata":
|
2024-02-06 21:09:52 +00:00
|
|
|
command => "${sdrun} /bin/bash -c 'podman unshare chown 1000:1000 /opt/${user}${userpostfix}/runnerdata'",
|
2024-01-24 15:25:22 +00:00
|
|
|
path => '/usr/bin:/usr/sbin:/bin',
|
|
|
|
provider => shell,
|
|
|
|
logoutput => false,
|
2024-02-06 21:09:52 +00:00
|
|
|
unless => "${sdrun} /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-01-24 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 13:19:58 +00:00
|
|
|
# Make sure the podman user can read the /data/config.yml file
|
|
|
|
exec { "podman-${user}${userpostfix}-own-runner-config":
|
2024-02-06 21:09:52 +00:00
|
|
|
command => "${sdrun} /bin/bash -c 'podman unshare chown 1000:1000 /opt/${user}${userpostfix}/runnerdata/config.yml'",
|
2024-02-06 13:19:58 +00:00
|
|
|
path => '/usr/bin:/usr/sbin:/bin',
|
|
|
|
provider => shell,
|
|
|
|
logoutput => false,
|
2024-02-06 21:09:52 +00:00
|
|
|
unless => "${sdrun} /bin/bash -c 'podman unshare stat --format %u /opt/${user}${userpostfix}/runnerdata/config.yml | \
|
|
|
|
grep ^1000$ && podman unshare stat --format %g /opt/${user}${userpostfix}/runnerdata/config.yml | grep ^1000$'",
|
2024-02-06 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 10:03:33 +00:00
|
|
|
exec { "enable-${user}${userpostfix}-linger":
|
|
|
|
command => "loginctl enable-linger ${user}${userpostfix}",
|
2024-01-19 09:50:39 +00:00
|
|
|
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-02-06 21:09:52 +00:00
|
|
|
|
2024-02-06 22:41:42 +00:00
|
|
|
# If required, build runner image by podman-compose
|
2024-02-06 22:13:12 +00:00
|
|
|
exec { "${user}${userpostfix}-build-runner-image":
|
|
|
|
command => "${sdrun} /bin/bash -c 'podman-compose build'",
|
|
|
|
path => '/usr/bin:/usr/sbin:/bin',
|
|
|
|
provider => shell,
|
|
|
|
logoutput => false,
|
2024-02-06 22:41:42 +00:00
|
|
|
unless => "${sdrun} /bin/bash -c \"podman image ls | grep '^localhost/podmanrunner\s\s*3\.[0-9]\.[0-9]'\"",
|
2024-02-06 22:13:12 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 21:09:52 +00:00
|
|
|
# If not already done, register runner with forgejo instance.
|
|
|
|
if $userdata and $userdata["token"] and $userdata["url"] {
|
|
|
|
exec { "${user}${userpostfix}-register-runner":
|
|
|
|
command => "${sdrun} /bin/bash -c 'podman run -it --rm -u podman -v ./runnerdata:/data:Z localhost/podmanrunner:3.3.0 /bin/bash -c \
|
|
|
|
\"date >> /data/register.log && forgejo-runner --config /data/config.yml register --no-interactive \
|
2024-02-06 22:13:12 +00:00
|
|
|
--token ${userdata["token"]} --name runner1 --instance ${userdata["url"]} 1>>/data/register.log 2>&1\"'",
|
2024-02-06 21:09:52 +00:00
|
|
|
path => '/usr/bin:/usr/sbin:/bin',
|
|
|
|
provider => shell,
|
|
|
|
logoutput => false,
|
|
|
|
unless => "test -f /opt/${user}${userpostfix}/runnerdata/.runner",
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 15:27:32 +00:00
|
|
|
}
|
2024-01-18 06:52:38 +00:00
|
|
|
}
|