1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Refactor --pre option in documentation.

Mark all pre commands as skip so they won't be run again after the container is built.

Ensure that pre commands added to the container are run as the container user if they are not intended to run as root.
This commit is contained in:
David Steele 2019-10-11 12:28:47 -04:00
parent 642ce003c8
commit e4408c7dd3
2 changed files with 14 additions and 6 deletions

View File

@ -261,8 +261,7 @@ sub execute
&log(DEBUG, (' ' x $iIndent) . "execute: $strCommand");
if ($self->{oManifest}->variableReplace($oCommand->paramGet('skip', false, 'n')) ne 'y' ||
$oCommand->paramGet('pre', false, 'n') eq 'y' && $self->{oManifest}->{bPre})
if ($self->{oManifest}->variableReplace($oCommand->paramGet('skip', false, 'n')) ne 'y')
{
if ($self->{bExe} && $self->isRequired($oSection))
{
@ -1041,6 +1040,7 @@ sub sectionChildProcess
my $strHost = $hCacheKey->{name};
my $strImage = $hCacheKey->{image};
my $strHostUser = $self->{oManifest}->variableReplace($oChild->paramGet('user'));
# Determine if a pre-built image should be created
if (defined($self->preExecute($strHost)))
@ -1056,9 +1056,16 @@ sub sectionChildProcess
foreach my $oExecute ($self->preExecute($strHost))
{
my $hExecuteKey = $self->executeKey($strHost, $oExecute);
my $strCommand =
join("\n", @{$hExecuteKey->{cmd}}) .
(defined($hExecuteKey->{'cmd-extra'}) ? ' ' . $hExecuteKey->{'cmd-extra'} : '');
$strCommand =~ s/'/'\\''/g;
$strCommand =
"sudo -u ${strHostUser}" .
($hCacheKey->{'bash-wrap'} ?
" bash" . ($hCacheKey->{'load-env'} ? ' -l' : '') . " -c '${strCommand}'" : " ${strCommand}");
if (defined($strCommandList))
{
@ -1102,10 +1109,8 @@ sub sectionChildProcess
}
my $oHost = new pgBackRestTest::Common::HostTest(
$$hCacheKey{name}, "doc-$$hCacheKey{name}", $strImage,
$self->{oManifest}->variableReplace($oChild->paramGet('user')), $$hCacheKey{os},
defined($strMount) ? [$strMount] : undef,
$strOption, $$hCacheKey{param}, $$hCacheKey{'update-hosts'});
$$hCacheKey{name}, "doc-$$hCacheKey{name}", $strImage, $strHostUser, $$hCacheKey{os},
defined($strMount) ? [$strMount] : undef, $strOption, $$hCacheKey{param}, $$hCacheKey{'update-hosts'});
$self->{host}{$$hCacheKey{name}} = $oHost;
$self->{oManifest}->variableSet('host-' . $hCacheKey->{id} . '-ip', $oHost->{strIP}, true);

View File

@ -572,6 +572,9 @@ sub build
# Add to pre-execute list
my $strHost = $self->variableReplace($oParent->paramGet('host'));
push(@{$self->{preExecute}{$strHost}}, $oNode);
# Skip this command so it doesn't get executed twice
$oNode->paramSet('skip', 'y')
}
}