File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ WORKDIR /usr/src/app
77RUN apt-get update && apt-get -y install iproute2 curl jq libgmp3-dev ruby-dev build-essential sqlite libsqlite3-dev python3 python3-pip && \
88 gem install bundler:1.17.3 && \
99 bundle install && \
10- pip3 install awscli && \
10+ pip3 install awscli netaddr && \
1111 apt-get autoremove -y --purge && \
1212 apt-get remove -y --auto-remove --purge ruby-dev libgmp3-dev build-essential libsqlite3-dev && \
1313 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" ")
77if [[ ${IP} == " " ]]; then
88 IP=$( hostname -i)
99fi
10-
1110SUBNET=$( echo ${IP} | cut -f1 -d.)
1211NETWORK=$( echo ${IP} | cut -f3 -d.)
1312
8079# Still no luck? Perhaps we're running fargate!
8180if [[ -z ${zone} ]]; then
8281 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' ) )
8584 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 .$)
9188 fi
9289 done
9390fi
9491
9592export CODE_HASH=" $( cat code_hash.txt) "
93+ export IP
9694export AZ=" ${IP} in AZ-${zone} "
9795
9896# exec bundle exec thin start
You can’t perform that action at this time.
0 commit comments