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;
|
|
|
|
|
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
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
use constant BACKREST_USER => 'backrest';
|
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
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant LIB_COVER_VERSION => '1.23-2';
|
|
|
|
push @EXPORT, qw(LIB_COVER_VERSION);
|
|
|
|
use constant LIB_COVER_PACKAGE => 'libdevel-cover-perl_' . LIB_COVER_VERSION . '_amd64.deb';
|
|
|
|
push @EXPORT, qw(LIB_COVER_PACKAGE);
|
|
|
|
use constant LIB_COVER_EXE => '/usr/bin/cover';
|
|
|
|
push @EXPORT, qw(LIB_COVER_EXE);
|
|
|
|
|
2016-10-01 19:39:44 +02:00
|
|
|
####################################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
# Container repo
|
2016-10-01 19:39:44 +02:00
|
|
|
####################################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
sub containerRepo
|
2016-10-01 19:39:44 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
return BACKREST_EXE . qw(/) . 'test';
|
2016-10-01 19:39:44 +02:00
|
|
|
}
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
push @EXPORT, qw(containerRepo);
|
2016-10-01 19:39:44 +02:00
|
|
|
|
2015-12-29 20:57:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# User/group creation
|
|
|
|
####################################################################################################################################
|
|
|
|
sub groupCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
my $strName = shift;
|
|
|
|
my $iId = shift;
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
return "groupadd -g${iId} ${strName}";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
return "adduser -g${strGroup} -u${iId} -n ${strName}";
|
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
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
return "adduser --uid=${iId} --ingroup=${strGroup} --disabled-password --gecos \"\" ${strName}";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
confess &log(ERROR, "unable to create user for os '${strOS}'");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub postgresGroupCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
return "# Create PostgreSQL group\n" .
|
2017-02-21 15:59:23 +02:00
|
|
|
'RUN ' . groupCreate($strOS, POSTGRES_GROUP, POSTGRES_GROUP_ID);
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub postgresUserCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
return "# Create PostgreSQL user\n" .
|
2017-02-21 15:59:23 +02:00
|
|
|
'RUN ' . userCreate($strOS, POSTGRES_USER, POSTGRES_USER_ID, POSTGRES_GROUP);
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub backrestUserCreate
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
2017-02-21 15:59:23 +02:00
|
|
|
my $strGroup = shift;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
return "# Create BackRest group\n" .
|
2017-02-21 15:59:23 +02:00
|
|
|
'RUN ' . userCreate($strOS, BACKREST_USER, BACKREST_USER_ID, $strGroup);
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
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" .
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN touch /etc/pgbackrest.conf && \\\n" .
|
|
|
|
" chmod 640 /etc/pgbackrest.conf && \\\n" .
|
|
|
|
" 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
my $strTag = containerRepo() . ":${strImage}";
|
|
|
|
&log(INFO, "Building ${strTag} image...");
|
2016-06-12 15:00:16 +02:00
|
|
|
|
|
|
|
$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' : '') .
|
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
|
|
|
####################################################################################################################################
|
|
|
|
# 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" .
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN mkdir /home/${strUser}/.ssh && \\\n" .
|
|
|
|
" cp /root/.ssh/id_rsa /home/${strUser}/.ssh/id_rsa && \\\n" .
|
|
|
|
" cp /root/.ssh/authorized_keys /home/${strUser}/.ssh/authorized_keys && \\\n" .
|
|
|
|
" cp /root/.ssh/config /home/${strUser}/.ssh/config && \\\n";
|
2016-07-30 14:43:38 +02:00
|
|
|
|
|
|
|
if ($bControlMaster)
|
|
|
|
{
|
|
|
|
$strScript .=
|
2017-02-21 15:59:23 +02:00
|
|
|
" echo ' ControlMaster auto' >> /home/${strUser}/.ssh/config && \\\n" .
|
|
|
|
" echo ' ControlPath /tmp/\%r\@\%h:\%p' >> /home/${strUser}/.ssh/config && \\\n" .
|
|
|
|
" echo ' ControlPersist 30' >> /home/${strUser}/.ssh/config && \\\n";
|
2016-07-30 14:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$strScript .=
|
2017-02-21 15:59:23 +02:00
|
|
|
" chown -R ${strUser}:${strGroup} /home/${strUser}/.ssh && \\\n" .
|
|
|
|
" chmod 700 /home/${strUser}/.ssh && \\\n" .
|
|
|
|
" 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" .
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN mkdir /var/lib/pgbackrest && \\\n" .
|
|
|
|
" chown -R ${strUser}:${strGroup} /var/lib/pgbackrest && \\\n" .
|
|
|
|
" 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 .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"\nRUN yum -y install sudo && \\" .
|
|
|
|
"\n echo '%${strGroup} ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/${strGroup} && \\" .
|
|
|
|
"\n sed -i 's/^Defaults requiretty\$/\\# Defaults requiretty/' /etc/sudoers";
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
elsif ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
|
|
|
$strScript .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"\nRUN apt-get -y install sudo && \\\n" .
|
|
|
|
"\n echo '%${strGroup} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers";
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "unable to find base for ${strOS}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $strScript;
|
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Devel::Cover setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub coverSetup
|
|
|
|
{
|
|
|
|
my $strOS = shift;
|
|
|
|
|
|
|
|
my $strScript = '';
|
|
|
|
my $oVm = vmGet();
|
|
|
|
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
|
|
|
$strScript .=
|
|
|
|
"\n\n# Install Devel::Cover\n" .
|
|
|
|
"COPY ${strOS}-" . LIB_COVER_PACKAGE . ' /tmp/' . LIB_COVER_PACKAGE . "\n" .
|
|
|
|
'RUN dpkg -i /tmp/' . LIB_COVER_PACKAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
$strImage .=
|
2017-01-27 16:42:30 +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
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
$strImage .=
|
2017-01-27 16:42:30 +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
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
$strImage .=
|
|
|
|
'RUN apt-get install -y libdbd-pg-perl libdbi-perl libnet-daemon-perl libplrpc-perl libhtml-parser-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)
|
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
$strImage .=
|
|
|
|
'RUN apt-get install -y libdbd-pg-perl libdbi-perl libhtml-parser-perl';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "unable to install perl for os '${strOS}'");
|
2016-05-24 14:17:13 +02:00
|
|
|
}
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
return $strImage;
|
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)
|
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
my $strRegExp = '^' . containerRepo();
|
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 .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN apt-get update && \\\n" .
|
|
|
|
" apt-get -y install openssh-server wget\n";
|
2017-02-17 00:18:48 +02:00
|
|
|
|
|
|
|
$strScript .=
|
|
|
|
"\n# Fix root tty\n" .
|
|
|
|
"RUN sed -i 's/^mesg n/tty -s \\&\\& mesg n/g' /root/.profile\n";
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
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 .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.0/redhat/rhel-6-x86_64/pgdg-centos90-9.0-5.noarch.rpm && \\\n" .
|
|
|
|
" rpm -ivh http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-6.noarch.rpm && \\\n" .
|
|
|
|
" rpm -ivh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-8.noarch.rpm && \\\n" .
|
|
|
|
" rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-3.noarch.rpm && \\\n" .
|
|
|
|
" rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-3.noarch.rpm && \\\n" .
|
|
|
|
" rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm && \\\n" .
|
|
|
|
" 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 .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-3.noarch.rpm && \\\n" .
|
|
|
|
" rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm && \\\n" .
|
|
|
|
" rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm && \\\n" .
|
|
|
|
" 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/ " .
|
2017-02-21 15:59:23 +02:00
|
|
|
$$oVm{$strOS}{&VM_OS_REPO} . "-pgdg main' >> /etc/apt/sources.list.d/pgdg.list && \\\n" .
|
|
|
|
" wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \\\n" .
|
|
|
|
" apt-get update";
|
2015-12-29 20:57:10 +02:00
|
|
|
}
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
$strScript .=
|
|
|
|
"\n\n# Regenerate SSH keys\n" .
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN rm -f /etc/ssh/ssh_host_rsa_key* && \\\n" .
|
|
|
|
" 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" .
|
2017-02-21 15:59:23 +02:00
|
|
|
"RUN 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";
|
|
|
|
|
|
|
|
# Copy ssh keys
|
|
|
|
$strScript .=
|
|
|
|
"\n\n# Copy ssh keys to root\n" .
|
|
|
|
"RUN mkdir -m 700 -p /root/.ssh\n" .
|
|
|
|
"COPY id_rsa /root/.ssh/id_rsa\n" .
|
|
|
|
"COPY id_rsa.pub /root/.ssh/authorized_keys\n" .
|
|
|
|
"RUN echo 'Host *' > /root/.ssh/config && \\\n" .
|
|
|
|
" echo ' StrictHostKeyChecking no' >> /root/.ssh/config && \\\n" .
|
|
|
|
" chmod 600 /root/.ssh/*";
|
2016-07-26 22:28:43 +02:00
|
|
|
|
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" .
|
2017-02-21 15:59:23 +02:00
|
|
|
'RUN ' . 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';
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
###########################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${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
|
|
|
|
2016-12-13 01:54:07 +02:00
|
|
|
# Build image
|
|
|
|
###########################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${strOS}-base-pre";
|
2016-12-13 01:54:07 +02:00
|
|
|
$strImage = "${strOS}-build";
|
|
|
|
|
|
|
|
# Install Perl packages
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
|
|
|
$strScript =
|
2017-02-18 05:31:16 +02:00
|
|
|
"# Install package build tools and package source\n" .
|
2017-04-10 18:31:30 +02:00
|
|
|
"RUN apt-get install -y devscripts build-essential lintian git libxml-checker-perl txt2man debhelper" .
|
|
|
|
" libpod-coverage-perl libppi-html-perl libtemplate-perl libtest-differences-perl && \\\n" .
|
|
|
|
" git clone https://anonscm.debian.org/git/pkg-postgresql/pgbackrest.git /root/package-src && \\\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 && git checkout debian/' . LIB_COVER_VERSION . ' && debuild -i -us -uc -b';
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strScript =
|
2017-02-21 15:59:23 +02:00
|
|
|
"# Install package build tools and package source\n" .
|
2017-02-18 05:31:16 +02:00
|
|
|
"RUN yum install -y gcc make perl-ExtUtils-MakeMaker perl-Test-Simple git\n";
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Write the image
|
|
|
|
containerWrite($strTempPath, $strOS, 'Build', $strImageParent, $strImage, $strScript, $bVmForce, false);
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
# Copy Devel::Cover to host so it can be installed in other containers
|
|
|
|
if ($$oVm{$strOS}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
|
|
|
{
|
|
|
|
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 " .
|
|
|
|
"bash -c 'cp /root/" . LIB_COVER_PACKAGE . " ${strTempPath}/${strOS}-" . LIB_COVER_PACKAGE . "'");
|
|
|
|
executeTest('docker rm -f test-build');
|
|
|
|
}
|
|
|
|
|
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}});
|
|
|
|
}
|
2017-02-21 15:59:23 +02:00
|
|
|
elsif ($strDbVersionBuild ne 'none')
|
2016-06-12 15:00:16 +02:00
|
|
|
{
|
|
|
|
push(@stryDbBuild, $strDbVersionBuild);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Merge db versions required for docs
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($strDbVersionBuild eq 'all' || $strDbVersionBuild eq 'minimal')
|
2016-06-12 15:00:16 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
if (defined($$oOS{&VM_DB_DOC}))
|
|
|
|
{
|
|
|
|
@stryDbBuild = keys %{{map {($_ => 1)} ## no critic (BuiltinFunctions::ProhibitVoidMap)
|
|
|
|
(@stryDbBuild, @{$$oOS{&VM_DB_DOC}})}};
|
|
|
|
$bDocBuild = true;
|
|
|
|
}
|
2016-06-12 15:00:16 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${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 .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"\nRUN apt-get install -y postgresql-${strDbVersion} && \\" .
|
|
|
|
"\n 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)
|
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${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
|
|
|
|
########################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${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
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
# Setup Devel::Cover
|
|
|
|
$strScript .= coverSetup($strOS);
|
|
|
|
|
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
|
|
|
|
2017-01-05 22:19:56 +02:00
|
|
|
# Db test image (for synthetic tests)
|
2016-06-12 15:00:16 +02:00
|
|
|
########################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${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
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
# Setup Devel::Cover
|
|
|
|
$strScript .= coverSetup($strOS);
|
|
|
|
|
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
|
|
|
|
########################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-loop-test";
|
|
|
|
|
|
|
|
# Create BackRest User
|
2017-02-21 15:59:23 +02:00
|
|
|
$strScript = backrestUserCreate($strOS, TEST_GROUP);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Install SSH key
|
|
|
|
$strScript .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"\n\n" . sshSetup($strOS, BACKREST_USER, TEST_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
|
|
|
|
2017-01-05 22:19:56 +02:00
|
|
|
# Setup sudo
|
|
|
|
$strScript .= "\n\n" . sudoSetup($strOS, TEST_GROUP);
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
# Setup Devel::Cover
|
|
|
|
$strScript .= coverSetup($strOS);
|
|
|
|
|
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-06-12 15:00:16 +02:00
|
|
|
my $strTitle = "Backup";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
|
|
|
# Backup Doc image
|
|
|
|
###########################################################################################################################
|
2016-06-12 15:00:16 +02:00
|
|
|
if ($bDocBuild)
|
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-backup-doc";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
# Create BackRest User
|
|
|
|
$strScript = backrestUserCreate($strOS, POSTGRES_GROUP);
|
|
|
|
|
|
|
|
# Install SSH key
|
|
|
|
$strScript .=
|
|
|
|
"\n\n" . sshSetup($strOS, BACKREST_USER, POSTGRES_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Create configuration file
|
2017-02-21 15:59:23 +02:00
|
|
|
$strScript .=
|
|
|
|
"\n\n" . backrestConfigCreate($strOS, BACKREST_USER, POSTGRES_GROUP);
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Setup repository
|
|
|
|
$strScript .=
|
2017-02-21 15:59:23 +02:00
|
|
|
"\n\n" . repoSetup($strOS, BACKREST_USER, POSTGRES_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
|
|
|
###########################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
$strImageParent = containerRepo() . ":${strOS}-base";
|
2016-06-12 15:00:16 +02:00
|
|
|
$strImage = "${strOS}-backup-test";
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
# Create BackRest User
|
|
|
|
$strScript = backrestUserCreate($strOS, TEST_GROUP);
|
|
|
|
|
|
|
|
# Install SSH key
|
|
|
|
$strScript .=
|
|
|
|
"\n\n" . sshSetup($strOS, BACKREST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
|
|
|
|
|
2016-06-12 15:00:16 +02:00
|
|
|
# Make test user home readable
|
2017-02-21 15:59:23 +02:00
|
|
|
$strScript .=
|
|
|
|
"\n\n# Make " . TEST_USER . " home dir readable\n" .
|
2016-06-12 15:00:16 +02:00
|
|
|
'RUN chmod g+r,g+x /home/' . TEST_USER;
|
2015-12-29 20:57:10 +02:00
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
# Setup Devel::Cover
|
|
|
|
$strScript .= coverSetup($strOS);
|
|
|
|
|
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;
|