diff --git a/INSTALL.md b/INSTALL.md index 71b28f6..42f2ab6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -228,17 +228,19 @@ Since Raspbian's Go compiler is version 1.0.2, we need something more up-to-date 2. Unpack it under the `piku` user like such: ```bash -su - piku -cd ~ +sudo su - piku tar -zxvf /tmp/go1.5.3.linux-arm.tar.gz +# remove unnecessary files +rm -rf go/api go/blog go/doc go/misc go/test ``` 3. Give it a temporary `GOPATH` and install `godep`: ```bash -su - piku -cd ~ -GOROOT=$HOME/go GOPATH=$HOME/golibs PATH=$PATH:$HOME/go/bin go get github.com/tools/godep +sudo su - piku +GOROOT=$HOME/go GOPATH=$HOME/gopath PATH=$PATH:$HOME/go/bin go get github.com/tools/godep +# temporary workaround until this is fixed in godep or Go 1.7(?) +GOROOT=$HOME/go GOPATH=$HOME/gopath PATH=$PATH:$HOME/go/bin go get golang.org/x/sys/unix ``` _TODO: complete this._ diff --git a/examples/golang/Godeps/Godeps.json b/examples/golang/Godeps/Godeps.json new file mode 100644 index 0000000..9dca9b3 --- /dev/null +++ b/examples/golang/Godeps/Godeps.json @@ -0,0 +1,6 @@ +{ + "ImportPath": ".", + "GoVersion": "go1.5", + "GodepVersion": "v61", + "Deps": ["github.com/labstack/echo"] +} \ No newline at end of file diff --git a/examples/golang/server.go b/examples/golang/server.go new file mode 100644 index 0000000..1ef843d --- /dev/null +++ b/examples/golang/server.go @@ -0,0 +1,16 @@ +package main + +import ( + "os" + "net/http" + "github.com/labstack/echo" + "github.com/labstack/echo/engine/standard" +) + +func main() { + e := echo.New() + e.Get("/", func(c echo.Context) error { + return c.String(http.StatusOK, "Hello, World!") + }) + e.Run(standard.New(":" + os.Getenv("PORT"))) +} \ No newline at end of file diff --git a/piku.py b/piku.py index 1fef677..18e7fe8 100644 --- a/piku.py +++ b/piku.py @@ -139,8 +139,9 @@ def do_deploy(app, deltas={}): if exists(join(app_path, 'requirements.txt')): echo("-----> Python app detected.", fg='green') deploy_python(app, deltas) - # if exists(join(app_path, 'Godeps')) or len(glob(join(app_path),'*.go')): - # Go deployment + if exists(join(app_path, 'Godeps')) or len(glob(join(app_path),'*.go')): + echo("-----> Go app detected.", fg='green') + deploy_go(app, deltas) else: echo("-----> Could not detect runtime!", fg='red') # TODO: detect other runtimes @@ -150,6 +151,33 @@ def do_deploy(app, deltas={}): echo("Error: app '%s' not found." % app, fg='red') +def deploy_go(app, deltas={}): + """Deploy a Go application""" + + go_path = join(ENV_ROOT, app) + deps = join(APP_ROOT, app, 'Godeps') + + first_time = False + if not exists(go_path): + echo("-----> Creating GOPATH for '%s'" % app, fg='green') + os.makedirs(go_path) + # copy across a pre-built GOPATH to save provisioning time + call('cp -a $HOME/gopath %s' % app, cwd=ENV_ROOT, shell=True) + first_time = True + + if exists(deps): + if first_time or getmtime(deps) > getmtime(go_path): + echo("-----> Running godep for '%s'" % app, fg='green') + env = { + 'GOPATH': '$HOME/gopath', + 'GOROOT': '$HOME/go', + 'PATH': '$PATH:$HOME/go/bin', + 'GO15VENDOREXPERIMENT': '1' + } + call('godep update ...', cwd=join(APP_ROOT, app), env=env, shell=True) + spawn_app(app, deltas) + + def deploy_python(app, deltas={}): """Deploy a Python application"""