Skip to content

Instantly share code, notes, and snippets.

@hpcprofessional
Last active September 10, 2018 23:14
Show Gist options
  • Save hpcprofessional/9f0663ad5b1652f709e99311be68f194 to your computer and use it in GitHub Desktop.
Save hpcprofessional/9f0663ad5b1652f709e99311be68f194 to your computer and use it in GitHub Desktop.
A Puppet profile to install the Puppet Container Registry
# Puppet Container Registry (PCR) Evaluation quickstart
#
# Tested with Cent 7
#
# This script supports two options:
# 1. Puppet apply and then run start_script.sh
# 2. install puppetlabs/docker, uncomment lines 97 - 117, then Puppet apply
#
# Standalone usage: puppet apply profile_pcr.pp
# Traditional usage: Remove the 'include' line at the end and copy to your profile manifests directory
class profile::pcr (
$home_dir = '/pipelines', #Directory to execute PCR
$storage_dir = "$home_dir/pcr", #Subdir for PCR image storage volume mount (if S3 not used)
$mysql_dir = "$home_dir/mysql", #Subdir for MySQL volume mount
$mysql_db = "PCRDB",
$europa_db_endpoint = 'mysql://172.17.0.1:3306/PCRDB',
$europa_db_user = 'pcr',
$europa_db_pass = 'password',
) {
package { 'docker' :
ensure => present,
}
service { 'docker' :
ensure => running,
}
user { ['docker','pcr'] :
ensure => present,
}
group { ['docker','pcr'] :
ensure => present,
}
file { [$home_dir, $storage_dir, $mysql_dir] :
ensure => directory,
owner => 'pcr',
group => 'pcr',
mode => '0755',
}
file { "${home_dir}/pcr.env" :
ensure => file,
owner => 'pcr',
group => 'pcr',
mode => '0755',
content => @("END")
EUROPA_DB_ENDPOINT=$europa_db_endpoint
EUROPA_DB_USER=$europa_db_user
EUROPA_DB_PASS=$europa_db_pass
| END
}
file { "${home_dir}/mysql.env" :
ensure => file,
owner => 'pcr',
group => 'pcr',
mode => '0755',
content => @("END")
MYSQL_ROOT_PASSWORD=$europa_db_pass
MYSQL_DATABASE=$mysql_db
MYSQL_USER=pcr
MYSQL_PASSWORD=$europa_db_pass
MYSQL_ROOT_HOST=172.17.0.1
| END
}
#This script can be used to pull and start the containers if installing puppetlabs/docker isn't desired
file { "${home_dir}/start_script.sh" :
ensure => file,
owner => 'pcr',
group => 'pcr',
mode => '0755',
content => @("END")
#!/bin/bash
docker pull puppet/puppet-container-registry-enterprise:latest
docker pull mysql/mysql-server:5.7
cd $home_dir
docker run --rm --name mysql -v ${mysql_dir}:/var/lib/mysql --env-file ${home_dir}/mysql.env -p 3306:3306 -d mysql/mysql-server:5.7
sleep 10 #experience shows it's best to give this container a few moments to initialize
docker run --rm --name pcr -v ${storage_dir}:${storage_dir} --env-file ${home_dir}/pcr.env -p 80:80 -p 443:443 -d puppet/puppet-container-registry-enterprise:latest
| END
}
#puppet module install puppetlabs/docker module to uncomment and use the code below
#docker::image { 'puppet/puppet-container-registry-enterprise:latest' : }
#docker::image { 'mysql/mysql-server:5.7' : }
#docker::run { 'mysql' :
# image => 'mysql/mysql-server:5.7',
# volumes => "${mysql_dir}:/var/lib/mysql",
# env_file => "${home_dir}/mysql.env",
# ports => ['3306:3306'],
# remove_container_on_stop => true,
# require => Service['docker']
#}
#docker::run { 'pcr' :
# image => 'puppet/puppet-container-registry-enterprise:latest',
# volumes => "${home_dir}",
# env_file => "${home_dir}/pcr.env",
# ports => ['80:80','443:443'],
# remove_container_on_stop => true,
# after => [ 'mysql' ],
# require => Service['docker']
#}
}
include profile::pcr_evaluation #This line makes it work with puppet apply; remove if put on Puppet master.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment