# -*- coding: utf-8 -*-

# Copyright 2012 tsuru authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import os
from fabric.api import abort, cd, env, local, put, run

current_dir = os.path.abspath(os.path.dirname(__file__))
env.user = 'ubuntu'
env.tsuru_path = '/home/%s/tsuru' % env.user


def build():
    goos = local("go env GOOS", capture=True)
    goarch = local("go env GOARCH", capture=True)
    if goos != "linux" or goarch != "amd64":
        abort("tsuru must be built on linux_amd64 for deployment, you're on %s_%s" % (goos, goarch))
    local("mkdir -p dist")
    local("go clean ./...")
    local("go build -a -o dist/collector ./collector")
    local("go build -a -o dist/webserver ./api/webserver")


def clean():
    local("rm -rf dist")
    local("rm -f dist.tar.gz")


def send():
    local("tar -czf dist.tar.gz dist")
    run("mkdir -p %(tsuru_path)s" % env)
    put(os.path.join(current_dir, "dist.tar.gz"), env.tsuru_path)


def restart():
    with cd(env.tsuru_path):
        run("tar -xzf dist.tar.gz")
    run("circusctl restart web")
    run("circusctl restart collector")


def deploy():
    build()
    send()
    restart()
    clean()

# -*- coding: utf-8 -*-

# Copyright 2012 tsuru authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import os
from fabric.api import abort, cd, env, local, put, run

current_dir = os.path.abspath(os.path.dirname(__file__))
env.user = 'ubuntu'
env.tsuru_path = '/home/%s/tsuru' % env.user


def build():
    goos = local("go env GOOS", capture=True)
    goarch = local("go env GOARCH", capture=True)
    if goos != "linux" or goarch != "amd64":
        abort("tsuru must be built on linux_amd64 for deployment, " +
              "you're on %s_%s" % (goos, goarch))
    local("mkdir -p dist")
    local("go clean ./...")
    local("go build -a -o dist/collector ./collector")
    local("go build -a -o dist/webserver ./api/webserver")


def clean():
    local("rm -rf dist")
    local("rm -f dist.tar.gz")


def send():
    local("tar -czf dist.tar.gz dist")
    run("mkdir -p %(tsuru_path)s" % env)
    put(os.path.join(current_dir, "dist.tar.gz"), env.tsuru_path)


def restart():
    with cd(env.tsuru_path):
        run("tar -xzf dist.tar.gz")
    run("circusctl restart web")
    run("circusctl restart collector")


def deploy():
    build()
    send()
    restart()
    clean()

fix pep8 issue