-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-docker-compose
executable file
·97 lines (75 loc) · 1.88 KB
/
get-docker-compose
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
set -eu
PROGNAME=$(basename $0)
BASEDIR=$(cd $(dirname $0); pwd)
IMAGE=masnagam/docker-compose
PLATFORM=
TAG=latest
CONTAINER=
if [ "$(uname)" != Linux ] || id -nG | grep -q docker; then
DOCKER='docker'
else
DOCKER='sudo docker'
fi
help() {
cat <<EOF >&2
Get docker-compose
Usage:
get-docker-compose -h | --help
get-docker-compose [--platform <platform>] [tag]
Options:
-h, --help
Show help
--platform <platform>
Platform like linux/amd64.
Arguments:
tag [default: $TAG]
One of tags listed in https://hub.docker.com/r/masnagam/docker-compose/tags.
Description:
This script extracts docker-compose a Docker image downloaded from
masnagam/docker-compose:\$tag and outputs it to STDOUT.
The docker-compose is extracted as a TAR archive. Therefore, it has to be
expanded by an archiver program like tar in order to extract docker-compose.
The downloaded Docker image will be removed automatically.
Examples:
Install the latest version of docker-compose into /usr/local/bin:
get-docker-compose | sudo tar -x -C /usr/local/bin
Extract docker-compose for a remote aarch64 machine, and copy it via SSH
get-docker-compose --platform=linux/arm64/v8 | ssh \$REMOTE tar -x
EOF
exit 0
}
error() {
echo "$1" >&2
exit 1
}
clean() {
sleep 1
if [ -n "$CONTAINER" ]; then
$DOCKER container rm -f "$CONTAINER"
fi
$DOCKER image rm -f $IMAGE:$TAG
}
while [ $# -gt 0 ]
do
case "$1" in
'-h' | '--help')
help
;;
'--platform')
PLATFORM="$2"
shift 2
;;
*)
TAG="$1"
break
;;
esac
done
trap "clean" EXIT INT TERM
CREATE_OPTS=
if [ -n "$PLATFORM" ]; then
CREATE_OPTS="--platform $PLATFORM"
fi
CONTAINER=$($DOCKER create $CREATE_OPTS $IMAGE)
$DOCKER cp $CONTAINER:/usr/local/bin/docker-compose -