2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
# ContainerTest.pm - Build containers for testing and documentation
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
package pgBackRestTest::Common::ContainerTest;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess longmess);
|
2016-10-01 19:39:44 +02:00
|
|
|
use English '-no_match_vars';
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
use Cwd qw(abs_path);
|
2018-07-21 23:02:42 +02:00
|
|
|
use Digest::SHA qw(sha1_hex);
|
2016-01-09 15:21:53 +02:00
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
2015-12-29 20:57:10 +02:00
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use Getopt::Long qw(GetOptions);
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
2016-05-11 00:12:37 +02:00
|
|
|
use pgBackRest::Common::String;
|
2016-10-01 19:39:44 +02:00
|
|
|
use pgBackRest::Version;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::VmTest;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# User/group definitions
|
|
|
|
####################################################################################################################################
|
2015-12-29 20:57:10 +02:00
|
|
|
use constant POSTGRES_GROUP => 'postgres';
|
2016-10-01 19:39:44 +02:00
|
|
|
push @EXPORT, qw(POSTGRES_GROUP);
|
2018-07-21 23:02:42 +02:00
|
|
|
use constant POSTGRES_GROUP_ID => 5000;
|
2015-12-29 20:57:10 +02:00
|
|
|
use constant POSTGRES_USER => POSTGRES_GROUP;
|
2018-07-21 23:02:42 +02:00
|
|
|
use constant POSTGRES_USER_ID => 5000;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
use constant TEST_GROUP => getgrgid($UID) . '';
|
2016-12-04 00:34:51 +02:00
|
|
|
push @EXPORT, qw(TEST_GROUP);
|
2017-02-21 15:59:23 +02:00
|
|
|
use constant TEST_GROUP_ID => getgrnam(TEST_GROUP) . '';
|
2016-10-01 19:39:44 +02:00
|
|
|
use constant TEST_USER => getpwuid($UID) . '';
|
|
|
|
push @EXPORT, qw(TEST_USER);
|
|
|
|
use constant TEST_USER_ID => $UID;
|
2016-06-12 15:00:16 +02:00
|
|
|
|
2018-02-04 01:27:38 +02:00
|
|
|
use constant BACKREST_USER => 'pgbackrest';
|
2016-12-23 15:22:59 +02:00
|
|
|
push @EXPORT, qw(BACKREST_USER);
|
2016-09-06 20:01:39 +02:00
|
|
|
use constant BACKREST_USER_ID => getpwnam(BACKREST_USER) . '';
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Package constants
|
|
|
|
####################################################################################################################################
|
2018-06-06 21:52:28 +02:00
|
|
|
use constant LIB_COVER_VERSION => '1.29-2';
|
2017-04-10 18:31:30 +02:00
|
|
|
push @EXPORT, qw(LIB_COVER_VERSION);
|
|
|
|
use constant LIB_COVER_EXE => '/usr/bin/cover';
|
|
|
|
push @EXPORT, qw(LIB_COVER_EXE);
|
|
|
|
|
2017-08-08 22:26:44 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Cert file constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant CERT_FAKE_PATH => '/etc/fake-cert';
|
|
|
|
use constant CERT_FAKE_CA => CERT_FAKE_PATH . '/ca.crt';
|
|
|
|
push @EXPORT, qw(CERT_FAKE_CA);
|
2017-08-08 23:15:01 +02:00
|
|
|
use constant CERT_FAKE_SERVER => CERT_FAKE_PATH . '/server.crt';
|
|
|
|
push @EXPORT, qw(CERT_FAKE_SERVER);
|
|
|
|
use constant CERT_FAKE_SERVER_KEY => CERT_FAKE_PATH . '/server.key';
|
|
|
|
push @EXPORT, qw(CERT_FAKE_SERVER_KEY);
|
2017-08-08 22:26:44 +02:00
|
|
|
|
2016-10-01 19:39:44 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
# Container Debug - speeds container debugging by splitting each section into a separate intermediate container
|
2016-10-01 19:39:44 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
use constant CONTAINER_DEBUG => false;
|
2016-10-01 19:39:44 +02:00
|
|
|
|
2018-06-12 19:43:15 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Container Debug - speeds container debugging by splitting each section into a separate intermediate container
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant CONTAINER_S3_SERVER_TAG => 's3-server-20180612A';
|
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Store cache container checksums
|
|
|
|
####################################################################################################################################
|
|
|
|
my $hContainerCache;
|
|
|
|
|
2017-11-19 03:14:14 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Generate Devel::Cover package name
|
|
|
|
####################################################################################################################################
|
|
|
|
sub packageDevelCover
|
|
|
|
{
|
|
|
|
my $strArch = shift;
|
|
|
|
|
|
|
|
return 'libdevel-cover-perl_' . LIB_COVER_VERSION . "_${strArch}.deb";
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(packageDevelCover);
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
# Container repo - defines the Docker repository where the containers will be located
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
sub containerRepo
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
return BACKREST_EXE . qw(/) . 'test';
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
push @EXPORT, qw(containerRepo);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
# Section header
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
sub sectionHeader
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
return (CONTAINER_DEBUG ? "\n\nRUN \\\n" : " && \\\n\n");
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 00:47:29 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Write the Docker container
|
|
|
|
####################################################################################################################################
|
|
|
|
sub containerWrite
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
my $oStorageDocker = shift;
|
2016-04-14 00:47:29 +02:00
|
|
|
my $strTempPath = shift;
|
2016-06-12 15:00:16 +02:00
|
|
|
my $strOS = shift;
|
|
|
|
my $strTitle = shift;
|
|
|
|
my $strImageParent = shift;
|
2016-04-14 00:47:29 +02:00
|
|
|
my $strImage = shift;
|
2017-06-24 16:59:00 +02:00
|
|
|
my $strCopy = shift;
|
2016-06-12 15:00:16 +02:00
|
|
|
my $strScript = shift;
|
2016-04-14 00:47:29 +02:00
|
|
|
my $bForce = shift;
|
2016-06-12 15:00:16 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
my $strTag = containerRepo() . ":${strImage}";
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
$strScript =
|
|
|
|
"# ${strTitle} Container\n" .
|
2018-07-21 23:02:42 +02:00
|
|
|
"FROM ${strImageParent}" .
|
|
|
|
(defined($strCopy) ? "\n\n${strCopy}\n\n" : '') .
|
|
|
|
(defined($strScript) && $strScript ne ''?
|
|
|
|
"\n\nRUN echo '" . (CONTAINER_DEBUG ? 'DEBUG' : 'OPTIMIZED') . " BUILD'" . $strScript : '');
|
|
|
|
|
|
|
|
# Search for the image in the cache
|
|
|
|
my $strScriptSha1;
|
|
|
|
my $bCached = false;
|
|
|
|
|
|
|
|
if ($strImage =~ /\-base$/)
|
|
|
|
{
|
|
|
|
$strScriptSha1 = sha1_hex($strScript);
|
|
|
|
|
|
|
|
foreach my $strBuild (reverse(keys(%{$hContainerCache})))
|
|
|
|
{
|
|
|
|
if (defined($hContainerCache->{$strBuild}{$strOS}) && $hContainerCache->{$strBuild}{$strOS} eq $strScriptSha1)
|
|
|
|
{
|
|
|
|
&log(INFO, "Using cached ${strTag}-${strBuild} image (${strScriptSha1}) ...");
|
|
|
|
|
|
|
|
$strScript =
|
|
|
|
"# ${strTitle} Container\n" .
|
|
|
|
"FROM ${strTag}-${strBuild}";
|
|
|
|
|
|
|
|
$bCached = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$bCached)
|
|
|
|
{
|
|
|
|
&log(INFO, "Building ${strTag} image" . (defined($strScriptSha1) ? " (${strScriptSha1})" : '') . ' ...');
|
|
|
|
}
|
2016-04-14 00:47:29 +02:00
|
|
|
|
|
|
|
# Write the image
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageDocker->put("${strTempPath}/${strImage}", trim($strScript) . "\n");
|
2016-04-14 00:47:29 +02:00
|
|
|
executeTest('docker build' . (defined($bForce) && $bForce ? ' --no-cache' : '') .
|
2017-02-21 15:59:23 +02:00
|
|
|
" -f ${strTempPath}/${strImage} -t ${strTag} ${strTempPath}",
|
2016-04-14 00:47:29 +02:00
|
|
|
{bSuppressStdErr => true});
|
|
|
|
}
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
# User/group creation
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
sub groupCreate
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
|
|
|
my $strOS = shift;
|
2017-06-24 16:59:00 +02:00
|
|
|
my $strName = shift;
|
|
|
|
my $iId = shift;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
return "groupadd -g${iId} ${strName}";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
sub userCreate
|
2016-06-12 15:00:16 +02:00
|
|
|
{
|
|
|
|
my $strOS = shift;
|
2017-06-24 16:59:00 +02:00
|
|
|
my $strName = shift;
|
|
|
|
my $iId = shift;
|
2016-06-12 15:00:16 +02:00
|
|
|
my $strGroup = shift;
|
|
|
|
|
|
|
|
my $oVm = vmGet();
|
|
|
|
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
return "adduser -g${strGroup} -u${iId} -n ${strName}";
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
elsif ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
return "adduser --uid=${iId} --ingroup=${strGroup} --disabled-password --gecos \"\" ${strName}";
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
confess &log(ERROR, "unable to create user for os '${strOS}'");
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
# Setup SSH
|
2017-04-10 18:31:30 +02:00
|
|
|
####################################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
sub sshSetup
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
|
|
|
my $strOS = shift;
|
2017-06-24 16:59:00 +02:00
|
|
|
my $strUser = shift;
|
|
|
|
my $strGroup = shift;
|
|
|
|
my $bControlMaster = shift;
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
my $strUserPath = $strUser eq 'root' ? "/${strUser}" : "/home/${strUser}";
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
my $strScript = sectionHeader() .
|
|
|
|
"# Setup SSH\n" .
|
2018-07-21 23:02:42 +02:00
|
|
|
" mkdir ${strUserPath}/.ssh && \\\n" .
|
|
|
|
" echo '-----BEGIN RSA PRIVATE KEY-----' > ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'MIICXwIBAAKBgQDR0yJsZW5d5LcqteiOtv8d+FFeFFHDPI0VTcTOdMn1iDiIP1ou' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'X3Q2OyNjsBaDbsRJd+sp9IRq1LKX3zsBcgGZANwm0zduuNEPEU94ajS/uRoejIqY' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo '/XkKOpnEF6ZbQ2S7TaE4sWeGLvba7kUFs0QTOO+N+nV2dMbdqZf6C8lazwIDAQAB' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'AoGBAJXa6xzrnFVmwgK5BKzYuX/YF5TPgk2j80ch0ct50buQXH/Cb0/rUH5i4jWS' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'T6Hy/DFUehnuzpvV6O9auTOhDs3BhEKFRuRLn1nBwTtZny5Hh+cw7azUCEHFCJlz' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'makCrVbgawtno6oU/pFgQm1FcxD0f+Me5ruNcLHqUZsPQwkRAkEA+8pG+ckOlz6R' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'AJLIHedmfcrEY9T7sfdo83bzMOz8H5soUUP4aOTLJYCla1LO7JdDnXMGo0KxaHBP' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'l8j5zDmVewJBANVVPDJr1w37m0FBi37QgUOAijVfLXgyPMxYp2uc9ddjncif0063' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo '0Wc0FQefoPszf3CDrHv/RHvhHq97jXDwTb0CQQDgH83NygoS1r57pCw9chzpG/R0' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'aMEiSPhCvz757fj+qT3aGIal2AJ7/2c/gRZvwrWNETZ3XIZOUKqIkXzJLPjBAkEA' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'wnP799W2Y8d4/+VX2pMBkF7lG7sSviHEq1sP2BZtPBRQKSQNvw3scM7XcGh/mxmY' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'yx0qpqfKa8SKbNgI1+4iXQJBAOlg8MJLwkUtrG+p8wf69oCuZsnyv0K6UMDxm6/8' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'cbvfmvODulYFaIahaqHWEZoRo5CLYZ7gN43WHPOrKxdDL78=' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo '-----END RSA PRIVATE KEY-----' >> ${strUserPath}/.ssh/id_rsa && \\\n" .
|
|
|
|
" echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDR0yJsZW5d5LcqteiOtv8d+FFeFFHDPI0VTcTOdMn1iDiIP1ouX3Q2OyNjsBaDbsRJd+sp9I" .
|
|
|
|
"Rq1LKX3zsBcgGZANwm0zduuNEPEU94ajS/uRoejIqY/XkKOpnEF6ZbQ2S7TaE4sWeGLvba7kUFs0QTOO+N+nV2dMbdqZf6C8lazw== " .
|
|
|
|
"user\@pgbackrest-test' > ${strUserPath}/.ssh/authorized_keys && \\\n" .
|
|
|
|
" echo 'Host *' > ${strUserPath}/.ssh/config && \\\n" .
|
|
|
|
" echo ' StrictHostKeyChecking no' >> ${strUserPath}/.ssh/config && \\\n";
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
if ($bControlMaster)
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
|
|
|
$strScript .=
|
2018-07-21 23:02:42 +02:00
|
|
|
" echo ' ControlMaster auto' >> ${strUserPath}/.ssh/config && \\\n" .
|
|
|
|
" echo ' ControlPath /tmp/\%r\@\%h:\%p' >> ${strUserPath}/.ssh/config && \\\n" .
|
|
|
|
" echo ' ControlPersist 30' >> ${strUserPath}/.ssh/config && \\\n";
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .=
|
2018-07-21 23:02:42 +02:00
|
|
|
" chown -R ${strUser}:${strGroup} ${strUserPath}/.ssh && \\\n" .
|
|
|
|
" chmod 700 ${strUserPath}/.ssh && \\\n" .
|
|
|
|
" chmod 600 ${strUserPath}/.ssh/*";
|
2017-06-24 16:59:00 +02:00
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
return $strScript;
|
|
|
|
}
|
|
|
|
|
2017-08-08 22:26:44 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Cert Setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub certSetup
|
|
|
|
{
|
|
|
|
return
|
|
|
|
sectionHeader() .
|
|
|
|
"# Generate fake certs\n" .
|
|
|
|
" mkdir -p -m 755 /etc/fake-cert && \\\n" .
|
|
|
|
" cd /etc/fake-cert && \\\n" .
|
|
|
|
" openssl genrsa -out ca.key 2048 && \\\n" .
|
|
|
|
" openssl req -new -x509 -extensions v3_ca -key ca.key -out ca.crt -days 99999 \\\n" .
|
|
|
|
" -subj \"/C=US/ST=Country/L=City/O=Organization/CN=pgbackrest.org\" && \\\n" .
|
|
|
|
" openssl genrsa -out server.key 2048 && \\\n" .
|
|
|
|
" openssl req -new -key server.key -out server.csr \\\n" .
|
|
|
|
" -subj \"/C=US/ST=Country/L=City/O=Organization/CN=*.pgbackrest.org\" && \\\n" .
|
|
|
|
" openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 99999 \\\n" .
|
2018-06-06 21:52:28 +02:00
|
|
|
" -sha256 && \\\n" .
|
|
|
|
" chmod 644 /etc/fake-cert/*";
|
2017-08-08 22:26:44 +02:00
|
|
|
}
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# S3 server setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub s3ServerSetup
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
# Install node.js
|
2017-06-24 16:59:00 +02:00
|
|
|
my $strScript = sectionHeader() .
|
|
|
|
"# Install node.js\n";
|
2017-06-12 16:52:32 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
if ($strOS eq VM_CO7)
|
2017-06-12 16:52:32 +02:00
|
|
|
{
|
|
|
|
$strScript .=
|
2017-06-24 16:59:00 +02:00
|
|
|
" wget -O /root/nodejs.sh https://rpm.nodesource.com/setup_6.x && \\\n" .
|
2017-06-12 16:52:32 +02:00
|
|
|
" bash /root/nodejs.sh && \\\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
" yum install -y nodejs";
|
2017-06-12 16:52:32 +02:00
|
|
|
}
|
2017-06-24 16:59:00 +02:00
|
|
|
else
|
2017-06-12 16:52:32 +02:00
|
|
|
{
|
|
|
|
$strScript .=
|
2017-06-24 16:59:00 +02:00
|
|
|
" wget -O /root/nodejs.sh https://deb.nodesource.com/setup_6.x && \\\n" .
|
2017-06-12 16:52:32 +02:00
|
|
|
" bash /root/nodejs.sh && \\\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
" apt-get install -y nodejs";
|
2018-06-06 21:52:28 +02:00
|
|
|
|
|
|
|
if ($strOS eq VM_U18)
|
|
|
|
{
|
|
|
|
$strScript .= ' npm';
|
|
|
|
}
|
2017-06-12 16:52:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Install Scality S3
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Install Scality S3\n";
|
2017-06-12 16:52:32 +02:00
|
|
|
|
|
|
|
$strScript .=
|
|
|
|
" wget -O /root/scalitys3.tar.gz https://github.com/scality/S3/archive/GA6.4.2.1.tar.gz && \\\n" .
|
|
|
|
" mkdir /root/scalitys3 && \\\n" .
|
|
|
|
" tar -C /root/scalitys3 --strip-components 1 -xvf /root/scalitys3.tar.gz && \\\n" .
|
|
|
|
" cd /root/scalitys3 && \\\n" .
|
|
|
|
" npm install && \\\n" .
|
2017-08-08 22:26:44 +02:00
|
|
|
' sed -i "0,/,/s//,\n \"certFilePaths\":{\"key\":\"\/etc\/fake\-cert\/server.key\",\"cert\":' .
|
|
|
|
'\"\/etc\/fake\-cert\/server.crt\",\"ca\":\"\/etc\/fake\-cert\/ca.crt\"},/"' . " \\\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
' ./config.json' . " && \\\n" .
|
2017-06-12 16:52:32 +02:00
|
|
|
' sed -i "s/ort\"\: 8000/ort\"\: 443/" ./config.json';
|
|
|
|
|
|
|
|
return $strScript;
|
|
|
|
}
|
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Entry point setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub entryPointSetup
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
my $strScript =
|
|
|
|
"\n\n# Start SSH when container starts\n" .
|
|
|
|
'ENTRYPOINT ';
|
|
|
|
|
|
|
|
my $oVm = vmGet();
|
|
|
|
|
|
|
|
if ($oVm->{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL || $strOS eq VM_U12)
|
|
|
|
{
|
|
|
|
$strScript .= '/usr/sbin/sshd -D';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strScript .= 'service ssh restart && bash';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $strScript;
|
|
|
|
}
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Build containers
|
|
|
|
####################################################################################################################################
|
2016-01-09 15:21:53 +02:00
|
|
|
sub containerBuild
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
my $oStorageDocker = shift;
|
2016-04-14 00:47:29 +02:00
|
|
|
my $strVm = shift;
|
|
|
|
my $bVmForce = shift;
|
|
|
|
|
2016-01-09 15:21:53 +02:00
|
|
|
# Create temp path
|
2017-06-09 23:51:41 +02:00
|
|
|
my $strTempPath = $oStorageDocker->pathGet('test/.vagrant/docker');
|
|
|
|
$oStorageDocker->pathCreate($strTempPath, {strMode => '0770', bIgnoreExists => true, bCreateParent => true});
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
# Load container definitions from yaml
|
|
|
|
require YAML::XS;
|
|
|
|
YAML::XS->import(qw(Load));
|
|
|
|
|
|
|
|
$hContainerCache = Load(${$oStorageDocker->get($oStorageDocker->pathGet('test/container.yaml'))});
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Remove old images on force
|
|
|
|
if ($bVmForce)
|
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
my $strRegExp = '^' . containerRepo();
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
if ($strVm ne 'all')
|
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
$strRegExp .= "\:${strVm}-";
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
executeTest("rm -f ${strTempPath}/" . ($strVm eq 'all' ? '*' : "${strVm}-*"));
|
|
|
|
imageRemove("${strRegExp}.*");
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# VM Images
|
|
|
|
################################################################################################################################
|
2016-05-24 14:17:13 +02:00
|
|
|
my $oVm = vmGet();
|
2016-01-11 02:30:51 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
foreach my $strOS ($strVm eq 'all' ? VM_LIST : ($strVm))
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
my $oOS = $oVm->{$strOS};
|
2016-06-12 15:00:16 +02:00
|
|
|
my $bDocBuild = false;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
# Deprecated OSs can only be used to build packages
|
|
|
|
my $bDeprecated = $oVm->{$strOS}{&VM_DEPRECATED} ? true : false;
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
# Base image
|
|
|
|
###########################################################################################################################
|
2016-06-12 15:00:16 +02:00
|
|
|
my $strImageParent = "$$oVm{$strOS}{&VM_IMAGE}";
|
|
|
|
my $strImage = "${strOS}-base";
|
2018-07-21 23:02:42 +02:00
|
|
|
my $strCopy = undef;
|
2017-06-24 16:59:00 +02:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strScript = sectionHeader() .
|
|
|
|
"# Install base packages\n";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
|
|
|
$strScript .=
|
2017-06-24 16:59:00 +02:00
|
|
|
" yum -y install epel-release && \\\n" .
|
|
|
|
" yum -y update && \\\n" .
|
2017-12-23 01:36:36 +02:00
|
|
|
" yum -y install openssh-server openssh-clients wget sudo python-pip build-essential valgrind git \\\n" .
|
2018-04-08 16:19:24 +02:00
|
|
|
" perl perl-Digest-SHA perl-DBD-Pg perl-XML-LibXML perl-IO-Socket-SSL perl-YAML-LibYAML \\\n" .
|
2018-07-21 23:02:42 +02:00
|
|
|
" gcc make perl-ExtUtils-MakeMaker perl-Test-Simple openssl-devel perl-ExtUtils-Embed rpm-build zlib-devel";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
if ($strOS eq VM_CO6)
|
|
|
|
{
|
|
|
|
$strScript .= ' perl-Time-HiRes perl-parent perl-JSON';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strScript .= ' perl-JSON-PP';
|
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2017-06-24 16:59:00 +02:00
|
|
|
else
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2018-06-06 21:52:28 +02:00
|
|
|
" export DEBCONF_NONINTERACTIVE_SEEN=true DEBIAN_FRONTEND=noninteractive && \\\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
" apt-get update && \\\n" .
|
2017-10-30 15:29:46 +02:00
|
|
|
" apt-get -y install wget python && \\\n" .
|
|
|
|
" wget --no-check-certificate -O /root/get-pip.py https://bootstrap.pypa.io/get-pip.py && \\\n" .
|
|
|
|
" python /root/get-pip.py && \\\n" .
|
2017-12-23 01:36:36 +02:00
|
|
|
" apt-get -y install openssh-server wget sudo python-pip build-essential valgrind git \\\n" .
|
2018-04-08 16:19:24 +02:00
|
|
|
" libdbd-pg-perl libhtml-parser-perl libio-socket-ssl-perl libxml-libxml-perl libssl-dev libperl-dev \\\n" .
|
2018-07-21 23:02:42 +02:00
|
|
|
" libyaml-libyaml-perl tzdata devscripts lintian libxml-checker-perl txt2man debhelper \\\n" .
|
|
|
|
" libppi-html-perl libtemplate-perl libtest-differences-perl zlib1g-dev";
|
2017-06-24 16:59:00 +02:00
|
|
|
|
2018-02-15 00:19:54 +02:00
|
|
|
if ($strOS eq VM_U12)
|
2017-06-24 16:59:00 +02:00
|
|
|
{
|
2018-02-15 00:19:54 +02:00
|
|
|
$strScript .= ' libperl5.14';
|
2017-06-24 16:59:00 +02:00
|
|
|
}
|
2018-06-06 21:52:28 +02:00
|
|
|
elsif ($strOS eq VM_U18)
|
2018-03-18 19:32:19 +02:00
|
|
|
{
|
2018-06-06 21:52:28 +02:00
|
|
|
$strScript .= ' clang-6.0 clang-tools-6.0 lcov';
|
2018-03-18 19:32:19 +02:00
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Regenerate SSH keys\n" .
|
|
|
|
" rm -f /etc/ssh/ssh_host_rsa_key* && \\\n" .
|
2017-02-21 15:59:23 +02:00
|
|
|
" ssh-keygen -t rsa -b 1024 -f /etc/ssh/ssh_host_rsa_key";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Fix root tty\n" .
|
|
|
|
" sed -i 's/^mesg n/tty -s \\&\\& mesg n/g' /root/.profile";
|
2016-07-26 22:28:43 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Suppress dpkg interactive output\n" .
|
|
|
|
" rm /etc/apt/apt.conf.d/70debconf";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
if ($strOS eq VM_U12)
|
|
|
|
{
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Create run directory required by SSH (not created automatically on Ubuntu 12.04)\n" .
|
|
|
|
" mkdir -p /var/run/sshd";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 22:26:44 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strScript .= certSetup();
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (!$bDeprecated)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .= sectionHeader() .
|
2017-11-19 02:53:41 +02:00
|
|
|
"# Create PostgreSQL user/group with known ids for testing\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
' ' . groupCreate($strOS, POSTGRES_GROUP, POSTGRES_GROUP_ID) . " && \\\n" .
|
|
|
|
' ' . userCreate($strOS, POSTGRES_USER, POSTGRES_USER_ID, POSTGRES_GROUP);
|
|
|
|
|
|
|
|
$strScript .= sectionHeader() .
|
2018-07-21 23:02:42 +02:00
|
|
|
"# Install PostgreSQL packages\n";
|
2017-06-24 16:59:00 +02:00
|
|
|
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
|
|
|
if ($strOS eq VM_CO6)
|
|
|
|
{
|
|
|
|
$strScript .=
|
2018-07-21 23:02:42 +02:00
|
|
|
" rpm -ivh \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.0/redhat/rhel-6-x86_64/pgdg-centos90-9.0-5.noarch.rpm \\\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
" http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-6.noarch.rpm \\\n" .
|
2018-07-21 23:02:42 +02:00
|
|
|
" http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-8.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-3.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-3.noarch.rpm \\\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
" http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm \\\n" .
|
2018-07-21 23:02:42 +02:00
|
|
|
" http://yum.postgresql.org/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm";
|
2017-06-24 16:59:00 +02:00
|
|
|
}
|
|
|
|
elsif ($strOS eq VM_CO7)
|
|
|
|
{
|
|
|
|
$strScript .=
|
2018-07-21 23:02:42 +02:00
|
|
|
" rpm -ivh \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.2/redhat/rhel-7-x86_64/pgdg-centos92-9.2-3.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-3.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm \\\n" .
|
|
|
|
" http://yum.postgresql.org/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm";
|
2017-06-24 16:59:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
" echo 'deb http://apt.postgresql.org/pub/repos/apt/ " .
|
2018-06-05 14:59:17 +02:00
|
|
|
$$oVm{$strOS}{&VM_OS_REPO} . '-pgdg main' . ($strOS ne VM_U12 ? ' 11' : '') .
|
|
|
|
"' >> /etc/apt/sources.list.d/pgdg.list && \\\n" .
|
2017-06-24 16:59:00 +02:00
|
|
|
" wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \\\n" .
|
2018-06-06 21:52:28 +02:00
|
|
|
" apt-get update && \\\n" .
|
|
|
|
" apt-get install -y postgresql-common && \\\n" .
|
|
|
|
" sed -i 's/^\\#create\\_main\\_cluster.*\$/create\\_main\\_cluster \\= false/' " .
|
|
|
|
"/etc/postgresql-common/createcluster.conf";
|
2017-06-24 16:59:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($oOS->{&VM_DB}) && @{$oOS->{&VM_DB}} > 0)
|
|
|
|
{
|
2018-06-06 21:52:28 +02:00
|
|
|
$strScript .= sectionHeader() .
|
2018-07-21 23:02:42 +02:00
|
|
|
"# Install PostgreSQL\n";
|
2017-06-24 16:59:00 +02:00
|
|
|
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
|
|
|
$strScript .= " yum -y install";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strScript .= " apt-get install -y";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Construct list of databases to install
|
|
|
|
foreach my $strDbVersion (@{$oOS->{&VM_DB}})
|
|
|
|
{
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
|
|
|
my $strDbVersionNoDot = $strDbVersion;
|
|
|
|
$strDbVersionNoDot =~ s/\.//;
|
|
|
|
|
|
|
|
$strScript .= " postgresql${strDbVersionNoDot}-server";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strScript .= " postgresql-${strDbVersion}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2017-06-24 16:59:00 +02:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (!$bDeprecated)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Install AWS CLI\n" .
|
2018-04-16 21:25:50 +02:00
|
|
|
" pip install --upgrade --no-cache-dir pip==9.0.3 && \\\n" .
|
2018-07-21 23:02:42 +02:00
|
|
|
" pip install --upgrade awscli";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-27 21:58:02 +02:00
|
|
|
if (!$bDeprecated && $strOS ne VM_CO6 && $strOS ne VM_U12)
|
2017-06-24 16:59:00 +02:00
|
|
|
{
|
|
|
|
$strScript .= s3ServerSetup($strOS);
|
|
|
|
}
|
2016-06-12 15:00:16 +02:00
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
containerWrite(
|
|
|
|
$oStorageDocker, $strTempPath, $strOS, 'Base', $strImageParent, $strImage, $strCopy, $strScript, $bVmForce);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-12-13 01:54:07 +02:00
|
|
|
# Build image
|
|
|
|
###########################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
$strImageParent = containerRepo() . ":${strOS}-base";
|
2016-12-13 01:54:07 +02:00
|
|
|
$strImage = "${strOS}-build";
|
2017-06-24 16:59:00 +02:00
|
|
|
$strCopy = undef;
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-11-19 03:14:14 +02:00
|
|
|
my $strPkgDevelCover = packageDevelCover($oVm->{$strOS}{&VM_ARCH});
|
2017-11-19 02:53:41 +02:00
|
|
|
my $bPkgDevelCoverBuild = vmCoverage($strOS) && !$oStorageDocker->exists("test/package/${strOS}-${strPkgDevelCover}");
|
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
$strScript = sectionHeader() .
|
|
|
|
"# Create test user\n" .
|
|
|
|
' ' . groupCreate($strOS, TEST_GROUP, TEST_GROUP_ID) . " && \\\n" .
|
|
|
|
' ' . userCreate($strOS, TEST_USER, TEST_USER_ID, TEST_GROUP);
|
|
|
|
|
2016-12-13 01:54:07 +02:00
|
|
|
# Install Perl packages
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Install pgBackRest package source\n" .
|
2018-02-08 21:49:35 +02:00
|
|
|
" git clone https://salsa.debian.org/postgresql/pgbackrest.git /root/package-src";
|
2017-06-24 16:59:00 +02:00
|
|
|
|
|
|
|
# Build only when a new version has been specified
|
2017-11-19 02:53:41 +02:00
|
|
|
if ($bPkgDevelCoverBuild)
|
2017-06-24 16:59:00 +02:00
|
|
|
{
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Install Devel::Cover package source & build\n" .
|
|
|
|
" git clone https://anonscm.debian.org/git/pkg-perl/packages/libdevel-cover-perl.git" .
|
|
|
|
" /root/libdevel-cover-perl && \\\n" .
|
|
|
|
" cd /root/libdevel-cover-perl && \\\n" .
|
|
|
|
" git checkout debian/" . LIB_COVER_VERSION . " && \\\n" .
|
|
|
|
" debuild -i -us -uc -b";
|
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-27 02:32:27 +02:00
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Install pgBackRest package source\n" .
|
|
|
|
" mkdir /root/package-src && \\\n" .
|
|
|
|
" wget -O /root/package-src/pgbackrest-conf.patch " .
|
|
|
|
"'https://git.postgresql.org/gitweb/?p=pgrpms.git;a=blob_plain;" .
|
|
|
|
"f=rpm/redhat/master/pgbackrest/master/pgbackrest-conf.patch;hb=refs/heads/master' && \\\n" .
|
|
|
|
" wget -O /root/package-src/pgbackrest.spec " .
|
|
|
|
"'https://git.postgresql.org/gitweb/?p=pgrpms.git;a=blob_plain;" .
|
|
|
|
"f=rpm/redhat/master/pgbackrest/master/pgbackrest.spec;hb=refs/heads/master'";
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
$strScript .= entryPointSetup($strOS);
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
containerWrite($oStorageDocker, $strTempPath, $strOS, 'Build', $strImageParent, $strImage, $strCopy,$strScript, $bVmForce);
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
# Copy Devel::Cover to host so it can be installed in other containers (if it doesn't already exist)
|
2017-11-19 02:53:41 +02:00
|
|
|
if ($bPkgDevelCoverBuild)
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
|
|
|
executeTest('docker rm -f test-build', {bSuppressError => true});
|
|
|
|
executeTest(
|
|
|
|
"docker run -itd -h test-build --name=test-build" .
|
|
|
|
" -v ${strTempPath}:${strTempPath} " . containerRepo() . ":${strOS}-build",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
executeTest(
|
|
|
|
"docker exec -i test-build " .
|
2017-11-19 02:53:41 +02:00
|
|
|
"bash -c 'cp /root/${strPkgDevelCover} ${strTempPath}/${strOS}-${strPkgDevelCover}'");
|
2017-04-10 18:31:30 +02:00
|
|
|
executeTest('docker rm -f test-build');
|
2017-06-24 16:59:00 +02:00
|
|
|
|
|
|
|
$oStorageDocker->move(
|
2017-11-19 02:53:41 +02:00
|
|
|
"test/.vagrant/docker/${strOS}-${strPkgDevelCover}", "test/package/${strOS}-${strPkgDevelCover}");
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
# S3 image
|
|
|
|
###########################################################################################################################
|
2017-06-24 16:59:00 +02:00
|
|
|
if (!$bDeprecated)
|
|
|
|
{
|
|
|
|
$strImage = "${strOS}-s3-server";
|
2018-07-21 23:02:42 +02:00
|
|
|
$strScript = '';
|
2017-06-24 16:59:00 +02:00
|
|
|
$strCopy = undef;
|
2017-06-12 16:52:32 +02:00
|
|
|
|
2017-06-27 21:58:02 +02:00
|
|
|
if ($strOS ne VM_CO6 && $strOS ne VM_U12)
|
2017-06-24 16:59:00 +02:00
|
|
|
{
|
|
|
|
$strImageParent = containerRepo() . ":${strOS}-base";
|
2018-07-21 23:02:42 +02:00
|
|
|
$strScript = "\n\nENTRYPOINT npm start --prefix /root/scalitys3";
|
2017-06-24 16:59:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-12 19:43:15 +02:00
|
|
|
$strImageParent = containerRepo() . ':' . CONTAINER_S3_SERVER_TAG;
|
2017-06-24 16:59:00 +02:00
|
|
|
}
|
2017-06-12 16:52:32 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
containerWrite(
|
|
|
|
$oStorageDocker, $strTempPath, $strOS, 'S3 Server', $strImageParent, $strImage, $strCopy, $strScript, $bVmForce);
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
# Test image
|
|
|
|
########################################################################################################################
|
|
|
|
if (!$bDeprecated)
|
2016-01-23 01:01:21 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${strOS}-base";
|
2017-06-24 16:59:00 +02:00
|
|
|
$strImage = "${strOS}-test";
|
2016-01-11 02:30:51 +02:00
|
|
|
|
2017-11-19 02:53:41 +02:00
|
|
|
if (vmCoverage($strOS))
|
2016-01-11 02:30:51 +02:00
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
$oStorageDocker->copy(
|
2017-11-19 02:53:41 +02:00
|
|
|
"test/package/${strOS}-${strPkgDevelCover}", "test/.vagrant/docker/${strOS}-${strPkgDevelCover}");
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
$strCopy =
|
|
|
|
"# Copy Devel::Cover\n" .
|
2017-11-19 02:53:41 +02:00
|
|
|
"COPY ${strOS}-${strPkgDevelCover} /tmp/${strPkgDevelCover}";
|
2016-06-12 15:00:16 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript = sectionHeader() .
|
2018-06-06 21:52:28 +02:00
|
|
|
"# Install packages\n" .
|
|
|
|
" apt-get install -y libjson-maybexs-perl";
|
|
|
|
|
|
|
|
$strScript .= sectionHeader() .
|
2017-06-24 16:59:00 +02:00
|
|
|
"# Install Devel::Cover\n" .
|
2017-11-19 02:53:41 +02:00
|
|
|
" dpkg -i /tmp/${strPkgDevelCover}";
|
2017-06-24 16:59:00 +02:00
|
|
|
}
|
|
|
|
else
|
2016-06-12 15:00:16 +02:00
|
|
|
{
|
2017-06-24 16:59:00 +02:00
|
|
|
$strCopy = undef;
|
|
|
|
$strScript = '';
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2018-07-21 23:02:42 +02:00
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Create banner to make sure pgBackRest ignores it\n" .
|
|
|
|
" echo '***********************************************' > /etc/issue.net && \\\n" .
|
|
|
|
" echo 'Sample banner to make sure banners are skipped.' >> /etc/issue.net && \\\n" .
|
|
|
|
" echo '' >> /etc/issue.net && \\\n" .
|
|
|
|
" echo 'More banner after a blank line.' >> /etc/issue.net && \\\n" .
|
|
|
|
" echo '***********************************************' >> /etc/issue.net && \\\n" .
|
|
|
|
" echo 'Banner /etc/issue.net' >> /etc/ssh/sshd_config";
|
|
|
|
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Create test user\n" .
|
|
|
|
' ' . groupCreate($strOS, TEST_GROUP, TEST_GROUP_ID) . " && \\\n" .
|
|
|
|
' ' . userCreate($strOS, TEST_USER, TEST_USER_ID, TEST_GROUP) . " && \\\n" .
|
|
|
|
' mkdir -m 750 /home/' . TEST_USER . "/test && \\\n" .
|
|
|
|
' chown ' . TEST_USER . ':' . TEST_GROUP . ' /home/' . TEST_USER . "/test";
|
|
|
|
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Configure sudo\n";
|
|
|
|
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
" echo '%" . TEST_GROUP . " ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/" . TEST_GROUP . " && \\\n" .
|
|
|
|
" sed -i 's/^Defaults requiretty\$/\\# Defaults requiretty/' /etc/sudoers";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
" echo '%" . TEST_GROUP . " ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers";
|
|
|
|
}
|
|
|
|
|
|
|
|
$strScript .=
|
|
|
|
sshSetup($strOS, TEST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
|
|
|
|
|
|
|
if (!$bDeprecated)
|
|
|
|
{
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Config AWS CLI\n" .
|
|
|
|
' sudo -i -u ' . TEST_USER . " aws configure set region us-east-1 && \\\n" .
|
|
|
|
' sudo -i -u ' . TEST_USER . " aws configure set aws_access_key_id accessKey1 && \\\n" .
|
|
|
|
' sudo -i -u ' . TEST_USER . " aws configure set aws_secret_access_key verySecretKey1";
|
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Create pgbackrest user\n" .
|
|
|
|
' ' . userCreate($strOS, BACKREST_USER, BACKREST_USER_ID, TEST_GROUP);
|
2016-06-12 15:00:16 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
$strScript .=
|
|
|
|
sshSetup($strOS, BACKREST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
|
|
|
|
|
|
|
$strScript .= sectionHeader() .
|
|
|
|
"# Make " . TEST_USER . " home dir readable\n" .
|
|
|
|
' chmod g+r,g+x /home/' . TEST_USER;
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-07-21 23:02:42 +02:00
|
|
|
$strScript .= entryPointSetup($strOS);
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
containerWrite(
|
2017-06-24 16:59:00 +02:00
|
|
|
$oStorageDocker, $strTempPath, $strOS, 'Test', $strImageParent, $strImage, $strCopy, $strScript, $bVmForce);
|
2016-01-23 01:01:21 +02:00
|
|
|
}
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
2017-06-24 16:59:00 +02:00
|
|
|
|
|
|
|
&log(INFO, "Build Complete");
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
push @EXPORT, qw(containerBuild);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# containerRemove
|
|
|
|
#
|
|
|
|
# Remove containers that match a regexp.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub containerRemove
|
|
|
|
{
|
|
|
|
my $strRegExp = shift;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
foreach my $strContainer (sort(split("\n", trim(executeTest('docker ps -a --format "{{.Names}}"')))))
|
|
|
|
{
|
|
|
|
if ($strContainer =~ $strRegExp)
|
|
|
|
{
|
|
|
|
executeTest("docker rm -f ${strContainer}", {bSuppressError => true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-10-01 19:39:44 +02:00
|
|
|
push @EXPORT, qw(containerRemove);
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# imageRemove
|
|
|
|
#
|
|
|
|
# Remove images that match a regexp.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub imageRemove
|
|
|
|
{
|
|
|
|
my $strRegExp = shift;
|
2016-01-23 01:01:21 +02:00
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
foreach my $strImage (sort(split("\n", trim(executeTest('docker images --format "{{.Repository}}:{{.Tag}}"')))))
|
2016-06-12 15:00:16 +02:00
|
|
|
{
|
|
|
|
if ($strImage =~ $strRegExp)
|
|
|
|
{
|
|
|
|
&log(INFO, "Removing ${strImage} image...");
|
2017-06-24 16:59:00 +02:00
|
|
|
executeTest("docker rmi -f ${strImage}");
|
2016-01-23 01:01:21 +02:00
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-09 15:21:53 +02:00
|
|
|
|
|
|
|
1;
|