From 890ff87a9ca8c9b7c366aabed73534e9174b736b Mon Sep 17 00:00:00 2001 From: Jeff Billimek Date: Thu, 9 Aug 2018 07:21:17 -0400 Subject: [PATCH] support for deployments to cloudfoundry (#116) * support for deploying to cloudfoundry * tweaking readme --- deployments/cloudfoundry/README.md | 14 +++++++++++++ deployments/cloudfoundry/config.yaml | 0 deployments/cloudfoundry/manifest-example.yml | 19 ++++++++++++++++++ deployments/cloudfoundry/run.sh | 20 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 deployments/cloudfoundry/README.md create mode 100644 deployments/cloudfoundry/config.yaml create mode 100644 deployments/cloudfoundry/manifest-example.yml create mode 100755 deployments/cloudfoundry/run.sh diff --git a/deployments/cloudfoundry/README.md b/deployments/cloudfoundry/README.md new file mode 100644 index 0000000..c6128f9 --- /dev/null +++ b/deployments/cloudfoundry/README.md @@ -0,0 +1,14 @@ +# golang-url-shortener on cloudfoundry + +## configuration + +1. Either compile or download the linux amd64 binary and copy it into this directory (e.g. `cp ../../releases/golang-url-shortener_linux_amd64/golang-url-shortener .` if you compiled it yourself via make) +1. `cp manifest-example.yml manifest.yml` and edit to meet your needs +1. (optional) create any services that may be required for securing env variables or things like redis, for example: + * creating a cups service to hold oauth keys: `cf create-user-provided-service gourl-oauth -p '{"githubClientID":"","githubClientSecret":""}'` + * creating a redis service for later binding: `cf create-service thd-redis default gourl-redis-service` +1. (optional) modify run.sh to set `REDIS_SERVICE_NAME` to match the name of the redis service for your cloudfoundry implementation + +## deployment + +`cf push` or `cf push ` \ No newline at end of file diff --git a/deployments/cloudfoundry/config.yaml b/deployments/cloudfoundry/config.yaml new file mode 100644 index 0000000..e69de29 diff --git a/deployments/cloudfoundry/manifest-example.yml b/deployments/cloudfoundry/manifest-example.yml new file mode 100644 index 0000000..50cc97e --- /dev/null +++ b/deployments/cloudfoundry/manifest-example.yml @@ -0,0 +1,19 @@ +applications: +- name: gourl + buildpack: binary_buildpack + memory: 64m + command: './run.sh' + instances: 1 # should not be more than 1 due to session handling + health-check-type: http + health-check-http-endpoint: /ok + # if you use any marketplace or cups services, define the binding here + # services: + # - gourl-redis-service + # - gourl-oauth + # define any configuration settings via environment variables here (see https://github.com/mxschmitt/golang-url-shortener/wiki/Configuration) + env: + GUS_BASE_URL: "https://gourl.mydomain.com" + GUS_BACKEND: redis + GUS_SHORTED_ID_LENGTH: 5 + GUS_ENABLE_DEBUG_MODE: false + \ No newline at end of file diff --git a/deployments/cloudfoundry/run.sh b/deployments/cloudfoundry/run.sh new file mode 100755 index 0000000..3f8c1f6 --- /dev/null +++ b/deployments/cloudfoundry/run.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +REDIS_SERVICE_NAME="thd-redis" + +CUPS=$(echo $VCAP_SERVICES | grep "user-provided") +REDIS=$(echo $VCAP_SERVICES | grep "$REDIS_SERVICE_NAME") + +if [ "$CUPS" != "" ]; then + export GUS_GITHUB_CLIENT_ID="$(echo $VCAP_SERVICES | jq -r '.["'user-provided'"][0].credentials.githubClientID')" + export GUS_GITHUB_CLIENT_SECRET="$(echo $VCAP_SERVICES | jq -r '.["'user-provided'"][0].credentials.githubClientSecret')" +fi + +if [ "$REDIS" != "" ]; then + export GUS_REDIS_HOST="$(echo $VCAP_SERVICES | jq -r '.["'$REDIS_SERVICE_NAME'"][0].credentials.host'):$(echo $VCAP_SERVICES | jq -r '.["'$REDIS_SERVICE_NAME'"][0].credentials.port')" + export GUS_REDIS_PASSWORD="$(echo $VCAP_SERVICES | jq -r '.["'$REDIS_SERVICE_NAME'"][0].credentials.password')" +fi + +echo "#### Starting golang-url-shortener..." + +./golang-url-shortener