File tree Expand file tree Collapse file tree 14 files changed +204
-0
lines changed
Expand file tree Collapse file tree 14 files changed +204
-0
lines changed Original file line number Diff line number Diff line change 11# capi-sidecar-samples
22
33Sample apps demonstrating how to use [ sidecar processes] ( http://v3-apidocs.cloudfoundry.org/version/release-candidate/#sidecars ) in Cloud Foundry.
4+
5+ ## Apps
6+ This repository currently contains the following sample apps and sidecars.
7+
8+ You can quickly deploy both apps by targeting your Cloud Foundry api using the ` cf cli ` and running the ` push_sample_app_with_sidecar.sh ` script.
9+
10+ ### config-server-sidecar
11+ A simple Golang binary that emulates a "configuration server" for the parent app to call out to.
12+
13+ ### sidecar-dependent-app
14+ A simple Sinatra app that calls out to the ` config-server-sidecar ` binary and echoes back its response.
Original file line number Diff line number Diff line change 1+ config-server
Original file line number Diff line number Diff line change 1+ # Sample "Config Server" Sidecar Process
2+
3+ This is a simple Golang "config server" designed to be used along with the sample ` sidecar-dependent-app ` .
4+ It listens on ` localhost:$CONFIG_SERVER_PORT/config/ ` and returns some hard coded "configuration" for the parent app to consume.
5+
6+
7+ ## Building the binary
8+ ```
9+ GOOS=linux GOARCH=amd64 go build -o config-server .
10+ ```
11+
12+ ## Running the config server
13+ ```
14+ CONFIG_SERVER_PORT=8082 ./config-server
15+ ```
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ "net/http"
7+ "os"
8+ )
9+
10+ func main () {
11+ // Emulate an external configuration service
12+ http .HandleFunc ("/config/" , config )
13+ fmt .Println ("listening..." )
14+ err := http .ListenAndServe (":" + os .Getenv ("CONFIG_SERVER_PORT" ), nil )
15+ if err != nil {
16+ panic (err )
17+ }
18+ }
19+
20+ type Config struct {
21+ Scope string
22+ Password string
23+ }
24+
25+ func config (res http.ResponseWriter , req * http.Request ) {
26+ config := Config {"some-service.admin" , "not-a-real-p4$$w0rd" }
27+
28+ js , err := json .Marshal (config )
29+ if err != nil {
30+ panic (err )
31+ }
32+
33+ fmt .Println ("Received a request for config." )
34+ fmt .Fprintln (res , string (js ))
35+ }
Original file line number Diff line number Diff line change 1+ ---
2+ applications :
3+ - env :
4+ GOPACKAGENAME : config-server
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ SAMPLE_APP_PATH=" sidecar-dependent-app"
4+ CONFIG_SERVER_SIDECAR_PATH=" config-server-sidecar"
5+
6+ function clean() {
7+ rm " ${SAMPLE_APP_PATH} /config-server"
8+ rm " ${CONFIG_SERVER_SIDECAR_PATH} /config-server"
9+ }
10+
11+ function build_config_server() {
12+ pushd ${CONFIG_SERVER_SIDECAR_PATH} > /dev/null
13+ GOOS=linux GOARCH=amd64 go build -o config-server .
14+ popd > /dev/null
15+ cp " ${CONFIG_SERVER_SIDECAR_PATH} /config-server" ${SAMPLE_APP_PATH}
16+ }
17+
18+ function push_app_with_sidecars() {
19+ pushd ${SAMPLE_APP_PATH} > /dev/null
20+ cf v3-create-app sidecar-dependent-app
21+ cf v3-apply-manifest -f manifest.yml
22+ cf v3-push sidecar-dependent-app
23+ popd > /dev/null
24+ }
25+
26+ function main() {
27+ clean
28+ build_config_server
29+ push_app_with_sidecars
30+ }
31+
32+ main
Original file line number Diff line number Diff line change 1+ config-server
Original file line number Diff line number Diff line change 1+ source "http://rubygems.org"
2+
3+ gem "sinatra"
4+ gem "json"
5+ gem "typhoeus"
6+
7+ group :test , :development do
8+ gem "rspec"
9+ gem "rack-test"
10+ end
Original file line number Diff line number Diff line change 1+ GEM
2+ remote: http://rubygems.org/
3+ specs:
4+ diff-lcs (1.3 )
5+ ethon (0.12.0 )
6+ ffi (>= 1.3.0 )
7+ ffi (1.10.0 )
8+ json (2.1.0 )
9+ mustermann (1.0.3 )
10+ rack (2.0.6 )
11+ rack-protection (2.0.4 )
12+ rack
13+ rack-test (0.8.3 )
14+ rack (>= 1.0 , < 3 )
15+ rspec (3.7.0 )
16+ rspec-core (~> 3.7.0 )
17+ rspec-expectations (~> 3.7.0 )
18+ rspec-mocks (~> 3.7.0 )
19+ rspec-core (3.7.1 )
20+ rspec-support (~> 3.7.0 )
21+ rspec-expectations (3.7.0 )
22+ diff-lcs (>= 1.2.0 , < 2.0 )
23+ rspec-support (~> 3.7.0 )
24+ rspec-mocks (3.7.0 )
25+ diff-lcs (>= 1.2.0 , < 2.0 )
26+ rspec-support (~> 3.7.0 )
27+ rspec-support (3.7.1 )
28+ sinatra (2.0.4 )
29+ mustermann (~> 1.0 )
30+ rack (~> 2.0 )
31+ rack-protection (= 2.0.4 )
32+ tilt (~> 2.0 )
33+ tilt (2.0.9 )
34+ typhoeus (1.3.1 )
35+ ethon (>= 0.9.0 )
36+
37+ PLATFORMS
38+ ruby
39+
40+ DEPENDENCIES
41+ json
42+ rack-test
43+ rspec
44+ sinatra
45+ typhoeus
46+
47+ BUNDLED WITH
48+ 1.17.3
Original file line number Diff line number Diff line change 1+ web : bundle exec rackup config.ru -p $PORT
You can’t perform that action at this time.
0 commit comments