Created
August 17, 2022 11:20
-
-
Save eskerda/954c68e3f2e1d069a96ef4fd254862ef to your computer and use it in GitHub Desktop.
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
# Attach a volume to a service using a set of clever defaults | |
# | |
# usage: | |
# attach-compose.sh <service> <path> | |
# attach-compose.sh --no-cmd <service> <path> | |
function _compose { | |
local flags=() | |
[[ -f docker-compose.yml ]] && \ | |
flags+=("-f docker-compose.yml") | |
[[ -f docker-compose.override.yml ]] && \ | |
flags+=("-f docker-compose.override.yml") | |
docker-compose ${flags[@]} $@ | |
} | |
function _attach_compose { | |
local service=$1 | |
local path=$(realpath $2) | |
local image=$(_compose images $service -q) | |
local workingdir=$(docker inspect $image -f '{{ .Config.WorkingDir }}') | |
cat << EOF | |
services: | |
$1: | |
command: tail -f /dev/null | |
volumes: | |
- ${path}:${workingdir}/$(basename ${path}) | |
EOF | |
} | |
function attach_compose { | |
local service=$1; local path=$2; shift 2 | |
_compose -f <(_attach_compose $service $path) $@ | |
} | |
attach_compose $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment