-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker-entrypoint
executable file
·37 lines (28 loc) · 1.09 KB
/
docker-entrypoint
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
#!/usr/bin/env bash
EC2_JOIN=
function ec2_members() {
if [ -z ${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI+x} ]; then
return
fi
local region=$(wget http://169.254.169.254/latest/meta-data/placement/availability-zone -q -O- | sed 's/[a-z]$//')
mkdir -p ~/.aws
echo "[default]" > ~/.aws/config
echo "output = json" >> ~/.aws/config
echo "region = $region" >> ~/.aws/config
AWS_TAG=${AWS_TAG:=dkron=member}
AWS_TAG_NAME=$(echo $AWS_TAG | cut -f1 -d=)
AWS_TAG_VALUE=$(echo $AWS_TAG | cut -f2 -d=)
EC2_JOIN=$(aws ec2 describe-instances --filters Name=tag:${AWS_TAG_NAME},Values=${AWS_TAG_VALUE} | jq ".Reservations | map(.Instances)[][].PrivateIpAddress" | cut -f2 -d'"' | paste -sd ";" - | sed -e "s/;/ --join /g")
if [ -n "$EC2_JOIN" ]; then
EC2_JOIN=$(echo " --join $EC2_JOIN")
fi
}
ec2_members
export EC2_JOIN
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- /opt/local/dkron/dkron "$@"
elif [ "$1" == 'agent' -o "$1" == 'keygen' -o "$1" == 'version' ]; then
set -- /opt/local/dkron/dkron "$@"
fi
exec "$@"