Skip to content

Commit

Permalink
Merge pull request brentley#4 from brentley/sd
Browse files Browse the repository at this point in the history
Sd
  • Loading branch information
brentley authored Aug 14, 2018
2 parents 714357a + dcd172d commit af8810e
Show file tree
Hide file tree
Showing 49 changed files with 122 additions and 88 deletions.
53 changes: 30 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.4)
binding_of_caller (0.7.3)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
builder (3.2.3)
byebug (9.1.0)
byebug (10.0.2)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
Expand All @@ -48,36 +48,38 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.3)
crass (1.0.4)
daemons (1.2.6)
debug_inspector (0.0.3)
erubis (2.7.0)
eventmachine (1.2.7)
execjs (2.7.0)
ffi (1.9.18)
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (0.9.1)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.1)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.6)
libv8 (3.16.14.19-x86_64-linux)
loofah (2.1.1)
libv8 (3.16.14.19)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.10.3)
multi_json (1.12.2)
nokogiri (1.8.1)
minitest (5.11.3)
multi_json (1.13.1)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
rack (1.6.8)
rack (1.6.10)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.10)
Expand All @@ -97,20 +99,20 @@ GEM
activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (4.2.10)
actionpack (= 4.2.10)
activesupport (= 4.2.10)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.0)
rb-fsevent (0.10.2)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rdoc (4.3.0)
ref (2.0.0)
sass (3.5.4)
sass (3.5.7)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -126,7 +128,7 @@ GEM
rdoc (~> 4.0)
spring (2.0.2)
activesupport (>= 4.2)
sprockets (3.7.1)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
Expand All @@ -137,15 +139,19 @@ GEM
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
thin (1.7.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.3)
tzinfo (1.2.4)
turbolinks (5.1.1)
turbolinks-source (~> 5.1)
turbolinks-source (5.1.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.0.2)
uglifier (4.1.18)
execjs (>= 0.3.0, < 3)
web-console (2.3.0)
activemodel (>= 4.0)
Expand All @@ -168,6 +174,7 @@ DEPENDENCIES
spring
sqlite3
therubyracer
thin
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Amazon ECS Workshop
# Amazon Containers Workshop

This is part of an Amazon ECS workshop at https://ecsworkshop.com
This is part of an Amazon Containers workshop at https://ecsworkshop.com or https://eksworkshop.com
2 changes: 1 addition & 1 deletion app/assets/images/a-N-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-N-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-N-c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-a-N.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-a-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-a-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-a-c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-b-N.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-b-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-b-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-b-c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-c-N.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-c-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-c-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/a-c-c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-N-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-N-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-N-c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-a-N.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-a-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-a-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-a-c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-b-N.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-b-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-b-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/images/b-b-c.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/b-c-N.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/b-c-a.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/b-c-b.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/b-c-c.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-N-a.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-N-b.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-N-c.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-a-N.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-a-a.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-a-b.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-a-c.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-b-N.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-b-a.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-b-b.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-b-c.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-c-N.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-c-a.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-c-b.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/images/c-c-c.svg

Large diffs are not rendered by default.

58 changes: 42 additions & 16 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'net/http'
require 'resolv'
require 'uri'

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
Expand All @@ -8,9 +10,8 @@ class ApplicationController < ActionController::Base
# Example endpoint that calls the backend nodejs api
def index
begin
url = URI.parse(backend_addr)
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
req = Net::HTTP::Get.new(nodejs_uri.to_s)
res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http|
http.request(req)
}

Expand All @@ -20,9 +21,15 @@ def index
@text = "no backend found"
end

crystalurl = URI.parse(crystal_addr)
crystalreq = Net::HTTP::Get.new(crystalurl.to_s)
crystalres = Net::HTTP.start(crystalurl.host, crystalurl.port) {|http|
rescue => e
logger.error e.message
logger.error e.backtrace.join("\n")
@text = "no backend found"
end

begin
crystalreq = Net::HTTP::Get.new(crystal_uri.to_s)
crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http|
http.request(crystalreq)
}

Expand All @@ -32,8 +39,9 @@ def index
@crystal = "no backend found"
end

rescue
@text = "no backend found"
rescue => e
logger.error e.message
logger.error e.backtrace.join("\n")
@crystal = "no backend found"
end
end
Expand All @@ -43,16 +51,34 @@ def health
render plain: "OK"
end

def crystal_addr
crystal_addr = ENV["BACKEND_API"]
# The address will be of the form, http://172.17.0.5:5432, so we add a trailing slash
crystal_addr.sub(/^http:/, 'http:') + "/crystal"
def crystal_uri
expand_url ENV["CRYSTAL_URL"]
end

def nodejs_uri
expand_url ENV["NODEJS_URL"]
end

def backend_addr
backend_addr = ENV["BACKEND_API"]
# The address will be of the form, http://172.17.0.5:5432, so we add a trailing slash
backend_addr.sub(/^http:/, 'http:') + "/"
# Resolve the SRV records for the hostname in the URL
def expand_url(url)
uri = URI(url)
resolver = Resolv::DNS.new()

# if host is relative, append the service discovery name
host = uri.host.count('.') > 0 ? uri.host : "#{uri.host}.#{ENV["_SERVICE_DISCOVERY_NAME"]}"

# lookup the SRV record and use if found
begin
srv = resolver.getresource(host, Resolv::DNS::Resource::IN::SRV)
uri.host = srv.target.to_s
uri.port = srv.port.to_s
rescue => e
logger.error e.message
logger.error e.backtrace.join("\n")
end

logger.info "expanded #{url} to #{uri}"
uri
end

before_action :discover_availability_zone
Expand Down
5 changes: 3 additions & 2 deletions mu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ service:
port: 3000
pathPatterns:
- /*
networkMode: awsvpc
discoveryTTL: 5
environment:
BACKEND_API: "http://api.internal.service:80"
CRYSTAL_URL: "http://ecsdemo-crystal/crystal"
NODEJS_URL: "http://ecsdemo-nodejs/"

0 comments on commit af8810e

Please sign in to comment.