|
| 1 | +# @summary |
| 2 | +# TMA multi-user workstation: XFCE, Docker services, LabVIEW, VIPM |
| 3 | +# |
| 4 | +# @param tma_db_repo TMA MariaDB repository |
| 5 | +# @param tma_db_path Path for TMA DB (shared service) |
| 6 | +# @param github_token GitHub Personal Access Token for private repos (optional) |
| 7 | +# @param pxi_0_ip PXI 0 IP address |
| 8 | +# @param pxi_1_ip PXI 1 IP address |
| 9 | +# @param opman_path Operation Manager path (shared service) |
| 10 | +# @param labview_rpm_url Full URL to NI LabVIEW RPM |
| 11 | +# @param compose_cmd Docker compose command (docker-compose or docker compose) |
| 12 | +# @param ghcr_username GitHub Container Registry username |
| 13 | +# @param ghcr_token GitHub Container Registry token (Sensitive) |
| 14 | +# @param vipm_url VIPM ZIP download URL |
| 15 | +# @param vipc_url VIPC dependencies URL |
| 16 | +# @param vipm_root VIPM root installation path |
| 17 | +# @param vipc_path VIPC file destination path |
| 18 | +# @param enable_graphical Enable graphical mode (XFCE + GDM) |
| 19 | +# @param tma_group LDAP group name for TMA users (must exist in FreeIPA) |
| 20 | +class profile::ts::tma ( |
| 21 | + String[1] $tma_db_repo, |
| 22 | + Stdlib::Absolutepath $tma_db_path, |
| 23 | + String[1] $pxi_0_ip, |
| 24 | + String[1] $pxi_1_ip, |
| 25 | + Optional[Sensitive[String[1]]] $github_token = undef, |
| 26 | + Stdlib::Absolutepath $opman_path = '/opt/tma/operation-manager', |
| 27 | + String[1] $labview_rpm_url = 'https://repo-nexus.lsst.org/nexus/repository/ts_yum/releases/ni-labview-2024-pro-24.3.2.49152-0%2Bf0-rhel9.noarch.rpm', |
| 28 | + String[1] $compose_cmd = 'docker-compose', |
| 29 | + Optional[String[1]] $ghcr_username = undef, |
| 30 | + Optional[Sensitive[String[1]]] $ghcr_token = undef, |
| 31 | + Optional[String[1]] $vipm_url = undef, |
| 32 | + String[1] $vipc_url = 'https://github.com/lsst-ts/ts_tma_vipm_dependency/raw/develop/LSST_tma_dependencies.vipc', |
| 33 | + Stdlib::Absolutepath $vipm_root = '/usr/local/JKI/VIPM', |
| 34 | + Stdlib::Absolutepath $vipc_path = '/usr/local/JKI/VIPM/LSST_tma_dependencies.vipc', |
| 35 | + Boolean $enable_graphical = true, |
| 36 | + String[1] $tma_group = 'tma', |
| 37 | +) { |
| 38 | + if $enable_graphical { |
| 39 | + ensure_packages(['@base-x', '@xfce-desktop']) |
| 40 | + |
| 41 | + exec { 'set-graphical-target': |
| 42 | + command => '/bin/systemctl set-default graphical.target', |
| 43 | + unless => '/bin/systemctl get-default | grep -q graphical.target', |
| 44 | + onlyif => '/bin/systemctl is-active sssd', |
| 45 | + path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'], |
| 46 | + require => [Class['ipa::client'], Package['@base-x'], Package['@xfce-desktop']], |
| 47 | + } |
| 48 | + |
| 49 | + file { '/etc/gdm/custom.conf': |
| 50 | + ensure => file, |
| 51 | + owner => 'root', |
| 52 | + group => 'root', |
| 53 | + mode => '0644', |
| 54 | + content => epp('profile/ts/tma/gdm-custom.conf.epp'), |
| 55 | + notify => Service['gdm'], |
| 56 | + } |
| 57 | + |
| 58 | + service { 'gdm': |
| 59 | + ensure => running, |
| 60 | + enable => true, |
| 61 | + require => [Exec['set-graphical-target'], Package['@xfce-desktop']], |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + if $ghcr_username != undef and $ghcr_token != undef { |
| 66 | + exec { 'docker-login-ghcr': |
| 67 | + command => "bash -lc 'printf %s ${ghcr_token.unwrap} | docker login ghcr.io -u ${ghcr_username} --password-stdin'", |
| 68 | + unless => "bash -lc 'docker info 2>/dev/null | grep -q ghcr.io'", |
| 69 | + path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'], |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + file { '/opt/tma': |
| 74 | + ensure => directory, |
| 75 | + owner => 'root', |
| 76 | + group => $tma_group, |
| 77 | + mode => '0775', |
| 78 | + require => Class['ipa'], |
| 79 | + } |
| 80 | + |
| 81 | + if $github_token != undef { |
| 82 | + file { $tma_db_path: |
| 83 | + ensure => directory, |
| 84 | + owner => 'root', |
| 85 | + group => $tma_group, |
| 86 | + mode => '2775', |
| 87 | + require => [File['/opt/tma'], Class['ipa']], |
| 88 | + } |
| 89 | + |
| 90 | + $tma_db_source = regsubst($tma_db_repo, '^git@github\.com:', "https://${github_token.unwrap}@github.com/") |
| 91 | + |
| 92 | + vcsrepo { $tma_db_path: |
| 93 | + ensure => present, |
| 94 | + provider => git, |
| 95 | + source => $tma_db_source, |
| 96 | + require => File[$tma_db_path], |
| 97 | + } |
| 98 | + |
| 99 | + file { "${tma_db_path}/backup": |
| 100 | + ensure => directory, |
| 101 | + owner => 'root', |
| 102 | + group => $tma_group, |
| 103 | + mode => '2775', |
| 104 | + require => Class['ipa'], |
| 105 | + } |
| 106 | + |
| 107 | + exec { 'tma-db-up': |
| 108 | + command => "${compose_cmd} up -d", |
| 109 | + cwd => $tma_db_path, |
| 110 | + refreshonly => true, |
| 111 | + subscribe => Vcsrepo[$tma_db_path], |
| 112 | + path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin', '/usr/local/bin'], |
| 113 | + } |
| 114 | + |
| 115 | + cron { 'tma-db-createbackup': |
| 116 | + ensure => present, |
| 117 | + command => "${tma_db_path}/createbackup.pl", |
| 118 | + minute => '5', |
| 119 | + hour => '12', |
| 120 | + user => 'root', |
| 121 | + } |
| 122 | + |
| 123 | + cron { 'tma-db-python-backup': |
| 124 | + ensure => present, |
| 125 | + command => "docker run --rm -v ${tma_db_path}/python:/script -v ${tma_db_path}/backup:/backup python:3.7 python /script/main.py", |
| 126 | + minute => '5', |
| 127 | + hour => '13', |
| 128 | + user => 'root', |
| 129 | + } |
| 130 | + } else { |
| 131 | + notify { 'tma-db-skip': |
| 132 | + message => 'TMA DB skip: no GitHub token', |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + file { $opman_path: |
| 137 | + ensure => directory, |
| 138 | + owner => 'root', |
| 139 | + group => $tma_group, |
| 140 | + mode => '2775', |
| 141 | + require => [File['/opt/tma'], Class['ipa']], |
| 142 | + } |
| 143 | + |
| 144 | + $compose_content = @("COMPOSE") |
| 145 | + version: '3' |
| 146 | + services: |
| 147 | + mt-mount-manager: |
| 148 | + image: ghcr.io/lsst-ts/ts_tma_operation-manager_mt-mount-operation-manager:latest |
| 149 | + container_name: mt-mount-manager |
| 150 | + ports: |
| 151 | + - "60005:60005" |
| 152 | + - "40005:40005" |
| 153 | + - "30005:30005" |
| 154 | + volumes: |
| 155 | + - /var/log/mtmount_operation_manager/:/var/log/mtmount_operation_manager |
| 156 | + environment: |
| 157 | + - PXI_0_IP=${pxi_0_ip} |
| 158 | + - PXI_1_IP=${pxi_1_ip} |
| 159 | + restart: unless-stopped |
| 160 | + | COMPOSE |
| 161 | + |
| 162 | + file { "${opman_path}/docker-compose.yml": |
| 163 | + ensure => file, |
| 164 | + owner => 'root', |
| 165 | + group => $tma_group, |
| 166 | + mode => '0664', |
| 167 | + content => $compose_content, |
| 168 | + require => Class['ipa'], |
| 169 | + notify => Exec['opman-up'], |
| 170 | + } |
| 171 | + |
| 172 | + exec { 'opman-up': |
| 173 | + command => "${compose_cmd} up -d", |
| 174 | + cwd => $opman_path, |
| 175 | + refreshonly => true, |
| 176 | + path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin', '/usr/local/bin'], |
| 177 | + } |
| 178 | + |
| 179 | + yumrepo { 'ni-labview-2024-el9-pro': |
| 180 | + ensure => present, |
| 181 | + baseurl => 'https://download.ni.com/ni-linux-desktop/LabVIEW/2024/Q3/f2/pro/rpm/ni-labview-2024/el9', |
| 182 | + enabled => 1, |
| 183 | + gpgcheck => 0, |
| 184 | + repo_gpgcheck => 0, |
| 185 | + before => Package['ni-labview-2024-pro'], |
| 186 | + } |
| 187 | + |
| 188 | + package { 'ni-labview-2024-pro': |
| 189 | + ensure => '24.3.2.49152-0+f0', |
| 190 | + } |
| 191 | + |
| 192 | + file { ['/usr/local/JKI', '/etc/JKI']: |
| 193 | + ensure => directory, |
| 194 | + owner => 0, |
| 195 | + group => 0, |
| 196 | + mode => '0755', |
| 197 | + } |
| 198 | + |
| 199 | + file { $vipm_root: |
| 200 | + ensure => directory, |
| 201 | + owner => 0, |
| 202 | + group => 0, |
| 203 | + mode => '0755', |
| 204 | + require => File['/usr/local/JKI'], |
| 205 | + } |
| 206 | + |
| 207 | + if $vipm_url != undef { |
| 208 | + exec { 'vipm-download': |
| 209 | + command => "curl -fsSL -o /tmp/vipm.zip ${vipm_url}", |
| 210 | + unless => "test -x ${vipm_root}/vipm", |
| 211 | + path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'], |
| 212 | + require => File[$vipm_root], |
| 213 | + } |
| 214 | + |
| 215 | + exec { 'vipm-unzip': |
| 216 | + command => "unzip -o /tmp/vipm.zip -d ${vipm_root} && rm -f /tmp/vipm.zip", |
| 217 | + unless => "test -x ${vipm_root}/vipm", |
| 218 | + path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'], |
| 219 | + require => Exec['vipm-download'], |
| 220 | + } |
| 221 | + } |
| 222 | + |
| 223 | + if $github_token != undef { |
| 224 | + exec { 'vipc-fetch': |
| 225 | + command => "bash -lc 'curl -fsSL -H \"Authorization: token ${github_token.unwrap}\" -o ${vipc_path} ${vipc_url}'", |
| 226 | + creates => $vipc_path, |
| 227 | + path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'], |
| 228 | + require => File[$vipm_root], |
| 229 | + } |
| 230 | + } else { |
| 231 | + notify { 'vipc-skip': |
| 232 | + message => 'VIPC skip: no GitHub token', |
| 233 | + } |
| 234 | + } |
| 235 | +} |
0 commit comments