Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit 890ff87

Browse files
billimekmxschmitt
authored andcommitted
support for deployments to cloudfoundry (#116)
* support for deploying to cloudfoundry * tweaking readme
1 parent 566f2a3 commit 890ff87

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

deployments/cloudfoundry/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# golang-url-shortener on cloudfoundry
2+
3+
## configuration
4+
5+
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)
6+
1. `cp manifest-example.yml manifest.yml` and edit to meet your needs
7+
1. (optional) create any services that may be required for securing env variables or things like redis, for example:
8+
* creating a cups service to hold oauth keys: `cf create-user-provided-service gourl-oauth -p '{"githubClientID":"<some id>","githubClientSecret":"<some key>"}'`
9+
* creating a redis service for later binding: `cf create-service thd-redis default gourl-redis-service`
10+
1. (optional) modify run.sh to set `REDIS_SERVICE_NAME` to match the name of the redis service for your cloudfoundry implementation
11+
12+
## deployment
13+
14+
`cf push` or `cf push <custom app name>`

deployments/cloudfoundry/config.yaml

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
applications:
2+
- name: gourl
3+
buildpack: binary_buildpack
4+
memory: 64m
5+
command: './run.sh'
6+
instances: 1 # should not be more than 1 due to session handling
7+
health-check-type: http
8+
health-check-http-endpoint: /ok
9+
# if you use any marketplace or cups services, define the binding here
10+
# services:
11+
# - gourl-redis-service
12+
# - gourl-oauth
13+
# define any configuration settings via environment variables here (see https://github.com/mxschmitt/golang-url-shortener/wiki/Configuration)
14+
env:
15+
GUS_BASE_URL: "https://gourl.mydomain.com"
16+
GUS_BACKEND: redis
17+
GUS_SHORTED_ID_LENGTH: 5
18+
GUS_ENABLE_DEBUG_MODE: false
19+

deployments/cloudfoundry/run.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
REDIS_SERVICE_NAME="thd-redis"
4+
5+
CUPS=$(echo $VCAP_SERVICES | grep "user-provided")
6+
REDIS=$(echo $VCAP_SERVICES | grep "$REDIS_SERVICE_NAME")
7+
8+
if [ "$CUPS" != "" ]; then
9+
export GUS_GITHUB_CLIENT_ID="$(echo $VCAP_SERVICES | jq -r '.["'user-provided'"][0].credentials.githubClientID')"
10+
export GUS_GITHUB_CLIENT_SECRET="$(echo $VCAP_SERVICES | jq -r '.["'user-provided'"][0].credentials.githubClientSecret')"
11+
fi
12+
13+
if [ "$REDIS" != "" ]; then
14+
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')"
15+
export GUS_REDIS_PASSWORD="$(echo $VCAP_SERVICES | jq -r '.["'$REDIS_SERVICE_NAME'"][0].credentials.password')"
16+
fi
17+
18+
echo "#### Starting golang-url-shortener..."
19+
20+
./golang-url-shortener

0 commit comments

Comments
 (0)