Skip to content

Instantly share code, notes, and snippets.

@tlwr
Last active June 23, 2022 11:55
Show Gist options
  • Save tlwr/cdce75187e2e375078406bad07b26bf8 to your computer and use it in GitHub Desktop.
Save tlwr/cdce75187e2e375078406bad07b26bf8 to your computer and use it in GitHub Desktop.
PaaS service discovery example
# 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
require File.expand_path('../app.rb', __FILE__)
run Sinatra::Application
source 'https://rubygems.org'
gem 'http'
gem 'sinatra'

PaaS service discovery example

  1. Save the files in the gist
  2. Run chmod +x push.sh && . !$
  3. Run chmod +x test.sh && . !$
---
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
PaaS Service Discovery & Internal Networking
#!/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
#!/usr/bin/env bash
url="https://$(cf apps | grep frontend | awk '{print $6}')"
watch -d -n1 "curl --silent $url"
@rhowe-gds
Copy link

grep foo | awk '{ something}' => awk '/foo/ { something }'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment