forked from wxWidgets/Phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
132 lines (116 loc) · 4.24 KB
/
tasks.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
#----------------------------------------------------------------------
# Name: tasks.py
# Purpose: Invoke-based set of commands for dealing with wxPython's
# Docker files, images and performing wxPython builds.
#
# Author: Robin Dunn
#
# Created: 1-July-2019
# Copyright: (c) 2019 by Total Control Software
# License: wxWindows License
#----------------------------------------------------------------------
import os
import glob
from invoke import task, run
HERE = os.path.abspath(os.path.dirname(__file__))
@task(
aliases=['build_image', 'bi'],
help={
'image': 'Name of a docker image to build. May be specified more than once. Defaults to all.',
'gui': 'Build the gui version of an image instead of just the build image.',
},
iterable=['image'],
)
def build_images(ctx, image, gui=False):
"""
Build docker image(s).
"""
if image == []:
image = _get_all_distros(gui)
os.chdir(HERE)
dist=os.path.abspath('../dist')
img_type = 'gui' if gui else 'build'
for img_name in image:
# build it
ctx.run('docker build --no-cache '
'-f {type}/{name}/Dockerfile '
'-t wxpython4/{type}:{name} .'.format(name=img_name, type=img_type),
pty=True, echo=True)
# test it
ctx.run('docker run -it --rm -v {}:/dist '
'wxpython4/{}:{} hello.sh'.format(dist, img_type, img_name),
pty=True, echo=True)
@task(
help={
'image': 'Name of a docker image to push. May be specified more than once. Defaults to all.',
'gui': 'Push the gui version of an image instead of just the build image.',
},
iterable=['image'],
)
def push(ctx, image, gui=False):
"""
Push one or more images to docker hub. User should have already run
a `docker login` command.
"""
if image == []:
image = _get_all_distros(gui)
os.chdir(HERE)
img_type = 'gui' if gui else 'build'
for img_name in image:
# build it
ctx.run(
'docker push wxpython4/{type}:{name}'.format(name=img_name, type=img_type),
pty=True, echo=True)
@task(
aliases=['build_wxp', 'bwxp'],
help={
'image':'Name of a docker image to use for building. May be specified more than once. Defaults to all.',
'port': 'One of gtk2, gtk3 or all. Defaults to all.',
'venv': 'The name of a Python virtual environment to use for the build, like Py27, Py36, etc. Defaults to all.'
},
iterable=['image'],
)
def build_wxpython(ctx, image, venv='all', port='all'):
"""
Use docker images to build wxPython.
This command requires that there is a wxPython source archive in the ../dist
folder, such as one produced by `python build.py sdist` or one from a
release or snapshot build of wxPython.
"""
if image == []:
image = _get_all_distros()
os.chdir(HERE)
dist=os.path.abspath('../dist')
for img_name in image:
ctx.run('docker run -it --rm -v {}:/dist '
'wxpython4/build:{} do-build.sh {} {}'.format(dist, img_name, venv, port),
pty=True, echo=True)
@task(
help={
'image_tag':"The tag of the image to be run",
'cmd': "If given will run this command instead of the image's default command.",
'gui': "If given will run the 'gui' image insead of the 'build' image.",
'port': "Host port to use for the VNC connection.",
'keep': "Keep the container when it exits. Otherwise it will be auto-removed."
},
positional=['image_tag'],
)
def run(ctx, image_tag, cmd=None, gui=False, port=5901, keep=False):
"""
Run a wxpython docker image.
"""
os.chdir(HERE)
dist=os.path.abspath('../dist')
imgtype = 'gui' if gui else 'build'
cmd = '' if cmd is None else cmd
rm = '' if keep else '--rm'
ctx.run(
'docker run -it {} -v {}:/dist -p {}:5901 wxpython4/{}:{} {}'.format(
rm, dist, port, imgtype, image_tag, cmd),
pty=True, echo=True)
def _get_all_distros(gui):
os.chdir(HERE)
wildcard = os.path.join('gui' if gui else 'build', '*-*')
all_matching = glob.glob(wildcard)
return [os.path.basename(item) for item in all_matching]