~rootmos/scripts

cd4d19f0259f316481b3d80fbadc597c793918de — Gustav Behm a month ago 287b209
Make sure docker daemon is running before cleaning
1 files changed, 17 insertions(+), 10 deletions(-)

M dorker
M dorker => dorker +17 -10
@@ 74,7 74,7 @@ EOF

clean() {
    if [ -f "$CONTAINER" ]; then
        _d rm -f "$(cat "$CONTAINER")"
        _d rm -f "$(cat "$CONTAINER")" 1>&2
        rm -f "$CONTAINER"
    fi
}


@@ 129,11 129,12 @@ if [ "$ACTION" = "build" ]; then
    build
elif [ "$ACTION" = "run" ]; then
    OPTIND=1
    while getopts "iv:f-" OPT; do
    while getopts "iv:fE:-" OPT; do
        case $OPT in
            i) RUN_ARGS+=("--interactive" "--tty") ;;
            v) RUN_ARGS+=("--volume=$OPTARG") ;;
            f) FORCE_REBUILD=1 ;;
            E) RUN_ARGS+=("--entrypoint=$OPTARG") ;;
            -) break ;;
            ?) exit 2 ;;
        esac


@@ 146,17 147,20 @@ elif [ "$ACTION" = "run" ]; then
elif [ "$ACTION" = "rmi" ]; then
    ensure_daemon_is_running
    rmi
elif [ "$ACTION" = "clean" ]; then
    ensure_daemon_is_running
    clean
elif [ "$ACTION" = "deepclean" ]; then
    ensure_daemon_is_running
    deepclean
elif [ "$ACTION" = "prune" ]; then
    ensure_daemon_is_running
    # https://docs.docker.com/config/pruning/#prune-everything
    _d system prune --all
fi

if daemon_is_running; then
    if [ "$ACTION" = "clean" ]; then
        clean
    elif [ "$ACTION" = "deepclean" ]; then
        deepclean
    elif [ "$ACTION" = "prune" ]; then
        # https://docs.docker.com/config/pruning/#prune-everything
        _d system prune --all
    elif [ "$ACTION" = "exec" ]; then
    if [ "$ACTION" = "exec" ]; then
        ARGS=()
        OPTIND=1
        while getopts "i-" OPT; do


@@ 170,4 174,7 @@ if daemon_is_running; then

        _d exec "${ARGS[@]}" "$(cat "$CONTAINER")" "$@"
    fi
else
    echo 1>&2 "docker daemon isn't running; ignoring action: $ACTION"
    exit 1
fi