Show More
@@ -0,0 +1,111 b'' | |||||
|
1 | #!/usr/bin/env python3 | |||
|
2 | # | |||
|
3 | # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> | |||
|
4 | # | |||
|
5 | # This software may be used and distributed according to the terms of the | |||
|
6 | # GNU General Public License version 2 or any later version. | |||
|
7 | ||||
|
8 | import argparse | |||
|
9 | import pathlib | |||
|
10 | import shutil | |||
|
11 | import subprocess | |||
|
12 | import sys | |||
|
13 | ||||
|
14 | def get_docker() -> str: | |||
|
15 | docker = shutil.which('docker.io') or shutil.which('docker') | |||
|
16 | if not docker: | |||
|
17 | print('could not find docker executable') | |||
|
18 | return 1 | |||
|
19 | ||||
|
20 | try: | |||
|
21 | out = subprocess.check_output([docker, '-h'], stderr=subprocess.STDOUT) | |||
|
22 | ||||
|
23 | if b'Jansens' in out: | |||
|
24 | print('%s is the Docking System Tray; try installing docker.io' % | |||
|
25 | docker) | |||
|
26 | sys.exit(1) | |||
|
27 | except subprocess.CalledProcessError as e: | |||
|
28 | print('error calling `%s -h`: %s' % (docker, e.output)) | |||
|
29 | sys.exit(1) | |||
|
30 | ||||
|
31 | out = subprocess.check_output([docker, 'version'], | |||
|
32 | stderr=subprocess.STDOUT) | |||
|
33 | ||||
|
34 | lines = out.splitlines() | |||
|
35 | if not any(l.startswith((b'Client:', b'Client version:')) for l in lines): | |||
|
36 | print('`%s version` does not look like Docker' % docker) | |||
|
37 | sys.exit(1) | |||
|
38 | ||||
|
39 | if not any(l.startswith((b'Server:', b'Server version:')) for l in lines): | |||
|
40 | print('`%s version` does not look like Docker' % docker) | |||
|
41 | sys.exit(1) | |||
|
42 | ||||
|
43 | return docker | |||
|
44 | ||||
|
45 | def get_dockerfile(path: pathlib.Path, args: list) -> bytes: | |||
|
46 | with path.open('rb') as fh: | |||
|
47 | df = fh.read() | |||
|
48 | ||||
|
49 | for k, v in args: | |||
|
50 | df = df.replace(b'%%%s%%' % k, v) | |||
|
51 | ||||
|
52 | return df | |||
|
53 | ||||
|
54 | def build_docker_image(dockerfile: pathlib.Path, params: list, tag: str): | |||
|
55 | """Build a Docker image from a templatized Dockerfile.""" | |||
|
56 | docker = get_docker() | |||
|
57 | ||||
|
58 | dockerfile_path = pathlib.Path(dockerfile) | |||
|
59 | ||||
|
60 | dockerfile = get_dockerfile(dockerfile_path, params) | |||
|
61 | ||||
|
62 | print('building Dockerfile:') | |||
|
63 | print(dockerfile.decode('utf-8', 'replace')) | |||
|
64 | ||||
|
65 | args = [ | |||
|
66 | docker, | |||
|
67 | 'build', | |||
|
68 | '--build-arg', 'http_proxy', | |||
|
69 | '--build-arg', 'https_proxy', | |||
|
70 | '--tag', tag, | |||
|
71 | '-', | |||
|
72 | ] | |||
|
73 | ||||
|
74 | print('executing: %r' % args) | |||
|
75 | subprocess.run(args, input=dockerfile, check=True) | |||
|
76 | ||||
|
77 | def command_build(args): | |||
|
78 | build_args = [] | |||
|
79 | for arg in args.build_arg: | |||
|
80 | k, v = arg.split('=', 1) | |||
|
81 | build_args.append((k.encode('utf-8'), v.encode('utf-8'))) | |||
|
82 | ||||
|
83 | build_docker_image(pathlib.Path(args.dockerfile), | |||
|
84 | build_args, | |||
|
85 | args.tag) | |||
|
86 | ||||
|
87 | def command_docker(args): | |||
|
88 | print(get_docker()) | |||
|
89 | ||||
|
90 | def main() -> int: | |||
|
91 | parser = argparse.ArgumentParser() | |||
|
92 | ||||
|
93 | subparsers = parser.add_subparsers(title='subcommands') | |||
|
94 | ||||
|
95 | build = subparsers.add_parser('build', help='Build a Docker image') | |||
|
96 | build.set_defaults(func=command_build) | |||
|
97 | build.add_argument('--build-arg', action='append', default=[], | |||
|
98 | help='Substitution to perform in Dockerfile; ' | |||
|
99 | 'format: key=value') | |||
|
100 | build.add_argument('dockerfile', help='path to Dockerfile to use') | |||
|
101 | build.add_argument('tag', help='Tag to apply to created image') | |||
|
102 | ||||
|
103 | docker = subparsers.add_parser('docker-path', help='Resolve path to Docker') | |||
|
104 | docker.set_defaults(func=command_docker) | |||
|
105 | ||||
|
106 | args = parser.parse_args() | |||
|
107 | ||||
|
108 | return args.func(args) | |||
|
109 | ||||
|
110 | if __name__ == '__main__': | |||
|
111 | sys.exit(main()) |
@@ -1,21 +1,21 b'' | |||||
1 | #!/bin/bash -eu |
|
1 | #!/bin/bash -eu | |
2 |
|
2 | |||
3 | . $(dirname $0)/dockerlib.sh |
|
|||
4 | . $(dirname $0)/packagelib.sh |
|
3 | . $(dirname $0)/packagelib.sh | |
5 |
|
4 | |||
6 | BUILDDIR=$(dirname $0) |
|
5 | BUILDDIR=$(dirname $0) | |
7 | export ROOTDIR=$(cd $BUILDDIR/../.. > /dev/null; pwd) |
|
6 | export ROOTDIR=$(cd $BUILDDIR/../.. > /dev/null; pwd) | |
8 |
|
7 | |||
9 | checkdocker |
|
|||
10 |
|
||||
11 | DISTID="$1" |
|
8 | DISTID="$1" | |
12 | CODENAME="$2" |
|
9 | CODENAME="$2" | |
13 | PLATFORM="$1-$2" |
|
10 | PLATFORM="$1-$2" | |
14 | shift; shift # extra params are passed to build process |
|
11 | shift; shift # extra params are passed to build process | |
15 |
|
12 | |||
16 | OUTPUTDIR=${OUTPUTDIR:=$ROOTDIR/packages/$PLATFORM} |
|
13 | OUTPUTDIR=${OUTPUTDIR:=$ROOTDIR/packages/$PLATFORM} | |
|
14 | CONTAINER=hg-docker-$PLATFORM | |||
17 |
|
15 | |||
18 | initcontainer $PLATFORM |
|
16 | DOCKER=$($BUILDDIR/hg-docker docker-path) | |
|
17 | ||||
|
18 | $BUILDDIR/hg-docker build $BUILDDIR/docker/$PLATFORM $CONTAINER | |||
19 |
|
19 | |||
20 | # debuild only appears to be able to save built debs etc to .., so we |
|
20 | # debuild only appears to be able to save built debs etc to .., so we | |
21 | # have to share the .. of the current directory with the docker |
|
21 | # have to share the .. of the current directory with the docker |
@@ -1,16 +1,16 b'' | |||||
1 | #!/bin/bash -e |
|
1 | #!/bin/bash -e | |
2 |
|
2 | |||
3 | . $(dirname $0)/dockerlib.sh |
|
|||
4 |
|
||||
5 | BUILDDIR=$(dirname $0) |
|
3 | BUILDDIR=$(dirname $0) | |
6 | export ROOTDIR=$(cd $BUILDDIR/../..; pwd) |
|
4 | export ROOTDIR=$(cd $BUILDDIR/../..; pwd) | |
7 |
|
5 | |||
8 | checkdocker |
|
|||
9 |
|
||||
10 | PLATFORM="$1" |
|
6 | PLATFORM="$1" | |
11 | shift # extra params are passed to buildrpm |
|
7 | shift # extra params are passed to buildrpm | |
12 |
|
8 | |||
13 | initcontainer $PLATFORM |
|
9 | DOCKER=$($BUILDDIR/hg-docker docker-path) | |
|
10 | ||||
|
11 | CONTAINER=hg-docker-$PLATFORM | |||
|
12 | ||||
|
13 | $BUILDDIR/hg-docker build $BUILDDIR/docker/$PLATFORM $CONTAINER | |||
14 |
|
14 | |||
15 | RPMBUILDDIR=$ROOTDIR/packages/$PLATFORM |
|
15 | RPMBUILDDIR=$ROOTDIR/packages/$PLATFORM | |
16 | $ROOTDIR/contrib/packaging/buildrpm --rpmbuilddir $RPMBUILDDIR --prepare $* |
|
16 | $ROOTDIR/contrib/packaging/buildrpm --rpmbuilddir $RPMBUILDDIR --prepare $* |
@@ -20,6 +20,7 b' outputs, which should be fixed later.' | |||||
20 | > -X setup.py \ |
|
20 | > -X setup.py \ | |
21 | > -X contrib/debugshell.py \ |
|
21 | > -X contrib/debugshell.py \ | |
22 | > -X contrib/hgweb.fcgi \ |
|
22 | > -X contrib/hgweb.fcgi \ | |
|
23 | > -X contrib/packaging/hg-docker \ | |||
23 | > -X contrib/python-zstandard/ \ |
|
24 | > -X contrib/python-zstandard/ \ | |
24 | > -X contrib/win32/hgwebdir_wsgi.py \ |
|
25 | > -X contrib/win32/hgwebdir_wsgi.py \ | |
25 | > -X doc/gendoc.py \ |
|
26 | > -X doc/gendoc.py \ |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now