diff --git a/CHANGELOG.md b/CHANGELOG.md index 22b1927..53e0630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# Version 3.4.0 +## New Feature +- `dc shell ` to get a shell + +## Removal +- Removed `network` command + # Version 3.3.1 ## Bugfix - New commands were not showing up in tab completion diff --git a/build-files/CHANGELOG.md b/build-files/CHANGELOG.md index 2956670..7db57a8 100644 --- a/build-files/CHANGELOG.md +++ b/build-files/CHANGELOG.md @@ -1,3 +1,6 @@ -# Version 3.3.1 -## Bugfix -- New commands were not showing up in tab completion +# Version 3.4.0 +## New Feature +- `dc shell ` to get a shell + +## Removal +- Removed `network` command diff --git a/dc b/dc index 8db401f..283d315 100755 --- a/dc +++ b/dc @@ -6,7 +6,7 @@ set -m # VERSION -export DC_VERSION=v3.3.1 +export DC_VERSION=v3.4.0 ###### VARIABLES if [[ -z "${DC_DIR}" ]]; then @@ -173,9 +173,9 @@ function show_usage (){ printf " %brestart%b Restarts one or more services \n" "${RED}" "${NC}" printf " %bpull%b Pulls an image of a service \n" "${RED}" "${NC}" printf " %blogs%b Shows logs for a service or services \n" "${RED}" "${NC}" + printf " %shell%b Enters the shell of a container (defaults to /bin/sh) \n" "${RED}" "${NC}" printf "============================= System Commands ============================= \n" printf " %bips%b Shows assigned IPs of containers \n" "${RED}" "${NC}" - printf " %bnetwork%b Create the MacVLAN network, needs sudo \n" "${RED}" "${NC}" printf " %bprune%b Prunes images and containers (basic) or the system \n" "${RED}" "${NC}" printf "======================= Install, Update and Version ======================= \n" printf " %binstall%b Install dc for the user, needs sudo \n" "${RED}" "${NC}" @@ -664,18 +664,35 @@ function logs(){ fi } +function shell(){ + if [ "$#" -ne 1 ]; then + printf "No or multiple arguments provided, please provide the name of one service \n" + else + printf "Accessing shell for the following service: %s \n" "$1" + tmp_stack_files_age + SERVICE="$1" + DC_CMD_PARAM="exec ${SERVICE} /bin/sh" + if grep -r -q -x "${SERVICE}" "${TMP_DIR}"; then + STACK_NAME=$(basename "$(grep -r -x "${SERVICE}" "${TMP_DIR}" | cut -d : -f 1 )") + STACK="${DC_DIR}/${STACK_NAME}" + verbose_stack "${STACK}" "${STACK_NAME}" "${SERVICE}" + cd "${STACK}" || { echo "cd failed"; exit 1; } + create_env_file "${STACK}" "${STACK_NAME}" + dc_cmd_create "${DC_CMD_PARAM}" + cd - > /dev/null || { echo "cd failed"; exit 1; } + else + printf "ERROR: Service %s was not found in any of the stacks. Does it show up when you run %bdc list%b? \n" "${SERVICE}" "${RED}" "${NC}" + fi + fi + } + ################################################## # SYSTEM COMMANDS # ################################################## # IPS function ips(){ printf "Showing IPs \n" - (echo "CONTAINER IP-ADRESS MAC-ADDRESS"; docker inspect --format='{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}} {{.MacAddress}}{{end}}' $(docker ps -aq)| sort -k 2 -V) | column -t -s ' ' - } - -# NETWORK -function network(){ - printf "This function does nothing (yet) \n" + (echo "CONTAINER IP-ADRESS MAC-ADDRESS"; docker inspect --format='{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}} {{.MacAddress}}{{end}}' "$(docker ps -aq)"| sort -k 2 -V) | column -t -s ' ' } function prune() { @@ -754,14 +771,14 @@ case ${1} in "logs") logs "${@:2}" ;; +# ----------- shell ------------ + "shell") + shell "${@:2}" + ;; # ----------- ips ------------ "ips") ips ;; -# ----------- network ------------ - "network") - network - ;; # ----------- prune ------------ "prune") prune "${@}" diff --git a/dc-completion b/dc-completion index 868fb94..74f0249 100755 --- a/dc-completion +++ b/dc-completion @@ -2,7 +2,7 @@ # Copyright (C) 2022 - 2023 Ben Hählen # This is the completion file for `dc` ############## -# Version 3.3.1 +# Version 3.4.0 ############## _dc_completions() { @@ -21,7 +21,7 @@ _dc_completions() export DC_CMD="docker compose" # Basic/main options that will be completed - OPTS="install up down restart-stack-hard restart-stack-soft logs-stack start stop restart pull logs ips network clean list help update version prune" + OPTS="install up down restart-stack-hard restart-stack-soft logs-stack start stop restart pull logs ips clean list help update version prune shell" # Based on the arguments, we can run functions case "$cmd" in @@ -33,7 +33,7 @@ _dc_completions() COMPREPLY=( $(compgen -W "${STACKS}" -- "${CUR}") ) return 0 ;; - start|stop|restart|pull|logs) + start|stop|restart|pull|logs|shell) # We might need to create the tmp-files, so reusing the command from dc, however, this is duplicating stuff, which is not nice, but for a MVP, it works for STACK in $(find "${DC_DIR}" \( -name compose.yaml -or -name compose.yml -or -name docker-compose.yaml -or -name docker-compose.yml \) -printf '%h\n' | sort -u); do @@ -69,7 +69,7 @@ _dc_completions() COMPREPLY=( $(compgen -W "${SERVICES}" -- "${CUR}") ) return 0 ;; - install|ips|network|clean|list|help|version) + install|ips|clean|list|help|version) return ;; prune)