Skip to content

Instantly share code, notes, and snippets.

@elimisteve
Forked from mrosset/build
Last active December 10, 2015 11:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save elimisteve/4427866 to your computer and use it in GitHub Desktop.
Save elimisteve/4427866 to your computer and use it in GitHub Desktop.
`build`, `start`, and `stop` scripts for getting Go web apps to run on OpenShift. Put these files in the `.openshift/action_hooks/` directory of your app.
#!/bin/bash
# This is a simple build script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the deploy step. This script gets executed directly, so it
# could be python, php, ruby, etc.
tarball="https://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz"
# Set GOROOT since we don't use GOROOT_FINAL
mkdir -p $OPENSHIFT_HOMEDIR/app-root/data/go
export GOROOT=$OPENSHIFT_HOMEDIR/app-root/data/go
# GOPATH can be our repo dir.
export GOPATH=$OPENSHIFT_REPO_DIR
# If we do not have a go dir, download and extract dist tarball
if ! test -d "$GOROOT"; then
curl -# $tarball | tar xz -C $(dirname "$GOROOT")
fi
export GO=$GOROOT/bin/go
export GOAPP_SRC_FILE=$OPENSHIFT_REPO_DIR/goapp.go
# Install dependencies
$GO list -f '{{range .Imports}}{{.}}
{{end}}' $GOAPP_SRC_FILE | xargs $GO get
# Build app
$GO build $GOAPP_SRC_FILE
#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080
nohup ./goapp >> $OPENSHIFT_HOMEDIR/diy-0.1/logs/server.log 2>&1 &
#!/bin/bash
# The logic to stop your application should be put in this script.
kill `ps -ef | grep goapp | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment