Skip to content
Snippets Groups Projects
Commit 1c0f6a1d authored by Gerard Hickey's avatar Gerard Hickey
Browse files

sed command choosen based on OS type

Original version of the sed command to work on OSX had some
incompatiblity when executed under Linux. Now setting a variable to
the correct sed command based on the OS type. The variable is
then used to invoke sed with the proper swtiches.
parent b71640ab
Branches osx_update
No related merge requests found
......@@ -37,6 +37,12 @@ SOURCE="${3:-.}"
DOCKERFILE_EXT='.ubi8'
NEXUS_UBI_IMAGE='${BASE_REGISTRY}/redhat/ubi/ubi8:8.2'
sed="sed -i"
if [[ $(uanme -s) == 'Darwin' ]]; then
# OSX handles sed -i differently
sed="sed -i '' -e"
fi
declare -A LABELED_VERSIONS=(
[REGISTRY_VERSION]=
[GITLAB_EXPORTER_VERSION]=
......@@ -93,7 +99,7 @@ EOF
mv "${DOCKERFILE}.0" "${DOCKERFILE}"
if grep -sq 'ARG UBI_IMAGE=' "${DOCKERFILE}"; then
sed -i '' -e "s/^ARG UBI_IMAGE=.*/ARG UBI_IMAGE=\${BASE_REGISTRY}\/\${BASE_IMAGE}:\${BASE_TAG}/g" "${DOCKERFILE}"
$sed "s/^ARG UBI_IMAGE=.*/ARG UBI_IMAGE=\${BASE_REGISTRY}\/\${BASE_IMAGE}:\${BASE_TAG}/g" "${DOCKERFILE}"
fi
}
......@@ -101,8 +107,8 @@ replaceRubyImageArg() {
local DOCKERFILE="${1}"
local IMAGE_TAG="${2}"
if grep -sq 'ARG RUBY_IMAGE=' "${DOCKERFILE}"; then
sed -i '' -e "s/^ARG UBI_IMAGE.*/ARG UBI_IMAGE=${NEXUS_UBI_IMAGE//\//\\/}/g" "${DOCKERFILE}"
sed -i '' -e "s/^ARG RUBY_IMAGE=.*/ARG RUBY_IMAGE=\${BASE_REGISTRY}\/\${BASE_IMAGE}:\${BASE_TAG}/g" "${DOCKERFILE}"
$sed "s/^ARG UBI_IMAGE.*/ARG UBI_IMAGE=${NEXUS_UBI_IMAGE//\//\\/}/g" "${DOCKERFILE}"
$sed "s/^ARG RUBY_IMAGE=.*/ARG RUBY_IMAGE=\${BASE_REGISTRY}\/\${BASE_IMAGE}:\${BASE_TAG}/g" "${DOCKERFILE}"
fi
}
......@@ -110,14 +116,14 @@ replaceRailsImageArg() {
local DOCKERFILE="${1}"
local IMAGE_TAG="${2}"
if grep -sq 'ARG RAILS_IMAGE=' "${DOCKERFILE}"; then
sed -i '' -e "s/^ARG UBI_IMAGE.*/ARG UBI_IMAGE=${NEXUS_UBI_IMAGE//\//\\/}/g" "${DOCKERFILE}"
sed -i '' -e '/ARG RAILS_IMAGE=.*/d' "${DOCKERFILE}"
$sed "s/^ARG UBI_IMAGE.*/ARG UBI_IMAGE=${NEXUS_UBI_IMAGE//\//\\/}/g" "${DOCKERFILE}"
$sed '/ARG RAILS_IMAGE=.*/d' "${DOCKERFILE}"
if grep -sq 'ARG UBI_IMAGE=' "${DOCKERFILE}"; then
sed -i '' -e "/ARG UBI_IMAGE=.*/a ARG RAILS_IMAGE=\${BASE_REGISTRY}/\${BASE_IMAGE}:\${BASE_TAG}" "${DOCKERFILE}"
$sed "/ARG UBI_IMAGE=.*/a ARG RAILS_IMAGE=\${BASE_REGISTRY}/\${BASE_IMAGE}:\${BASE_TAG}" "${DOCKERFILE}"
else
sed -i '' -e "/ARG BASE_TAG=.*/a \\
$sed "/ARG BASE_TAG=.*/a \\
ARG RAILS_IMAGE=\${BASE_REGISTRY}/\${BASE_IMAGE}:\${BASE_TAG}" "${DOCKERFILE}"
sed -i '' -e "/ARG RAILS_IMAGE=.*/{n;d;}" "${DOCKERFILE}"
$sed "/ARG RAILS_IMAGE=.*/{n;d;}" "${DOCKERFILE}"
fi
fi
}
......@@ -126,15 +132,15 @@ replaceGitImageArg() {
local DOCKERFILE="${1}"; shift
local IMAGE_TAG="${1}"; shift
if grep -sq 'ARG GIT_IMAGE=' "${DOCKERFILE}"; then
sed -i '' -e "s/^ARG UBI_IMAGE.*/ARG UBI_IMAGE=${NEXUS_UBI_IMAGE//\//\\/}/g" "${DOCKERFILE}"
sed -i '' -e "s/^ARG GIT_IMAGE=.*/ARG GIT_IMAGE=\${BASE_REGISTRY}\/\${BASE_IMAGE}:\${BASE_TAG}/g" "${DOCKERFILE}"
$sed "s/^ARG UBI_IMAGE.*/ARG UBI_IMAGE=${NEXUS_UBI_IMAGE//\//\\/}/g" "${DOCKERFILE}"
$sed "s/^ARG GIT_IMAGE=.*/ARG GIT_IMAGE=\${BASE_REGISTRY}\/\${BASE_IMAGE}:\${BASE_TAG}/g" "${DOCKERFILE}"
fi
}
replaceLabeledVersions() {
local DOCKERFILE="${1}"
for _KEY in "${!LABELED_VERSIONS[@]}"; do
sed -i '' -e "s/^ARG ${_KEY}.*/ARG ${_KEY}=${LABELED_VERSIONS[$_KEY]}/g" "${DOCKERFILE}"
$sed "s/^ARG ${_KEY}.*/ARG ${_KEY}=${LABELED_VERSIONS[$_KEY]}/g" "${DOCKERFILE}"
done
}
......@@ -142,7 +148,7 @@ updateBuildScripts() {
local IMAGE_TAG="${1}"
local IMAGE_ROOT="${2}"
if [ -f "${IMAGE_ROOT}/build-scripts/build.sh" ]; then
sed -i '' -e "s/^TAG=.*/TAG=\$\{1:-${IMAGE_TAG}\}/g" "${IMAGE_ROOT}/build-scripts/build.sh"
$sed "s/^TAG=.*/TAG=\$\{1:-${IMAGE_TAG}\}/g" "${IMAGE_ROOT}/build-scripts/build.sh"
fi
}
......@@ -150,7 +156,7 @@ updateJenkinsfile() {
local IMAGE_TAG="${1}"
local IMAGE_ROOT="${2}"
if [ -f "${IMAGE_ROOT}/Jenkinsfile" ]; then
sed -i '' -e "s/version: \"[0-9]\+\.[0-9]\+\.[0-9]\+/version: \"${IMAGE_TAG}/g" "${IMAGE_ROOT}/Jenkinsfile"
$sed "s/version: \"[0-9]\+\.[0-9]\+\.[0-9]\+/version: \"${IMAGE_TAG}/g" "${IMAGE_ROOT}/Jenkinsfile"
fi
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment