Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 65 additions & 45 deletions src/BuildScriptGenerator/BaseBashBuildScript.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -135,43 +135,66 @@ then
{{ end }}

{{ if CopySourceDirectoryContentToDestinationDirectory }}
cd "$SOURCE_DIR"

echo
echo "Copying files to destination directory '$DESTINATION_DIR'..."
START_TIME=$SECONDS
excludedDirectories=""
{{ for excludedDir in DirectoriesToExcludeFromCopyToBuildOutputDir }}
excludedDirectories+=" --exclude {{ excludedDir }}"
{{ end }}

{{ if OutputDirectoryIsNested }}
{{ ## We create destination directory upfront for scenarios where pre or post build commands need access
to it. This espceially hanldes the scenario where output directory is a sub-directory of a source directory ## }}
tmpDestinationDir="/tmp/__oryxDestinationDir"
if [ -d "$DESTINATION_DIR" ]; then
mkdir -p "$tmpDestinationDir"
rsync -rcE --links "$DESTINATION_DIR/" "$tmpDestinationDir"
rm -rf "$DESTINATION_DIR"
fi
{{ end }}

{{ ## We use checksum and not the '--times' because the destination directory could be from
a different file system (ex: NFS) where setting modification times results in errors.
Even though checksum is slower compared to the '--times' option, it is more reliable
which is important for us. ## }}
rsync -rcE --links $excludedDirectories . "$DESTINATION_DIR"

{{ if OutputDirectoryIsNested }}
if [ -d "$tmpDestinationDir" ]; then
{{ # Do not overwrite files in destination directory }}
rsync -rcE --links "$tmpDestinationDir/" "$DESTINATION_DIR"
rm -rf "$tmpDestinationDir"
fi
{{ if CompressDestinationDir }}
cd "$SOURCE_DIR"

echo
echo "Copying files to destination directory '$DESTINATION_DIR'..."
START_TIME=$SECONDS
excludedDirectories=""
{{ for excludedDir in DirectoriesToExcludeFromCopyToBuildOutputDir }}
excludedDirectories+=" --exclude {{ excludedDir }}"
{{ end }}

tmpDestinationDir="/tmp/__oryxDestinationDir"
mkdir -p "$tmpDestinationDir"
tar -zcf "$tmpDestinationDir/output.tar.gz" $excludedDirectories .

DESTINATION_DIR="$OLD_DESTINATION_DIR"

rsync -a "$tmpDestinationDir/output.tar.gz" "$DESTINATION_DIR/output.tar.gz"
echo "Copied the compressed output to '$DESTINATION_DIR'"
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Done in $ELAPSED_TIME sec(s)."
{{ else }}
cd "$SOURCE_DIR"

echo
echo "Copying files to destination directory '$DESTINATION_DIR'..."
START_TIME=$SECONDS
excludedDirectories=""
{{ for excludedDir in DirectoriesToExcludeFromCopyToBuildOutputDir }}
excludedDirectories+=" --exclude {{ excludedDir }}"
{{ end }}

{{ if OutputDirectoryIsNested }}
{{ ## We create destination directory upfront for scenarios where pre or post build commands need access
to it. This espceially hanldes the scenario where output directory is a sub-directory of a source directory ## }}
tmpDestinationDir="/tmp/__oryxDestinationDir"
if [ -d "$DESTINATION_DIR" ]; then
mkdir -p "$tmpDestinationDir"
rsync -rcE --links "$DESTINATION_DIR/" "$tmpDestinationDir"
rm -rf "$DESTINATION_DIR"
fi
{{ end }}

{{ ## We use checksum and not the '--times' because the destination directory could be from
a different file system (ex: NFS) where setting modification times results in errors.
Even though checksum is slower compared to the '--times' option, it is more reliable
which is important for us. ## }}
rsync -rcE --links $excludedDirectories . "$DESTINATION_DIR"

{{ if OutputDirectoryIsNested }}
if [ -d "$tmpDestinationDir" ]; then
{{ # Do not overwrite files in destination directory }}
rsync -rcE --links "$tmpDestinationDir/" "$DESTINATION_DIR"
rm -rf "$tmpDestinationDir"
fi
{{ end }}

ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Done in $ELAPSED_TIME sec(s)."
{{ end }}

ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Done in $ELAPSED_TIME sec(s)."
{{ else }}
{{ if CompressDestinationDir }}
{{ ## In case of .NET apps, 'dotnet publish' writes to original destination directory. So here we are
Expand All @@ -183,16 +206,13 @@ then
shopt -s dotglob
mkdir -p $tempDestDir
mv * "$tempDestDir/"
DESTINATION_DIR="$OLD_DESTINATION_DIR"
echo "Compressing content of directory '$preCompressedDestinationDir'..."
cd "$preCompressedDestinationDir"
tar -zcf "$DESTINATION_DIR/output.tar.gz" .
echo "Copied the compressed output to '$DESTINATION_DIR'"
{{ end }}
{{ end }}

{{ if CompressDestinationDir }}
DESTINATION_DIR="$OLD_DESTINATION_DIR"
echo "Compressing content of directory '$preCompressedDestinationDir'..."
cd "$preCompressedDestinationDir"
tar -zcf "$DESTINATION_DIR/output.tar.gz" .
echo "Copied the compressed output to '$DESTINATION_DIR'"
{{ end }}
fi

{{ if ManifestFileName | IsNotBlank }}
Expand Down Expand Up @@ -228,4 +248,4 @@ fi

TOTAL_EXECUTION_ELAPSED_TIME=$(($SECONDS - $TOTAL_EXECUTION_START_TIME))
echo
echo "Done in $TOTAL_EXECUTION_ELAPSED_TIME sec(s)."
echo "Done in $TOTAL_EXECUTION_ELAPSED_TIME sec(s)."
Loading