From 7b41e4e4ee1dbff20891da1b8061879de7864c52 Mon Sep 17 00:00:00 2001 From: Adam Keller Date: Thu, 17 Sep 2020 16:25:08 +0000 Subject: [PATCH] Update to Dockerfile --- Dockerfile | 7 ++++--- startup-cdk.sh | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36733ed..e184438 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,16 @@ FROM ruby:2.5-slim COPY Gemfile Gemfile.lock /usr/src/app/ WORKDIR /usr/src/app -RUN apt-get update && apt-get -y install iproute2 curl jq libgmp3-dev ruby-dev build-essential sqlite libsqlite3-dev && \ +RUN apt-get update && apt-get -y install iproute2 curl jq libgmp3-dev ruby-dev build-essential sqlite libsqlite3-dev python3 python3-pip && \ bundle install && \ + pip3 install awscli && \ apt-get autoremove -y --purge && \ apt-get remove -y --auto-remove --purge ruby-dev libgmp3-dev build-essential libsqlite3-dev && \ apt-get clean && \ rm -rvf /root/* /root/.gem* /var/cache/* COPY . /usr/src/app -RUN chmod +x /usr/src/app/startup.sh +RUN chmod +x /usr/src/app/startup-cdk.sh # helpful when trying to update gems -> bundle update, remove the Gemfile.lock, start ruby # RUN bundle update @@ -20,4 +21,4 @@ RUN chmod +x /usr/src/app/startup.sh HEALTHCHECK --interval=10s --timeout=3s \ CMD curl -f -s http://localhost:3000/health/ || exit 1 EXPOSE 3000 -ENTRYPOINT ["bash","/usr/src/app/startup.sh"] +ENTRYPOINT ["bash","/usr/src/app/startup-cdk.sh"] diff --git a/startup-cdk.sh b/startup-cdk.sh index b7e025b..de6bed5 100755 --- a/startup-cdk.sh +++ b/startup-cdk.sh @@ -84,7 +84,10 @@ if [[ -z ${zone} ]]; then declare -a subnets=( $(aws ec2 describe-subnets | jq .Subnets[].CidrBlock| sed ':a;N;$!ba;s/\n/ /g') ) for sub in "${subnets[@]}"; do if $(ruby -e "puts(IPAddr.new($sub.to_s).include? $ip_addr.to_s)") == 'true'; then - zone=$(aws ec2 describe-subnets | jq -r ".Subnets[] | select(.CidrBlock==$sub) | .AvailabilityZone" | grep -o .$) + details=$(aws ec2 describe-subnets | jq -r ".Subnets[] | select(.CidrBlock==$sub)") + if [[ $(echo $details | jq .Tags) != "null" ]]; then + zone=$(echo $details | jq -r 'select(.Tags[].Value=="ecsworkshop") | .AvailabilityZone' | sort -u | grep -o .$) + fi fi done fi