Skip to content

Instantly share code, notes, and snippets.

@tdsmith
Created December 22, 2021 21:26
Show Gist options
  • Save tdsmith/478f6346ed227e19132c1cb413821cb4 to your computer and use it in GitHub Desktop.
Save tdsmith/478f6346ed227e19132c1cb413821cb4 to your computer and use it in GitHub Desktop.
include 'apt'
include 'cron'
include 'docker'
$gcloud_project = 'my-project-name'
$service_account = 'my-service-account@my-project-name.iam.gserviceaccount.com'
$auth_token_path = '/root/service_credentials.json'
## Configure Docker to authorize to Google Artifact Registry
apt::source { 'cloud-sdk':
location => 'https://packages.cloud.google.com/apt',
repos => 'main',
release => 'cloud-sdk',
key => {
id => '7F92E05B31093BEF5A3C2D38FEEA9169307EA071',
source => 'https://packages.cloud.google.com/apt/doc/apt-key.gpg'
},
}
package { 'google-cloud-sdk':
ensure => latest,
require => [Apt::Source['cloud-sdk'], Class['apt::update']],
}
file { $auth_token_path:
ensure => file,
# finds modules/gcloud/files/service_credentials.json
source => 'puppet:///modules/gcloud/service_credentials.json',
mode => '0600',
owner => 'root',
}
exec { 'gcloud-auth':
command => [
'/usr/bin/gcloud',
'auth',
'activate-service-account',
$service_account,
'--key-file',
$auth_token_path,
'--project',
$gcloud_project
],
require => [File[$auth_token_path]]
}
exec { 'gcloud-docker':
command => [
'/usr/bin/gcloud',
'auth',
'configure-docker',
'us-west1-docker.pkg.dev'
],
require => [Exec['gcloud-auth']]
}
## Set up Docker mount point
file { '/volumes': ensure => directory }
## Set up Docker networking
docker_network { 'docker':
ensure => present,
driver => 'bridge'
}
## Set up Caddy
docker::image { 'us-west1-docker.pkg.dev/.../docker/caddy':
ensure => latest,
require => [Exec['gcloud-docker']],
}
file { [
'/volumes/caddy-data',
'/volumes/caddy-config',
]:
ensure => directory
}
docker::run { 'caddy':
image => 'us-west1-docker.pkg.dev/.../docker/caddy',
net => 'docker',
ports => ['80:80', '443:443', '1337:1337'],
systemd_restart => 'always',
volumes => ['/volumes/www:/www:ro', '/volumes/caddy-data:/data','/volumes/caddy-config:/config'],
require => [File['/volumes/caddy-data'], File['/volumes/caddy-config']],
subscribe => Docker::Image['us-west1-docker.pkg.dev/.../docker/caddy'],
}
## set up ZNC
file { [
'/volumes/znc',
'/volumes/znc/modules',
]:
ensure => directory,
}
file { '/volumes/znc/modules/clientbuffer.cpp':
ensure => file,
source => 'puppet:///modules/znc/znc-clientbuffer/clientbuffer.cpp',
}
docker::image { 'znc':
ensure => latest,
}
docker::run { 'znc':
image => 'znc',
net => 'docker',
expose => ['2337'],
ports => ['127.0.0.1:2337:2337'],
systemd_restart => 'always',
volumes => ['/volumes/znc:/znc-data'],
subscribe => [File['/volumes/znc/modules/clientbuffer.cpp'], Docker::Image['znc']],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment