Skip to content

Commit

Permalink
Add build-only options
Browse files Browse the repository at this point in the history
This adds the option --build-only to exit after the image is built.
  • Loading branch information
gportay committed Feb 1, 2024
1 parent faefdfa commit 4346dc5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bash-completion
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2017-2020,2023 Gaël PORTAY
# Copyright (c) 2017-2020,2023-2024 Gaël PORTAY
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -144,7 +144,7 @@ _dosh()

local shopts="-a -b -e -f -h -m -n -u -v -x -C"
local short_opts="-c -s -i -o"
local long_opts="--dockerfile --context --no-auto-context --no-extra-options --no-doshprofile --no-doshrc --directory --working-directory --root --dind --home --mount-options --shell --ls --gc --build --rebuild --rmi --detach --exec --attach --kill --rm --tag --dry-run --verbose --version --help"
local long_opts="--dockerfile --context --no-auto-context --no-extra-options --no-doshprofile --no-doshrc --directory --working-directory --root --dind --home --mount-options --shell --ls --gc --build-only --build --rebuild --rmi --detach --exec --attach --kill --rm --tag --dry-run --verbose --version --help"
local shell="${DOSHELL:-/bin/sh}"
for (( i=0; i < ${#words[@]}; i++ )); do
if [[ ${words[i]} == --shell ]]; then
Expand Down
10 changes: 9 additions & 1 deletion dosh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Docker related options:
Equivalent to set DOSHELL=<SHELL>.
--ls List images and exit.
--gc Cleanup unused images and exit.
--build-only Build image if needed and exit.
--build Build image.
--rebuild Build image again, verbosely.
Equivalent to --build --verbose.
Expand Down Expand Up @@ -565,7 +566,7 @@ has_positional_parameter() {
}

is_doshopt() {
if [[ "$1" =~ ^--(no-auto-context|no-extra-options|no-doshprofile|no-doshrc|root|dind|home|ls|gc|build|rebuild|rmi|detach|kill|rm|tag)$ ]]
if [[ "$1" =~ ^--(no-auto-context|no-extra-options|no-doshprofile|no-doshrc|root|dind|home|ls|gc|build|rebuild|build-only|rmi|detach|kill|rm|tag)$ ]]
then
return 0
fi
Expand Down Expand Up @@ -834,6 +835,13 @@ then
fi
fi

# Image is built already, do not run a container and exit
if [[ ${build_only:-} ]]
then
# Do nothing
exit
fi

# Set the current user privileges for dosh-in-dosh
if [[ ${dind:-} ]]
then
Expand Down
5 changes: 4 additions & 1 deletion dosh.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ command-line through *docker-run(1)*.
**--gc**::
Cleanup unused images and exit.

**--build-only**::
Build image if needed and exit.

**--build**::
Build image.

Expand Down Expand Up @@ -413,7 +416,7 @@ Written by Gaël PORTAY *[email protected]*

== COPYRIGHT

Copyright (c) 2017-2020,2023 Gaël PORTAY
Copyright (c) 2017-2020,2023-2024 Gaël PORTAY

This program is free software: you can redistribute it and/or modify it under
the terms of the MIT License.
Expand Down
3 changes: 2 additions & 1 deletion support/docker-shell
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2023 Gaël PORTAY
# Copyright (c) 2023-2024 Gaël PORTAY
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -65,6 +65,7 @@ Options:
docker-run(1) manual.
--shell string Set shell interpretor.
--ls List images.
--build-only Build image if needed and exit.
--build Build image.
--rebuild Build image again, verbosely.
Equivalent to --build --verbose.
Expand Down
9 changes: 9 additions & 0 deletions tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ else
fi
echo

run "Test option --build-only"
if dosh --build-only -c "exit 1"
then
ok
else
ko
fi
echo

run "Test option --build"
if dosh --build --verbose -c "cat /etc/os*release" 2>&1 >/dev/null | tee /dev/stderr | \
grep '^Sending build context to Docker daemon'
Expand Down

0 comments on commit 4346dc5

Please sign in to comment.