summaryrefslogtreecommitdiffhomepage
path: root/test/lib/fabfile.py
blob: c50b7e22b353e9a534f370c4542e839d774be057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
from fabric import task
from invoke import run as local
from base import CmdBuffer


@task
def make_gobgp_ctn(ctx, tag='gobgp',
                   local_gobgp_path='',
                   from_image='osrg/quagga'):
    if local_gobgp_path == '':
        local_gobgp_path = os.getcwd()

    c = CmdBuffer()
    c << 'FROM {0}'.format(from_image)
    c << 'ENV GO111MODULE on'
    c << 'ADD gobgp /tmp/gobgp'
    c << 'RUN cd /tmp/gobgp && go install ./cmd/gobgpd ./cmd/gobgp'

    rindex = local_gobgp_path.rindex('gobgp')
    if rindex < 0:
        raise Exception('{0} seems not gobgp dir'.format(local_gobgp_path))

    workdir = local_gobgp_path[:rindex]
    os.chdir(workdir)
    local('echo \'{0}\' > Dockerfile'.format(str(c)))
    local('docker build -t {0} .'.format(tag))
    local('rm Dockerfile')