Skip to content

Commit

Permalink
buildBinFile uses docker
Browse files Browse the repository at this point in the history
Embed directories are using tar gz to embed files,
in order to keep the same tar.gz fingerprint,
we need to have a consistent environment.
So the compilation is done using docker image
scrasnups/build:bash-tools-ubuntu-5.3.
Also probably the difference comes from the
ownership that is written in the archive, we now
uses these options with tar command:
 --sort=name --mtime="@0" \
--owner=0 --group=0 --numeric-owner \
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime,delete=mtime \
--no-same-owner
  • Loading branch information
fchastanet committed May 6, 2024
1 parent 1210ee9 commit 6859280
Show file tree
Hide file tree
Showing 45 changed files with 171 additions and 102 deletions.
1 change: 1 addition & 0 deletions .cspell/bash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ every time
EXIT
exitcode
extglob
exthdr
Facadesh
failfast
fgrep
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config-github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ repos:
)
- repo: https://github.com/fchastanet/bash-tools-framework
rev: 3.0.0
rev: 3.1.0
hooks:
- id: fixShebangExecutionBit
- id: awkLint
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ repos:
)
- repo: https://github.com/fchastanet/bash-tools-framework
rev: 3.0.0
rev: 3.1.0
hooks:
- id: fixShebangExecutionBit
- id: awkLint
Expand Down
7 changes: 3 additions & 4 deletions bin/awkLint
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1205,10 +1204,10 @@ awkLintCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "lint awk files
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "lint awk files
Lint all files with .awk extension in current git folder.
Result in checkstyle format.")"
Result in checkstyle format."
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
80 changes: 61 additions & 19 deletions bin/buildBinFiles
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,21 @@ Assert::dirExists() {
fi
}

# @description check if tty (interactive mode) is active
# @noargs
# @exitcode 1 if tty not active
# @env NON_INTERACTIVE if 1 consider as not interactive even if environment is interactive
# @env INTERACTIVE if 1 consider as interactive even if environment is not interactive
Assert::tty() {
if [[ "${NON_INTERACTIVE:-0}" = "1" ]]; then
return 1
fi
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
tty -s
}

# @description ensure COMMAND_BIN_DIR env var is set
# and PATH correctly prepared
# @noargs
Expand Down Expand Up @@ -603,22 +618,6 @@ Log::logError() {
fi
}

# @description check if tty (interactive mode) is active
# @noargs
# @exitcode 1 if tty not active
# @env NON_INTERACTIVE if 1 consider as not interactive even if environment is interactive
# @env INTERACTIVE if 1 consider as interactive even if environment is not interactive
Assert::tty() {
if [[ "${NON_INTERACTIVE:-0}" = "1" ]]; then
return 1
fi
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
}

# @description log message to file
# @arg $1 message:String the message to display
Log::logFatal() {
Expand Down Expand Up @@ -1293,10 +1292,10 @@ buildBinFilesCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "build files using compile
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "build files using compile
and check if bin file has been updated, if yes return exit code > 0
INTERNAL TOOL")"
INTERNAL TOOL"
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]" "[ARGUMENTS]")"
Expand Down Expand Up @@ -1488,7 +1487,7 @@ getFiles() {
fi
}

