File tree 2 files changed +7
-9
lines changed
2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ WORKDIR /usr/src/app
7
7
RUN apt-get update && apt-get -y install iproute2 curl jq libgmp3-dev ruby-dev build-essential sqlite libsqlite3-dev python3 python3-pip && \
8
8
gem install bundler:1.17.3 && \
9
9
bundle install && \
10
- pip3 install awscli && \
10
+ pip3 install awscli netaddr && \
11
11
apt-get autoremove -y --purge && \
12
12
apt-get remove -y --auto-remove --purge ruby-dev libgmp3-dev build-essential libsqlite3-dev && \
13
13
apt-get clean && \
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ IP=$(ip route show |grep -o src.* |cut -f2 -d" ")
7
7
if [[ ${IP} == " " ]]; then
8
8
IP=$( hostname -i)
9
9
fi
10
-
11
10
SUBNET=$( echo ${IP} | cut -f1 -d.)
12
11
NETWORK=$( echo ${IP} | cut -f3 -d.)
13
12
80
79
# Still no luck? Perhaps we're running fargate!
81
80
if [[ -z ${zone} ]]; then
82
81
export AWS_DEFAULT_REGION=$REGION
83
- ip_addr=$( curl -m2 -s ${ECS_CONTAINER_METADATA_URI} | jq ' .Networks[].IPv4Addresses[]' )
84
- declare -a subnets=( $( aws ec2 describe-subnets | jq .Subnets[].CidrBlock| sed ' :a;N;$!ba;s/\n/ /g' ) )
82
+ ip_addr=$( curl -m2 -s ${ECS_CONTAINER_METADATA_URI} | jq -r ' .Networks[].IPv4Addresses[]' )
83
+ declare -a subnets=( $( aws ec2 describe-subnets | jq -r .Subnets[].CidrBlock| sed ' :a;N;$!ba;s/\n/ /g' ) )
85
84
for sub in " ${subnets[@]} " ; do
86
- if $( ruby -e " puts(IPAddr.new($sub .to_s).include? $ip_addr .to_s)" ) == ' true' ; then
87
- details=$( aws ec2 describe-subnets | jq -r " .Subnets[] | select(.CidrBlock==$sub )" )
88
- if [[ $( echo $details | jq .Tags) != " null" ]]; then
89
- zone=$( echo $details | jq -r ' select(.Tags[].Value=="ecsworkshop") | .AvailabilityZone' | sort -u | grep -o .$)
90
- fi
85
+ ip_match=$( echo -e " from netaddr import IPNetwork, IPAddress\nif IPAddress('$ip_addr ') in IPNetwork('$sub '):\n print('true')" | python3)
86
+ if [[ $ip_match == " true" ]]; then
87
+ zone=$( aws ec2 describe-subnets | jq -r --arg sub " $sub " ' .Subnets[] | select(.CidrBlock==$sub) | .AvailabilityZone' | grep -o .$)
91
88
fi
92
89
done
93
90
fi
94
91
95
92
export CODE_HASH=" $( cat code_hash.txt) "
93
+ export IP
96
94
export AZ=" ${IP} in AZ-${zone} "
97
95
98
96
# exec bundle exec thin start
You can’t perform that action at this time.
0 commit comments