Skip to content

Commit

Permalink
Refactor --pre option in documentation.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dwsteele committed Oct 11, 2019
1 parent 642ce00 commit e4408c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 11 additions & 6 deletions doc/lib/BackRestDoc/Common/DocExecute.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)))
Expand All @@ -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))
{
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions doc/lib/BackRestDoc/Common/DocRender.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}

Expand Down

0 comments on commit e4408c7

Please sign in to comment.