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);
|
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-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::FileCommon;
|
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);
|
2016-09-06 20:01:39 +02:00
|
|
|
use constant POSTGRES_GROUP_ID => getgrnam(POSTGRES_GROUP) . '';
|
2015-12-29 20:57:10 +02:00
|
|
|
use constant POSTGRES_USER => POSTGRES_GROUP;
|
|
|
|
use constant POSTGRES_USER_ID => POSTGRES_GROUP_ID;
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
use constant TEST_GROUP => POSTGRES_GROUP;
|
2016-12-04 00:34:51 +02:00
|
|
|
push @EXPORT, qw(TEST_GROUP);
|
2016-06-12 15:00:16 +02:00
|
|
|
use constant TEST_GROUP_ID => POSTGRES_GROUP_ID;
|
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
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
use constant BACKREST_GROUP => POSTGRES_GROUP;
|
|
|
|
use constant BACKREST_GROUP_ID => POSTGRES_GROUP_ID;
|
|
|
|
use constant BACKREST_USER => 'backrest';
|
2016-09-06 20:01:39 +02:00
|
|
|
use constant BACKREST_USER_ID => getpwnam(BACKREST_USER) . '';
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-10-01 19:39:44 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Container namespace
|
|
|
|
####################################################################################################################################
|
|
|
|
sub containerNamespace
|
|
|
|
{
|
|
|
|
return BACKREST_EXE . qw(/) . TEST_USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(containerNamespace);
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# User/group creation
|
|
|
|
####################################################################################################################################
|
|
|
|
sub groupCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
my $strName = shift;
|
|
|
|
my $iId = shift;
|
|
|
|
|
|
|
|
return "RUN groupadd -g${iId} ${strName}";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub userCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
my $strName = shift;
|
|
|
|
my $iId = shift;
|
|
|
|
my $strGroup = shift;
|
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
my $oVm = vmGet();
|
|
|
|
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
|
|
|
return "RUN adduser -g${strGroup} -u${iId} -n ${strName}";
|
|
|
|
}
|
2016-05-24 14:17:13 +02:00
|
|
|
elsif ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
|
|
|
return "RUN adduser --uid=${iId} --ingroup=${strGroup} --disabled-password --gecos \"\" ${strName}";
|
|
|
|
}
|
|
|
|
|
|
|
|
confess &log(ERROR, "unable to create user for os '${strOS}'");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub postgresGroupCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
return "# Create PostgreSQL group\n" .
|
|
|
|
groupCreate($strOS, POSTGRES_GROUP, POSTGRES_GROUP_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub postgresUserCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
return "# Create PostgreSQL user\n" .
|
|
|
|
userCreate($strOS, POSTGRES_USER, POSTGRES_USER_ID, POSTGRES_GROUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub backrestUserCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
return "# Create BackRest group\n" .
|
|
|
|
userCreate($strOS, BACKREST_USER, BACKREST_USER_ID, BACKREST_GROUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2016-04-14 15:30:54 +02:00
|
|
|
# Create configuration file
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
sub backrestConfigCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
my $strUser = shift;
|
|
|
|
my $strGroup = shift;
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
return "# Create pgbackrest.conf\n" .
|
|
|
|
"RUN touch /etc/pgbackrest.conf\n" .
|
|
|
|
"RUN chmod 640 /etc/pgbackrest.conf\n" .
|
|
|
|
"RUN chown ${strUser}:${strGroup} /etc/pgbackrest.conf";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 00:47:29 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Write the Docker container
|
|
|
|
####################################################################################################################################
|
|
|
|
sub containerWrite
|
|
|
|
{
|
|
|
|
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;
|
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
|
|
|
my $bPre = shift;
|
|
|
|
my $bPreOnly = shift;
|
|
|
|
|
|
|
|
if (defined($bPre) && $bPre)
|
|
|
|
{
|
|
|
|
$strImage .= '-pre';
|
|
|
|
$strImageParent .= '-pre';
|
|
|
|
$strTitle .= ' (Pre-Installed)'
|
|
|
|
}
|
|
|
|
elsif (!defined($bPre))
|
|
|
|
{
|
|
|
|
containerWrite($strTempPath, $strOS, $strTitle, $strImageParent, $strImage, $strScript, $bForce, true);
|
|
|
|
|
|
|
|
if (defined($bPreOnly) && $bPreOnly)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, "Building ${strImage} image...");
|
|
|
|
|
|
|
|
$strScript =
|
|
|
|
"# ${strTitle} Container\n" .
|
|
|
|
"FROM ${strImageParent}\n\n" .
|
|
|
|
$strScript;
|
2016-04-14 00:47:29 +02:00
|
|
|
|
|
|
|
# Write the image
|
2016-06-12 15:00:16 +02:00
|
|
|
fileStringWrite("${strTempPath}/${strImage}", trim($strScript) . "\n", false);
|
2016-04-14 00:47:29 +02:00
|
|
|
executeTest('docker build' . (defined($bForce) && $bForce ? ' --no-cache' : '') .
|
2016-10-01 19:39:44 +02:00
|
|
|
" -f ${strTempPath}/${strImage} -t " . containerNamespace() . "/${strImage} ${strTempPath}",
|
2016-04-14 00:47:29 +02:00
|
|
|
{bSuppressStdErr => true});
|
|
|
|
}
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Setup SSH
|
|
|
|
####################################################################################################################################
|
|
|
|
sub sshSetup
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
my $strUser = shift;
|
|
|
|
my $strGroup = shift;
|
2016-07-30 14:43:38 +02:00
|
|
|
my $bControlMaster = shift;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-07-30 14:43:38 +02:00
|
|
|
my $strScript =
|
2016-04-14 00:47:29 +02:00
|
|
|
"# Setup SSH\n" .
|
|
|
|
"RUN mkdir /home/${strUser}/.ssh\n" .
|
|
|
|
"COPY id_rsa /home/${strUser}/.ssh/id_rsa\n" .
|
|
|
|
"COPY id_rsa.pub /home/${strUser}/.ssh/authorized_keys\n" .
|
|
|
|
"RUN echo 'Host *' > /home/${strUser}/.ssh/config\n" .
|
2016-07-30 14:43:38 +02:00
|
|
|
"RUN echo ' StrictHostKeyChecking no' >> /home/${strUser}/.ssh/config\n";
|
|
|
|
|
|
|
|
if ($bControlMaster)
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
"RUN echo ' ControlMaster auto' >> /home/${strUser}/.ssh/config\n" .
|
|
|
|
"RUN echo ' ControlPath /tmp/\%r\@\%h:\%p' >> /home/${strUser}/.ssh/config\n" .
|
|
|
|
"RUN echo ' ControlPersist 30' >> /home/${strUser}/.ssh/config\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$strScript .=
|
2016-06-12 15:00:16 +02:00
|
|
|
"RUN chown -R ${strUser}:${strGroup} /home/${strUser}/.ssh\n" .
|
|
|
|
"RUN chmod 700 /home/${strUser}/.ssh\n" .
|
|
|
|
"RUN chmod 600 /home/${strUser}/.ssh/*";
|
2016-07-30 14:43:38 +02:00
|
|
|
|
|
|
|
return $strScript;
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2016-06-12 15:00:16 +02:00
|
|
|
# Repo setup
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
sub repoSetup
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
my $strUser = shift;
|
|
|
|
my $strGroup = shift;
|
|
|
|
|
|
|
|
return "# Setup repository\n" .
|
2016-04-14 15:30:54 +02:00
|
|
|
"RUN mkdir /var/lib/pgbackrest\n" .
|
|
|
|
"RUN chown -R ${strUser}:${strGroup} /var/lib/pgbackrest\n" .
|
|
|
|
"RUN chmod 750 /var/lib/pgbackrest";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Sudo setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub sudoSetup
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
my $strGroup = shift;
|
|
|
|
|
|
|
|
my $strScript =
|
|
|
|
"# Setup sudo";
|
|
|
|
|
|
|
|
my $oVm = vmGet();
|
|
|
|
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
"\nRUN yum -y install sudo\n" .
|
|
|
|
"\nRUN echo '%${strGroup} ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/${strGroup}" .
|
|
|
|
"\nRUN sed -i 's/^Defaults requiretty\$/\\# Defaults requiretty/' /etc/sudoers";
|
|
|
|
}
|
|
|
|
elsif ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
"\nRUN sed -i 's/^\\\%admin.*\$/\\\%${strGroup} ALL\\=\\(ALL\\) NOPASSWD\\: ALL/' /etc/sudoers";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "unable to find base for ${strOS}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $strScript;
|
|
|
|
}
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Install Perl packages
|
|
|
|
####################################################################################################################################
|
|
|
|
sub perlInstall
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
my $strImage =
|
|
|
|
"# Install Perl packages\n";
|
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
if ($strOS eq VM_CO6)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-05-24 14:17:13 +02:00
|
|
|
return $strImage .
|
2016-06-12 15:00:16 +02:00
|
|
|
"RUN yum install -y perl perl-Time-HiRes perl-parent perl-JSON perl-Digest-SHA perl-DBD-Pg";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2016-05-24 14:17:13 +02:00
|
|
|
elsif ($strOS eq VM_CO7)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-05-24 14:17:13 +02:00
|
|
|
return $strImage .
|
2016-09-06 15:35:02 +02:00
|
|
|
"RUN yum install -y perl perl-JSON-PP perl-Digest-SHA perl-DBD-Pg";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2016-05-24 14:17:13 +02:00
|
|
|
elsif ($strOS eq VM_U12 || $strOS eq VM_U14)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-05-24 14:17:13 +02:00
|
|
|
return $strImage .
|
2016-06-12 15:00:16 +02:00
|
|
|
"RUN apt-get install -y libdbd-pg-perl libdbi-perl libnet-daemon-perl libplrpc-perl";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2016-05-24 14:17:13 +02:00
|
|
|
elsif ($strOS eq VM_U16 || $strOS eq VM_D8)
|
|
|
|
{
|
|
|
|
return $strImage .
|
2016-06-12 15:00:16 +02:00
|
|
|
"RUN apt-get install -y libdbd-pg-perl libdbi-perl";
|
2016-05-24 14:17:13 +02:00
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
confess &log(ERROR, "unable to install perl for os '${strOS}'");
|
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
|
|
|
{
|
2016-04-14 00:47:29 +02:00
|
|
|
my $strVm = shift;
|
|
|
|
my $bVmForce = shift;
|
2016-06-12 15:00:16 +02:00
|
|
|
my $strDbVersionBuild = shift;
|
2016-04-14 00:47:29 +02:00
|
|
|
|
2016-01-09 15:21:53 +02:00
|
|
|
# Create temp path
|
|
|
|
my $strTempPath = dirname(abs_path($0)) . '/.vagrant/docker';
|
2016-06-02 15:32:56 +02:00
|
|
|
filePathCreate($strTempPath, '0770', true, true);
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Remove old images on force
|
|
|
|
if ($bVmForce)
|
|
|
|
{
|
2016-10-01 19:39:44 +02:00
|
|
|
my $strRegExp = '^' . containerNamespace() . '/';
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
if ($strVm ne 'all')
|
|
|
|
{
|
|
|
|
$strRegExp .= "${strVm}-";
|
|
|
|
}
|
|
|
|
|
|
|
|
executeTest("rm -f ${strTempPath}/" . ($strVm eq 'all' ? '*' : "${strVm}-*"));
|
|
|
|
imageRemove("${strRegExp}.*");
|
|
|
|
}
|
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
# Create SSH key (if it does not already exist)
|
|
|
|
if (-e "${strTempPath}/id_rsa")
|
|
|
|
{
|
|
|
|
&log(INFO, "SSH key already exists");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&log(INFO, "Building SSH keys...");
|
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
executeTest("ssh-keygen -f ${strTempPath}/id_rsa -t rsa -b 1024 -N ''", {bSuppressStdErr => true});
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
my $oVm = vmGet();
|
2016-01-11 02:30:51 +02:00
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
foreach my $strOS (sort(keys(%$oVm)))
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-04-14 00:47:29 +02:00
|
|
|
if ($strVm ne 'all' && $strVm ne $strOS)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2016-05-24 14:17:13 +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
|
|
|
|
|
|
|
# Base image
|
|
|
|
###########################################################################################################################
|
2016-06-12 15:00:16 +02:00
|
|
|
my $strImageParent = "$$oVm{$strOS}{&VM_IMAGE}";
|
|
|
|
my $strImage = "${strOS}-base";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Install base packages
|
2016-06-13 17:18:06 +02:00
|
|
|
my $strScript = "# 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 .= "RUN yum -y install openssh-server openssh-clients\n";
|
|
|
|
}
|
|
|
|
elsif ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
"RUN apt-get update\n" .
|
|
|
|
"RUN apt-get -y install openssh-server wget\n";
|
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Add PostgreSQL packages
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .= "\n# Add PostgreSQL packages\n";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
if ($strOS eq VM_CO6)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2015-12-29 20:57:10 +02:00
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.0/redhat/rhel-6-x86_64/pgdg-centos90-9.0-5.noarch.rpm\n" .
|
2016-09-30 01:07:46 +02:00
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-6.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-8.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-3.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-3.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2016-05-24 14:17:13 +02:00
|
|
|
elsif ($strOS eq VM_CO7)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-09-30 01:07:46 +02:00
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-3.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm\n" .
|
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2016-05-24 14:17:13 +02:00
|
|
|
elsif ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2015-12-29 20:57:10 +02:00
|
|
|
"RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ " .
|
2016-09-30 01:07:46 +02:00
|
|
|
$$oVm{$strOS}{&VM_OS_REPO} . "-pgdg main' >> /etc/apt/sources.list.d/pgdg.list\n" .
|
2015-12-29 20:57:10 +02:00
|
|
|
"RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -\n" .
|
|
|
|
"RUN apt-get update";
|
|
|
|
}
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
|
|
|
"\n\n# Regenerate SSH keys\n" .
|
|
|
|
"RUN rm -f /etc/ssh/ssh_host_rsa_key*\n" .
|
|
|
|
"RUN ssh-keygen -t rsa -b 1024 -f /etc/ssh/ssh_host_rsa_key";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-07-26 22:28:43 +02:00
|
|
|
$strScript .=
|
|
|
|
"\n\n# Add banner to make sure protocol ignores it\n" .
|
|
|
|
"RUN echo '***********************************************' > /etc/issue.net\n" .
|
|
|
|
"RUN echo 'Sample banner to make sure banners are skipped.' >> /etc/issue.net\n" .
|
|
|
|
"RUN echo '' >> /etc/issue.net\n" .
|
|
|
|
"RUN echo 'More banner after a blank line.' >> /etc/issue.net\n" .
|
|
|
|
"RUN echo '***********************************************' >> /etc/issue.net\n" .
|
|
|
|
"RUN echo 'Banner /etc/issue.net' >> /etc/ssh/sshd_config";
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Create PostgreSQL Group
|
|
|
|
$strScript .= "\n\n" . postgresGroupCreate($strOS);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Create test user
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2015-12-29 20:57:10 +02:00
|
|
|
"\n\n# Create test user\n" .
|
|
|
|
userCreate($strOS, TEST_USER, TEST_USER_ID, TEST_GROUP);
|
|
|
|
|
|
|
|
# Suppress dpkg interactive output
|
2016-05-24 14:17:13 +02:00
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2015-12-29 20:57:10 +02:00
|
|
|
"\n\n# Suppress dpkg interactive output\n" .
|
|
|
|
"RUN rm /etc/apt/apt.conf.d/70debconf";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start SSH when container starts
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2015-12-29 20:57:10 +02:00
|
|
|
"\n\n# Start SSH when container starts\n";
|
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
# This is required in newer versions of u12 containers - seems like a bug in the container
|
|
|
|
if ($strOS eq VM_U12)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-04-14 00:47:29 +02:00
|
|
|
"RUN mkdir /var/run/sshd\n";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2016-04-14 00:47:29 +02:00
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
if ($strOS eq VM_U14 || $strOS eq VM_D8 || $strOS eq VM_U16)
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-04-14 00:47:29 +02:00
|
|
|
"ENTRYPOINT service ssh restart && bash";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
2016-04-14 00:47:29 +02:00
|
|
|
else
|
2015-12-29 20:57:10 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-04-14 00:47:29 +02:00
|
|
|
"ENTRYPOINT /usr/sbin/sshd -D";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Write the image
|
2016-06-12 15:00:16 +02:00
|
|
|
containerWrite($strTempPath, $strOS, 'Base', $strImageParent, $strImage, $strScript, $bVmForce, false);
|
|
|
|
|
|
|
|
# Base pre image
|
|
|
|
###########################################################################################################################
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-base-pre";
|
|
|
|
|
|
|
|
# Install Perl packages
|
|
|
|
$strScript =
|
|
|
|
perlInstall($strOS) . "\n";
|
|
|
|
|
|
|
|
# Write the image
|
|
|
|
containerWrite($strTempPath, $strOS, 'Base (Pre-Installed)', $strImageParent, $strImage, $strScript, $bVmForce, false);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Db image
|
|
|
|
###########################################################################################################################
|
2016-06-12 15:00:16 +02:00
|
|
|
my @stryDbBuild;
|
|
|
|
|
|
|
|
# Get the list of db versions required for testing
|
|
|
|
if ($strDbVersionBuild eq 'all')
|
|
|
|
{
|
|
|
|
push(@stryDbBuild, @{$$oOS{&VM_DB}});
|
|
|
|
}
|
|
|
|
elsif ($strDbVersionBuild eq 'minimal')
|
|
|
|
{
|
|
|
|
push(@stryDbBuild, @{$$oOS{&VM_DB_MINIMAL}});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push(@stryDbBuild, $strDbVersionBuild);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Merge db versions required for docs
|
|
|
|
if (defined($$oOS{&VM_DB_DOC}))
|
|
|
|
{
|
|
|
|
@stryDbBuild = keys %{{map {($_ => 1)} ## no critic (BuiltinFunctions::ProhibitVoidMap)
|
|
|
|
(@stryDbBuild, @{$$oOS{&VM_DB_DOC}})}};
|
|
|
|
$bDocBuild = true;
|
|
|
|
}
|
|
|
|
|
2016-07-02 15:07:48 +02:00
|
|
|
foreach my $strDbVersion (sort(@stryDbBuild))
|
2016-01-23 01:01:21 +02:00
|
|
|
{
|
|
|
|
my $strDbVersionNoDot = $strDbVersion;
|
|
|
|
$strDbVersionNoDot =~ s/\.//;
|
2016-06-12 15:00:16 +02:00
|
|
|
my $strTitle = "Db ${strDbVersion}";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
my $bDocBuildVersion = ($bDocBuild && grep(/^$strDbVersion$/, @{$$oOS{&VM_DB_DOC}}));
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-db-${strDbVersion}";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-01-23 01:01:21 +02:00
|
|
|
# Create PostgreSQL User
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript = postgresUserCreate($strOS);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-01-23 01:01:21 +02:00
|
|
|
# Install PostgreSQL
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-01-23 01:01:21 +02:00
|
|
|
"\n\n# Install PostgreSQL";
|
2016-01-11 02:30:51 +02:00
|
|
|
|
2016-05-24 14:17:13 +02:00
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
2016-01-11 02:30:51 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-01-23 01:01:21 +02:00
|
|
|
"\nRUN apt-get install -y postgresql-${strDbVersion}" .
|
|
|
|
"\nRUN pg_dropcluster --stop ${strDbVersion} main";
|
2016-01-11 02:30:51 +02:00
|
|
|
}
|
2016-05-24 14:17:13 +02:00
|
|
|
elsif ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
2016-01-11 02:30:51 +02:00
|
|
|
{
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-01-23 01:01:21 +02:00
|
|
|
"\nRUN yum -y install postgresql${strDbVersionNoDot}-server";
|
2016-01-11 02:30:51 +02:00
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-01-23 01:01:21 +02:00
|
|
|
# Write the image
|
2016-06-12 15:00:16 +02:00
|
|
|
containerWrite($strTempPath, $strOS, $strTitle, $strImageParent, $strImage, $strScript, $bVmForce,
|
|
|
|
$bDocBuildVersion ? undef : true, $bDocBuildVersion ? undef : true);
|
|
|
|
|
|
|
|
# Db doc image
|
|
|
|
########################################################################################################################
|
|
|
|
if ($bDocBuildVersion)
|
|
|
|
{
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-db-${strDbVersion}";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-db-${strDbVersion}-doc";
|
|
|
|
|
|
|
|
# Install SSH key
|
2016-07-30 14:43:38 +02:00
|
|
|
$strScript = sshSetup($strOS, POSTGRES_USER, POSTGRES_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
# Setup sudo
|
|
|
|
$strScript .= "\n\n" . sudoSetup($strOS, TEST_GROUP);
|
|
|
|
|
|
|
|
# Write the image
|
|
|
|
containerWrite($strTempPath, $strOS, "${strTitle} Doc", $strImageParent, $strImage, $strScript, $bVmForce);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Db test image
|
|
|
|
########################################################################################################################
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-db-${strDbVersion}";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-db-${strDbVersion}-test";
|
|
|
|
|
|
|
|
# Install SSH key
|
2016-07-30 14:43:38 +02:00
|
|
|
$strScript = sshSetup($strOS, TEST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
# Write the image
|
|
|
|
containerWrite($strTempPath, $strOS, "${strTitle} Test", $strImageParent, $strImage, $strScript, $bVmForce, true, true);
|
2016-01-23 01:01:21 +02:00
|
|
|
}
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Db test image (for sythetic tests)
|
|
|
|
########################################################################################################################
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-db-test";
|
|
|
|
|
|
|
|
# Install SSH key
|
2016-07-30 14:43:38 +02:00
|
|
|
$strScript = sshSetup($strOS, TEST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
# Write the image
|
|
|
|
containerWrite($strTempPath, $strOS, 'Db Synthetic Test', $strImageParent, $strImage, $strScript, $bVmForce, true, true);
|
|
|
|
|
|
|
|
# Loop test image
|
|
|
|
########################################################################################################################
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-loop-test";
|
|
|
|
|
|
|
|
# Create BackRest User
|
|
|
|
$strScript = backrestUserCreate($strOS);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Install SSH key
|
|
|
|
$strScript .=
|
2016-07-30 14:43:38 +02:00
|
|
|
"\n\n" . sshSetup($strOS, BACKREST_USER, BACKREST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
# Install SSH key
|
|
|
|
$strScript .=
|
2016-07-30 14:43:38 +02:00
|
|
|
"\n\n" . sshSetup($strOS, TEST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Make test user home readable
|
|
|
|
$strScript .=
|
|
|
|
"\n\n# Make " . TEST_USER . " home dir readable\n" .
|
|
|
|
'RUN chmod g+r,g+x /home/' . TEST_USER;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Write the image
|
2016-06-12 15:00:16 +02:00
|
|
|
containerWrite($strTempPath, $strOS, 'Loop Test', $strImageParent, $strImage, $strScript, $bVmForce, true, true);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Backup image
|
|
|
|
###########################################################################################################################
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-backup";
|
|
|
|
my $strTitle = "Backup";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Create BackRest User
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript = backrestUserCreate($strOS);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Install SSH key
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
2016-07-30 14:43:38 +02:00
|
|
|
"\n\n" . sshSetup($strOS, BACKREST_USER, BACKREST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Write the image
|
2016-06-12 15:00:16 +02:00
|
|
|
containerWrite($strTempPath, $strOS, $strTitle, $strImageParent, $strImage, $strScript, $bVmForce,
|
|
|
|
$bDocBuild ? undef : true, $bDocBuild ? undef : true);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Backup Doc image
|
|
|
|
###########################################################################################################################
|
2016-06-12 15:00:16 +02:00
|
|
|
if ($bDocBuild)
|
|
|
|
{
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-backup";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-backup-doc";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Create configuration file
|
|
|
|
$strScript = backrestConfigCreate($strOS, BACKREST_USER, BACKREST_GROUP);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Setup repository
|
|
|
|
$strScript .=
|
|
|
|
"\n\n" . repoSetup($strOS, BACKREST_USER, BACKREST_GROUP);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Setup sudo
|
|
|
|
$strScript .= "\n\n" . sudoSetup($strOS, TEST_GROUP);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Write the image
|
|
|
|
containerWrite($strTempPath, $strOS, "${strTitle} Doc", $strImageParent, $strImage, $strScript, $bVmForce, true, true);
|
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Backup Test image
|
2015-12-29 20:57:10 +02:00
|
|
|
###########################################################################################################################
|
2016-10-01 19:39:44 +02:00
|
|
|
$strImageParent = containerNamespace() . "/${strOS}-backup";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-backup-test";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Make test user home readable
|
|
|
|
$strScript =
|
|
|
|
"# Make " . TEST_USER . " home dir readable\n" .
|
|
|
|
'RUN chmod g+r,g+x /home/' . TEST_USER;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Write the image
|
|
|
|
containerWrite($strTempPath, $strOS, "${strTitle} Test", $strImageParent, $strImage, $strScript, $bVmForce, true, true);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
foreach my $strImage (sort(split("\n", trim(executeTest('docker images --format "{{.Repository}}"')))))
|
|
|
|
{
|
|
|
|
if ($strImage =~ $strRegExp)
|
|
|
|
{
|
|
|
|
&log(INFO, "Removing ${strImage} image...");
|
|
|
|
executeTest("docker rmi -f ${strImage}", {bSuppressError => true});
|
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;
|