-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default command to cqfd run
, remove command and automatically init when needed
#106
Open
Ballasi
wants to merge
3
commits into
master
Choose a base branch
from
sudoisation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,9 @@ Options: | |
-h or --help Show this help text. | ||
|
||
Commands: | ||
init Initialize project build container | ||
flavors List flavors from config file to stdout | ||
run Run argument(s) inside build container | ||
release Run argument(s) and release software | ||
help Show this help text | ||
--init Initialize project build container | ||
--flavors List flavors from config file to stdout | ||
--release Run argument(s) and release software | ||
|
||
By default, run is assumed, and the run command is the one | ||
configured in .cqfdrc. | ||
|
@@ -111,13 +109,66 @@ die() { | |
exit 1 | ||
} | ||
|
||
# loading_throbber() - Loading throbber process for Docker build initialization | ||
loading_throbber() { | ||
pid=$1 | ||
delay=0.1 | ||
spinstr='-\|/' | ||
|
||
while kill -0 "$pid" 2>/dev/null | ||
do | ||
temp=${spinstr#?} | ||
state=$(awk '$2 ~ /(\[[0-9]+\/[0-9]+)\]/ { print $2 }' "$TEMP_OUTPUT" | sed 's/^.\(.*\).$/\1/' | tail -n 1) | ||
# if not using buildx, use previous format | ||
[ "$state" ] || state=$(awk '$1 == "Step" { print $2 }' "$TEMP_OUTPUT" | tail -n 1) | ||
spinstr=$temp${spinstr%"$temp"} | ||
# Getting the last line of the output of the long command | ||
if [ "$state" ]; then | ||
printf '\r[%c] %s: Initialization of the environment (%s)' "$spinstr" "$PROGNAME" "$state" | ||
line_length=$((46 + ${#state})) | ||
else | ||
printf '\r[%c] %s: Initialization of the environment' "$spinstr" "$PROGNAME" | ||
fi | ||
sleep $delay | ||
done | ||
} | ||
|
||
# docker_build() - Initialize build container | ||
docker_build() { | ||
export BUILDKIT_PROGRESS=plain | ||
TEMP_OUTPUT=$(mktemp -u) | ||
line_length=46 | ||
|
||
if [ -z "$project_build_context" ]; then | ||
docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "$(dirname "$dockerfile")" | ||
docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "$(dirname "$dockerfile")" > "$TEMP_OUTPUT" 2>&1 & | ||
else | ||
docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "${project_build_context}" -f "$dockerfile" | ||
docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "${project_build_context}" -f "$dockerfile" > "$TEMP_OUTPUT" 2>&1 & | ||
fi | ||
container_init_command_pid=$! | ||
|
||
if [ "$quiet" ]; then | ||
# If quiet mode is enabled, we don't display the throbber | ||
# and we wait for the docker build to finish | ||
wait $container_init_command_pid | ||
cat "$TEMP_OUTPUT" | ||
rm "$TEMP_OUTPUT" | ||
return 0 | ||
fi | ||
|
||
# Start the throbber | ||
loading_throbber $container_init_command_pid | ||
|
||
# Wait for the docker build to finish | ||
if ! wait $container_init_command_pid; then | ||
printf "\r%${line_length}s\r" | ||
cat "$TEMP_OUTPUT" 1>&2 | ||
rm "$TEMP_OUTPUT" | ||
die 'Initialization of environment failed' | ||
fi | ||
|
||
# Clean up the output file and the console | ||
printf "\r%${line_length}s\r" | ||
rm "$TEMP_OUTPUT" | ||
} | ||
|
||
# docker_run() - run command in configured container | ||
|
@@ -136,9 +187,8 @@ docker_build() { | |
# arg$1: the command string to execute as $cqfd_user | ||
# | ||
docker_run() { | ||
|
||
if ! docker image inspect $docker_img_name &> /dev/null; then | ||
die "The docker image doesn't exist, launch 'cqfd init' to create it" | ||
docker_build | ||
fi | ||
|
||
local interactive_options | ||
|
@@ -456,20 +506,22 @@ has_custom_cqfdrc=false | |
has_to_release=false | ||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
help|-h|"--help") | ||
-h|"--help") | ||
usage | ||
exit 0 | ||
;; | ||
version|-v|"--version") | ||
-v|"--version") | ||
echo $VERSION | ||
exit 0 | ||
;; | ||
init) | ||
"--init") | ||
config_load $flavor | ||
docker_build | ||
exit $? | ||
ret=$? | ||
[ "$quiet" ] || echo "$PROGNAME: Initialization of environment successful" | ||
exit $ret | ||
;; | ||
flavors) | ||
"--flavors") | ||
config_load | ||
echo $build_flavors | ||
exit 0 | ||
|
@@ -494,43 +546,33 @@ while [ $# -gt 0 ]; do | |
-q) | ||
quiet=true | ||
;; | ||
run|release) | ||
if [ "$1" = "release" ]; then | ||
has_to_release=true | ||
fi | ||
|
||
shift | ||
|
||
# No more args? run default command | ||
[ "$#" -eq 0 ] && break | ||
|
||
# -c appends following args to the default command | ||
if [ "$1" = "-c" ]; then | ||
if [ $# -lt 2 ]; then | ||
die "option -c requires arguments" | ||
fi | ||
|
||
shift | ||
build_cmd_append="$*" | ||
break | ||
fi | ||
|
||
# Run alternate command | ||
build_cmd_alt="$@" | ||
break | ||
;; | ||
?*) | ||
echo "Unknown command: $1" | ||
usage | ||
exit 1 | ||
"--release") | ||
has_to_release=true | ||
;; | ||
*) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be out of scope, but can we support |
||
# empty or no argument case | ||
# run a command | ||
break | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
# No more args? run default command | ||
if [ "$#" -ne 0 ]; then | ||
# -c appends following args to the default command | ||
if [ "$1" = "-c" ]; then | ||
if [ $# -lt 2 ]; then | ||
die "option -c requires arguments" | ||
fi | ||
|
||
shift | ||
build_cmd_append="$*" | ||
else | ||
# Run alternate command | ||
build_cmd_alt="$@" | ||
fi | ||
fi | ||
|
||
config_load $flavor | ||
|
||
if [ -n "$build_cmd_alt" ]; then | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these 3 now be in the
Options:
section?