attempting to find a sane model for Golang

feature/go
Rui Carmo 2016-04-06 23:56:49 +01:00
rodzic 069e4dc20e
commit c77bc91d36
4 zmienionych plików z 59 dodań i 7 usunięć

Wyświetl plik

@ -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._

6
examples/golang/Godeps/Godeps.json wygenerowano 100644
Wyświetl plik

@ -0,0 +1,6 @@
{
"ImportPath": ".",
"GoVersion": "go1.5",
"GodepVersion": "v61",
"Deps": ["github.com/labstack/echo"]
}

Wyświetl plik

@ -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")))
}

32
piku.py
Wyświetl plik

@ -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"""