Skip to content

Instantly share code, notes, and snippets.

@optiz0r
Created April 20, 2020 16:52
Show Gist options
  • Save optiz0r/3754da2cbe4e657ab73135a5c25e3756 to your computer and use it in GitHub Desktop.
Save optiz0r/3754da2cbe4e657ab73135a5c25e3756 to your computer and use it in GitHub Desktop.
puppet code for deploying nomad as a docker container
# == Class: sihnon::nomad
#
# Deploys nomad in docker
#
class sihnon::nomad (
String $image_name = 'optiz0r/nomad',
String $image_tag = '0.11.0-beta2',
String $root_dir = '/srv/nomad',
String $cert_name = $::fqdn,
Array[Stdlib::Host] $servers = [
'beaumonde.jellybean.sihnon.net',
'bellerophon.jellybean.sihnon.net',
'bernadette.jellybean.sihnon.net',
],
Stdlib::Fqdn $consul_domain = lookup('sihnon::consul::consul_domain', Stdlib::Fqdn, 'first', 'consul'),
Sensitive $consul_token = undef,
Sensitive $vault_token = undef,
) {
include ::sihnon::docker
$server = $::fqdn in $servers
$client = ! $server
file {
$root_dir:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0775';
"${root_dir}/config":
ensure => directory;
"${root_dir}/config/config.hcl":
content => epp('sihnon/app/nomad/config.hcl.epp', {
server => $server,
client => $client,
consul_domain => $consul_domain,
consul_token => $consul_token,
vault_token => $vault_token,
root_dir => $root_dir,
}),
show_diff => true;
#"${root_dir}/config/server.key":
# source => "/etc/dehydrated/private/${cert_name}.key",
# require => Dehydrated::Certificate[$cert_name];
#"${root_dir}/config/server.crt":
# source => "/etc/dehydrated/certs/${cert_name}_fullchain.pem",
# require => Dehydrated::Certificate[$cert_name];
#"${root_dir}/config/ca.crt":
# source => "/etc/dehydrated/certs/${cert_name}_ca.pem",
# require => Dehydrated::Certificate[$cert_name];
"${root_dir}/data":
ensure => directory,
owner => 'root',
group => 'root',
mode => '0775';
}
docker::image {
$image_name:
image_tag => $image_tag;
}
docker::run {
'nomad':
image => "${image_name}:${image_tag}",
detach => false,
privileged => true,
net => 'host',
ports => [
'4646:4646/tcp',
'4647:4647/tcp',
'4648:4648/tcp',
],
env => [
"NOMAD_DATA_DIR=${root_dir}/data",
],
volumes => [
"${root_dir}/config:${root_dir}/config",
"${root_dir}/data:${root_dir}/data",
'/run/docker.sock:/var/run/docker.sock',
'/tmp:/tmp',
],
service_provider => 'systemd',
extra_parameters => [
'--restart=unless-stopped',
],
command => "agent -config ${root_dir}/config",
require => [
File[
"${root_dir}/data",
],
],
subscribe => File[
"${root_dir}/config/config.hcl",
#"${root_dir}/config/server.key",
#"${root_dir}/config/server.crt",
#"${root_dir}/config/ca.crt",
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment