-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicelery.py
78 lines (57 loc) · 2.45 KB
/
icelery.py
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
from flask import Flask, request
from celery import Celery
import json
from builder.command.concrete.docker import CreateBuildingContextDockerCommand
from builder.command.concrete.docker import DestroyBuildingContextDockerCommand
from builder.command.concrete.docker import BuildFromDirDockerCommand
from builder.command.concrete.docker import PushDockerCommand
from settings import host_rabbit_celery
app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'pyamqp://celery:celery@{}:5672/celery'.format(host_rabbit_celery)
#app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
@celery.task
def build_docker(data):
# repo = 'https://github.com/kinderp/testproject.git'
# destination_dir = '1232456abc'
# docker_file = data
repo = data["repo"]
destination_dir = data["target_dir"]
docker_file = data["runtime_source"]
working_branch = data["working_branch"]
print(repo)
print(destination_dir)
print(working_branch)
# What does CreateBuildingContextDockerCommand do ?
#
# 1. clone repo in reproducer.repo field
# 2. create a new branch with the same name in image.name field
# 3. create a Dockerfile in that branch
# 4. push all
print("=={}==".format("Cloning..."))
b = CreateBuildingContextDockerCommand(repo, destination_dir, docker_file, working_branch)
b.execute()
print("=={}==".format("Building..."))
# it just build an image from a Dockerfile previous created
builder = BuildFromDirDockerCommand('building/{}'.format(destination_dir), 'registry.gitlab.com/caristia/antonio_suse/new_image')
#response = [line for line in builder.execute()]
#print(response)
for line in builder.execute():
print(line)
# it just push to a docker registry
print("=={}==".format("Pushing..."))
pusher = PushDockerCommand('registry.gitlab.com/caristia/antonio_suse/new_image')
#p_response = [line for line in pusher.execute()]
#print(p_response)
for line in pusher.execute():
print(line)
# destroy current dir under teaster/builing
DestroyBuildingContextDockerCommand(destination_dir).execute()
@app.route('/build_docker', methods=['POST'])
def building_docker():
data = request.data
task = build_docker.delay(json.loads(request.data))
return ""
if __name__ == '__main__':
app.run(host='0.0.0.0', port=6000, debug=True)