aboutsummaryrefslogtreecommitdiff
blob: 83eeda2178bb461ba93c5a324d2a53356aa39246 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

from twisted.internet import defer

from buildbot.plugins import worker, util

@util.renderer
def log_docker_images(props):
    return 'bb-worker-log' + ':latest'

@util.renderer
def docker_volumes(props):
    volumes_list = []
    #FIXME: set in master.cfg /srv/gentoo/portage/
    src_dir = '/srv/gentoo/portage/' + props.getProperty('project_uuid')
    dest_dir = '/var/cache/portage'
    #add distdir
    volumes_list.append(src_dir + '/distfiles' + ':' + dest_dir + '/distfiles')
    #add bindir
    volumes_list.append(src_dir + '/packages' + ':' + dest_dir + '/packages')
    return volumes_list

#NOTE: source permission set to user/group buildbot
@util.renderer
def docker_volumes_repositorys(props):
    volumes_list = []
    #FIXME: set in master.cfg /srv/gentoo/portage/repos
    src_dir = '/srv/gentoo/portage/repos'
    #FIXME: set to getProperty('builddir') + repositorys
    dest_dir = '/var/lib/buildbot_worker/repositorys'
    #add distdir
    volumes_list.append(':'.join([src_dir, dest_dir]))
    return volumes_list

@util.renderer
@defer.inlineCallbacks
def getDockerHost(props, docker_worker):
    print(docker_worker)
    gentooci = props.master.namedServices['services'].namedServices['gentooci']
    worker_data = yield gentooci.db.workers.getWorkerByUuid(docker_worker['uuid'])
    node = yield gentooci.db.workers.getNodeByWorkerUuid(worker_data['uuid'])
    node_data = yield gentooci.db.workers.getNodeByUuid(node['node_uuid'])
    print(worker_data)
    print(node_data)
    return node_data['docker_host_url']

@util.renderer
@defer.inlineCallbacks
def GetBuildDockerImage(props, docker_worker):
    gentooci = props.master.namedServices['services'].namedServices['gentooci']
    worker_data = yield gentooci.db.workers.getWorkerByUuid(docker_worker['uuid'])
    image_data = yield gentooci.db.workers.getImageById(worker_data['image_id'])
    print(image_data)
    return image_data['tag']

def gentoo_workers(worker_data):
    w = []
    for local_worker in worker_data['local']:
        if local_worker['enable']:
            w.append(worker.LocalWorker(local_worker['name']))
    # node workers
    for node_worker in worker_data['node']:
        if node_worker['enable']:
            w.append(worker.Worker(node_worker['uuid'], node_worker['password']))
    # docker workers
    docker_hostconfig = {}
    # For use of sandbox stuff
    # FEATURES="ipc-sandbox network-sandbox pid-sandbox"
    docker_hostconfig['cap_add'] = ['SYS_ADMIN', 'NET_ADMIN', 'SYS_PTRACE']
    # libseccomp overhead
    # https://github.com/seccomp/libseccomp/issues/153
    docker_hostconfig['security_opt'] = ['seccomp=unconfined']
    print(worker_data['docker'])
    for docker_worker in worker_data['docker']:
        #FIXME: get settings from db
        if docker_worker['type'] == 'build':
            w.append(worker.DockerLatentWorker(docker_worker['uuid'],
                            None,
                            docker_host=getDockerHost.withArgs(docker_worker),
                            image=GetBuildDockerImage.withArgs(docker_worker),
                            volumes=docker_volumes,
                            hostconfig=docker_hostconfig,
                            followStartupLogs=True,
                            masterFQDN='192.168.1.5',
                            build_wait_timeout=3600
                            ))
        if docker_worker['type'] == 'log':
            w.append(worker.DockerLatentWorker(docker_worker['uuid'],
                            None,
                            docker_host='tcp://192.168.1.12:2375',
                            image=log_docker_images,
                            #volumes=docker_volumes_repositorys,
                            hostconfig=docker_hostconfig,
                            followStartupLogs=True,
                            masterFQDN='192.168.1.5',
                            build_wait_timeout=600
                            ))
    return w