feat: reworked dev container script, many more features
This commit is contained in:
+50
-11
@@ -5,7 +5,7 @@ mount_path=$(pwd)
|
||||
if [[ -n "$2" ]]; then
|
||||
name=$2
|
||||
else
|
||||
name=$(pwd | rev | cut -d "/" -f 1 | rev)
|
||||
name=$(pwd | rev | cut -d "/" -f 1-2 | rev | sed -e 's/\//-/')
|
||||
fi
|
||||
|
||||
if [[ $1 == "help" ]]; then
|
||||
@@ -25,26 +25,65 @@ rm removes the container for the current directory if provided name is existing
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "
|
||||
janishutz dev containers
|
||||
"
|
||||
if [[ $(systemctl is-active docker) != "active" ]]; then
|
||||
echo "
|
||||
Docker daemon not running, starting with systemctl
|
||||
-> Docker daemon not running, starting with systemctl <-
|
||||
"
|
||||
sudo systemctl start docker
|
||||
fi
|
||||
|
||||
if [[ $1 == "rm" ]]; then
|
||||
echo "
|
||||
janishutz dev containers
|
||||
|
||||
-> Removing container $name <-
|
||||
-> Removing containers with $name in their name <-
|
||||
"
|
||||
docker stop $name
|
||||
docker container rm $name
|
||||
else
|
||||
echo "
|
||||
janishutz dev containers
|
||||
if [[ $(read -p "Do you really want to delete ALL containers for this directory? (y/N) " response && echo $response) == 'y' ]]; then
|
||||
for container in $(docker container ls -aq -f name=$name); do
|
||||
docker stop $container
|
||||
docker container rm $container
|
||||
done
|
||||
else
|
||||
echo "Aborting."
|
||||
exit 0
|
||||
fi
|
||||
elif [[ $1 == "shell" ]]; then
|
||||
containers=$(docker ps -q -f name=$name)
|
||||
count=$((${#containers[@]}))
|
||||
|
||||
if [[ ${containers[0]} == "" ]]; then
|
||||
count=$(($count-1))
|
||||
fi
|
||||
|
||||
if [[ $count == 0 ]]; then
|
||||
echo "
|
||||
-> No suitable running container found. Aborting.
|
||||
"
|
||||
elif [[ $count == 1 ]]; then
|
||||
echo "
|
||||
-> Connecting to running container ${containers[0]}
|
||||
"
|
||||
docker exec -it ${containers[0]} '/bin/bash'
|
||||
else
|
||||
echo "
|
||||
-> Multiple possible containers found to attach to. Pick one (enter number)
|
||||
"
|
||||
docker ps -f name=$name
|
||||
read -p "Enter number (1-$(${#containers[@]})) " sel
|
||||
docker exec -it containers[$sel] '/bin/bash'
|
||||
fi
|
||||
else
|
||||
name=$name-$1
|
||||
if [[ $(docker container ls -aq -f name=$name) != "" ]]; then
|
||||
echo "
|
||||
-> Starting existing container $name <-
|
||||
"
|
||||
docker start -i $name
|
||||
else
|
||||
echo "
|
||||
-> Creating container $name <-
|
||||
"
|
||||
eval "${base_path}$1-container $1-$name $mount_path"
|
||||
eval "${base_path}$1-container $name $mount_path"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
complete -a "base node php python torch-rocm vue webserver" -c dev-containers -f
|
||||
complete -a "base jupyter node php python torch-rocm vue webserver" -c dev-containers -f
|
||||
complete -a "rm" -d "Delete the container for this folder" -c dev-containers -f
|
||||
complete -a "help" -d "Show help" -c dev-containers -f
|
||||
complete -a "shell" -d "Create an extra shell for the currently running container" -c dev-containers -f
|
||||
|
||||
Reference in New Issue
Block a user