- Save the files in the gist
- Run
chmod +x push.sh && . !$
- Run
chmod +x test.sh && . !$
Last active
June 23, 2022 11:55
-
-
Save tlwr/cdce75187e2e375078406bad07b26bf8 to your computer and use it in GitHub Desktop.
PaaS service discovery example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'http' | |
require 'sinatra' | |
require 'time' | |
BACKEND = 'http://backend.apps.internal:8080' | |
get '/' do | |
app = ENV.fetch('APP') | |
<<-RESPONSE | |
#{app} | |
#{Time.now} | |
#{ENV.fetch('CF_INSTANCE_INDEX')} | |
#{ENV.fetch('CF_INSTANCE_ADDR')} | |
#{ENV.fetch('CF_INSTANCE_IP')} | |
#{ENV.fetch('CF_INSTANCE_INTERNAL_IP')} | |
----- | |
#{app == 'frontend' ? HTTP.get(BACKEND).body.to_s : ''} | |
RESPONSE | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path('../app.rb', __FILE__) | |
run Sinatra::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'http' | |
gem 'sinatra' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
applications: | |
- name: frontend | |
buildpack: ruby_buildpack | |
instances: 2 | |
host: frontend | |
domain: cloudapps.digital | |
env: | |
APP: frontend | |
- name: backend | |
buildpack: ruby_buildpack | |
instances: 2 | |
host: backend | |
domain: apps.internal | |
env: | |
APP: backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PaaS Service Discovery & Internal Networking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cf push -f manifest.yml | |
cf add-network-policy frontend \ | |
--destination-app backend \ | |
--protocol tcp \ | |
--port 8080 | |
cf restart frontend | |
cf restart backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
url="https://$(cf apps | grep frontend | awk '{print $6}')" | |
watch -d -n1 "curl --silent $url" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
grep foo | awk '{ something}'
=>awk '/foo/ { something }'