Skip to content

Commit

Permalink
Add working demo
Browse files Browse the repository at this point in the history
  • Loading branch information
pburkholder committed Sep 17, 2024
1 parent adadc77 commit 3ae820d
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 226 deletions.
225 changes: 1 addition & 224 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,224 +1 @@
# General Files
*.log
*.tmp
*.bak
*.swp
*.swo
.DS_Store
Thumbs.db
Desktop.ini
._*
.Trashes
.Spotlight-V100
.TemporaryItems
.Trash-*
*.pid
*.pid.lock
*.seed
*.db
*.dbmdl
*.tlog
*.tmproj
*.tmp_proj
*.un~
*.user
*.userosscache
*.userprefs
*.vbproj.user
*.vssscc
*.vspscc
*.suo
*.cache
*.csproj.user
*.sln.docstates
*.iws

# Byte-compiled / Optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.so

# Distribution / Packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE / Editor Configurations
/.idea/
*.iml
/.vscode/
*.code-workspace
*.sublime-project
*.sublime-workspace
/.vs/
/.atom/
/.eclipse/
/.netbeans/
/.intellij/
/.jbuilder/
/.rubymine/
/.mine/
/.textmate/
/.vim/
/.emacs.d/
*.sw*

# Security - Sensitive files
*.pem
*.key
*.crt
*.csr
*.gpg
*.asc
.secret
*.vault
*.token
*.apikey
*.credentials
secrets.yml
credentials.yml
config/dev.yml
config/private.yml

# Dependency Directories
/node_modules/
/bower_components/
/.jekyll-cache/
/vendor/

# Go specific
/bin/
/pkg/
*.o
*.a
*.out
**/vendor/
Gopkg.lock
Gopkg.toml
go.sum
go.mod

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Ruby specific
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.gem
*.rbc
.capistrano/
.rspec
.ruby-version
.ruby-gemset
# Ignore Byebug command history file.
.byebug_history

# Cloud Foundry specific
manifest.yml
manifest-*.yml
*.env
*.vars.yml
*.vars-*.yml
/deployments/

# BOSH specific
*.release
/releases/
/dev_releases/
/.dev_builds/
/blobs/
/config/
/private.yml
*.tgz

# Concourse specific
/fly-*
/concourse-*
/pipelines/
/tasks/
/groups/
/resources/

# Logs, Databases, and Configuration Files
*.log
*.sql
*.sqlite
*.sqlite3
/log/
*.env*
**/log/*.log
**/log/*.log*

# OS Generated Files
.DS_Store
.DS_Store?
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Build Artifacts and Directories
/dist/
/tmp/
/out/
/build/
/target/
/coverage/
/Release/
/Debug/
/x64/
/x86/
*.lock
*.DS_Store
*.tgz
/.terraform/

# Certificates and Keys
*.csr
*.crt
*.key
*.pem
*.pfx

# System and Miscellaneous
$RECYCLE.BIN/
$tf/
sample-app/
45 changes: 45 additions & 0 deletions 1_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail

export DOMAIN=app.cloud.gov

fail() {
echo $@
exit 1
}

if [ -z "${APP_NAME}" ]; then
fail "Must set base APP_NAME environment variable"
fi

cf check-route $DOMAIN --hostname $APP_NAME |
grep -q 'Route.*does not exist' || fail "APP_NAME $APP_NAME is already taken, try again"

# reserve route for later use
cf create-route $DOMAIN --hostname $APP_NAME

[ -r sample-app/manifest.yml ] || git clone https://github.com/cloudfoundry-tutorials/sample-app.git ./sample-app


A_APP_NAME="a-${APP_NAME}"
cf push "${A_APP_NAME}" --path ./sample-app -f app_manifest.yml \
--var app_name="${A_APP_NAME}" --var test_var=TEST_A

B_APP_NAME="b-${APP_NAME}"
cf push "${B_APP_NAME}" --path ./sample-app -f app_manifest.yml \
--var app_name="${B_APP_NAME}" --var test_var=TEST_B


echo "We can cheat A/B testing by mapping both hosts to the same route"
set -x
cf map-route ${A_APP_NAME} $DOMAIN --hostname ${APP_NAME}-x
cf map-route ${B_APP_NAME} $DOMAIN --hostname ${APP_NAME}-x
set +x

echo ========================================
echo "Visit https://${APP_NAME}-x.app.cloud.gov"
echo "Then run "2_demo.sh"
echo ========================================
exit 0
19 changes: 19 additions & 0 deletions 2_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail

export DOMAIN=app.cloud.gov

fail() {
echo $@
exit 1
}

if [ -z "${APP_NAME}" ]; then
fail "Must set base APP_NAME environment variable"
fi

cf push $APP_NAME -f proxy/manifest.yml --path proxy --var proxy-app-name="${APP_NAME}"

echo "Now visit https://$APP_NAME.$DOMAIN"

exit 0
16 changes: 16 additions & 0 deletions 3_fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail

export DOMAIN=app.cloud.gov

fail() {
echo $@
exit 1
}

if [ -z "${APP_NAME}" ]; then
fail "Must set base APP_NAME environment variable"
fi

cf add-network-policy $APP_NAME a-${APP_NAME} --protocol tcp --port 8080
cf add-network-policy $APP_NAME b-${APP_NAME} --protocol tcp --port 8080
1 change: 1 addition & 0 deletions 4_testing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
watch -n 1 -d "curl -s https://$APP_NAME.app.cloud.gov | grep TRAINING"
14 changes: 14 additions & 0 deletions 5_reweight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

export DOMAIN=app.cloud.gov

fail() {
echo $@
exit 1
}

set -x
cf set-env $APP_NAME WEIGHTING "80% version_a; * version_b;"
cf restart $APP_NAME
set +x
14 changes: 14 additions & 0 deletions 6_all_b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

export DOMAIN=app.cloud.gov

fail() {
echo $@
exit 1
}

set -x
cf set-env $APP_NAME WEIGHTING "100% version_b; * version_a;"
cf restage --strategy rolling $APP_NAME
set +x
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
# Github templates
# Sample app

This repo contains Github templates (pull request, issue, etc) for the cloud-gov organization.
This is a sample application written in Go used for training purposes.

## Demonstrating A/B Testing

1. Show two apps pushed to the same route, that differ only in their env variable:

```
git checkout tags/works-w-simple-routing
# update manifests to have non-conflictint routes
for i in a_manifest.yml b_manifest.yml ; do cf push -f $i; done
```

Reload route and you'll see the apps getting cycles.

Problem: These are balanced 50/50. Also, no session persisten

2. Use a proxy


cf add-network-policy pb-ab-test sample-app-a --protocol tcp --port 8080-8443
cf add-network-policy pb-ab-test sample-app-b --protocol tcp --port 8080-8443


cf network-policies | awk 'f;/source/{f=1}' | awk '{printf "cf remove-network-policy %s %s --protocol %s --port %s\n", $1, $2, $3, $4}'

# README

This project demonstrates hosting a private intranet application on cloud.gov using Cloud Foundry's Route Service feature.

```mermaid
flowchart LR
subgraph "Cloud.gov"
direction LR
lb["Load Balancers"]
rtr["Routers"]
proxy["Weighted Proxy Service)"]
app_a["app_a.apps.internal"]
app_b["app_b.apps.internal"]
lb --> rtr
rtr --> proxy
proxy --> app_a
proxy --> app_b
end
```

## Requirements

Install and log into the [Cloud Foundry CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html).
Loading

0 comments on commit 3ae820d

Please sign in to comment.