run() {
buildBinFiles() {
declare -a files=()
# shellcheck disable=SC2154
for arg in "${buildBinFilesArgs[@]}"; do
Expand Down Expand Up @@ -1523,6 +1522,49 @@ run() {
fi
}

runContainer() {
local image="scrasnups/build:bash-tools-ubuntu-5.3"

if ! docker inspect --type=image "${image}" &>/dev/null; then
docker pull "${image}"
fi

# run docker image
local -a localDockerRunArgs=(
--rm
-w /bash
-v "$(pwd):/bash"
--entrypoint /usr/local/bin/bash
)
# shellcheck disable=SC2154
if Assert::tty; then
localDockerRunArgs+=(-v "/tmp:/tmp")
localDockerRunArgs+=(-it)
fi
if [[ -n "${USER_ID:-}" ]]; then
localDockerRunArgs+=(--user "${USER_ID}:${GROUP_ID}")
fi
localDockerRunArgs+=(
-v "${REAL_SCRIPT_FILE}:/bash/bin/${SCRIPT_NAME}"
)
localDockerRunArgs+=(-e KEEP_TEMP_FILES="${KEEP_TEMP_FILES:-0}")

docker run \
"${localDockerRunArgs[@]}" \
"${image}" \
"/bash/bin/${SCRIPT_NAME}" \
"${ORIGINAL_BASH_FRAMEWORK_ARGV[@]}"

}

run() {
if [[ "${IN_BASH_DOCKER:-}" != "You're in docker" ]]; then
runContainer
else
buildBinFiles
fi
}

if [[ "${BASH_FRAMEWORK_QUIET_MODE:-0}" = "1" ]]; then
run &>/dev/null
else
Expand Down
7 changes: 3 additions & 4 deletions bin/buildPushDockerImage
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1387,7 +1386,7 @@ buildPushDockerImageCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "pull, build and push docker image
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "pull, build and push docker image
- pull previous docker image from docker hub if
exists
Expand All @@ -1399,7 +1398,7 @@ additional docker build options can be passed
via ${__HELP_OPTION_COLOR}DOCKER_BUILD_OPTIONS${__HELP_NORMAL} env variable
INTERNAL
")"
"
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
5 changes: 2 additions & 3 deletions bin/definitionLint
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1459,7 +1458,7 @@ definitionLintCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Lint files of the given directory.")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Lint files of the given directory."
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]" "[ARGUMENTS]")"
Expand Down
9 changes: 3 additions & 6 deletions bin/doc
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,7 @@ Docker::runBuildContainer() {
local optionContinuousIntegrationMode="$6"
local -n localDockerRunCmd=$7
local -n localDockerRunArgs=$8
if tty -s; then
localDockerRunArgs+=("-it")
fi

if [[ -d "$(pwd)/vendor/bash-tools-framework" ]]; then
localDockerRunArgs+=(
-v "$(cd "$(pwd)/vendor/bash-tools-framework" && pwd -P):/bash/vendor/bash-tools-framework"
Expand Down Expand Up @@ -922,8 +920,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -2006,7 +2003,7 @@ docCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Generate markdown documentation.")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Generate markdown documentation."
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
5 changes: 2 additions & 3 deletions bin/dockerLint
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1609,7 +1608,7 @@ dockerLintCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Lint docker files of the given directory using hadolint.")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Lint docker files of the given directory using hadolint."
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
5 changes: 2 additions & 3 deletions bin/findShebangFiles
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1243,7 +1242,7 @@ findShebangFiles() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "find all shebang files of this repository")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "find all shebang files of this repository"
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
5 changes: 2 additions & 3 deletions bin/frameworkLint
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1426,7 +1425,7 @@ frameworkLintCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "This framework linter")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "This framework linter"
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
3 changes: 1 addition & 2 deletions bin/installFacadeExample
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description Display message using error color (red) and exit immediately with error status 1
Expand Down
5 changes: 2 additions & 3 deletions bin/installRequirements
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1354,7 +1353,7 @@ installRequirementsCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "installs requirements")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "installs requirements"
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
5 changes: 2 additions & 3 deletions bin/megalinter
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1514,7 +1513,7 @@ megalinterCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "run megalinter over this repository.")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "run megalinter over this repository."
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]")"
Expand Down
5 changes: 2 additions & 3 deletions bin/plantuml
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1281,7 +1280,7 @@ plantumlCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Generates plantuml diagrams from puml files.")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Generates plantuml diagrams from puml files."
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]" "[ARGUMENTS]")"
Expand Down
9 changes: 3 additions & 6 deletions bin/runBuildContainer
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,7 @@ Docker::runBuildContainer() {
local optionContinuousIntegrationMode="$6"
local -n localDockerRunCmd=$7
local -n localDockerRunArgs=$8
if tty -s; then
localDockerRunArgs+=("-it")
fi

if [[ -d "$(pwd)/vendor/bash-tools-framework" ]]; then
localDockerRunArgs+=(
-v "$(cd "$(pwd)/vendor/bash-tools-framework" && pwd -P):/bash/vendor/bash-tools-framework"
Expand Down Expand Up @@ -689,8 +687,7 @@ Assert::tty() {
if [[ "${INTERACTIVE:-0}" = "1" ]]; then
return 0
fi
# check if stdout or stderr is connected to terminal
[[ -t 1 || -t 2 ]]
tty -s
}

# @description log message to file
Expand Down Expand Up @@ -1526,7 +1523,7 @@ runBuildContainerCommand() {
Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}"
Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}"
elif [[ "${options_parse_cmd}" = "help" ]]; then
echo -e "$(Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "run the container eventually building the docker image before.")"
Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "run the container eventually building the docker image before."
echo

echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]" "[ARGUMENTS]")"
Expand Down
Loading

0 comments on commit 6859280

Please sign in to comment.