|
1 | | -#!/usr/bin/env python |
| 1 | +#!/usr/bin/env python3 |
2 | 2 |
|
| 3 | +import os |
3 | 4 | import subprocess |
4 | 5 | import getpass |
| 6 | +import requests |
| 7 | +import tempfile |
| 8 | + |
| 9 | +from urllib.parse import urljoin |
| 10 | +from urllib.request import urlopen |
5 | 11 |
|
6 | 12 | DOCKER_ID = 'pathman' |
7 | | -pg_versions = ['9.5','9.6','10'] |
| 13 | +ALPINE_BASE_URL = 'https://raw.githubusercontent.com/docker-library/postgres/master/10/alpine/' |
| 14 | +ALPINE_ENTRYPOINT = 'docker-entrypoint.sh' |
| 15 | +ALPINE_PATCH = b''' |
| 16 | +--- Dockerfile 2017-07-25 12:43:20.424984422 +0300 |
| 17 | ++++ Dockerfile 2017-07-25 12:46:10.279267520 +0300 |
| 18 | +@@ -86,6 +86,7 @@ |
| 19 | + --enable-integer-datetimes \\ |
| 20 | + --enable-thread-safety \\ |
| 21 | + --enable-tap-tests \\ |
| 22 | ++ --enable-cassert \\ |
| 23 | + # skip debugging info -- we want tiny size instead |
| 24 | + # --enable-debug \\ |
| 25 | + --disable-rpath \\ |
| 26 | +
|
| 27 | +''' |
| 28 | +CUSTOM_IMAGE_NAME = "%s/postgres_stable" % DOCKER_ID |
| 29 | + |
| 30 | +def make_alpine_image(image_name): |
| 31 | + dockerfile = urlopen(urljoin(ALPINE_BASE_URL, 'Dockerfile')).read() |
| 32 | + entrypoint_sh = urlopen(urljoin(ALPINE_BASE_URL, ALPINE_ENTRYPOINT)).read() |
| 33 | + |
| 34 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 35 | + print("Creating build in %s" % tmpdir) |
| 36 | + patch_name = os.path.join(tmpdir, "cassert.patch") |
| 37 | + |
| 38 | + with open(os.path.join(tmpdir, 'Dockerfile'), 'w') as f: |
| 39 | + f.write(dockerfile.decode()) |
| 40 | + |
| 41 | + with open(os.path.join(tmpdir, ALPINE_ENTRYPOINT), 'w') as f: |
| 42 | + f.write(entrypoint_sh.decode()) |
| 43 | + |
| 44 | + with open(patch_name, 'w') as f: |
| 45 | + f.write(ALPINE_PATCH.decode()) |
| 46 | + |
| 47 | + with open(patch_name, 'r') as f: |
| 48 | + p = subprocess.Popen(["patch", "-p0"], cwd=tmpdir, stdin=subprocess.PIPE) |
| 49 | + p.communicate(str.encode(f.read())) |
| 50 | + print("patch applied") |
| 51 | + subprocess.check_output(["docker", "build", ".", '-t', image_name], cwd=tmpdir) |
| 52 | + print("build ok: ", image_name) |
| 53 | + subprocess.check_output(['docker', 'push', image_name], |
| 54 | + stderr=subprocess.STDOUT) |
| 55 | + print("upload ok:", image_name) |
| 56 | + |
| 57 | +make_alpine_image(CUSTOM_IMAGE_NAME) |
| 58 | + |
| 59 | +pg_containers = [ |
| 60 | + ('pg95', 'postgres:9.5-alpine'), |
| 61 | + ('pg96', 'postgres:9.6-alpine'), |
| 62 | + ('pg10', 'postgres:10-alpine'), |
| 63 | + ('pg10_ca', CUSTOM_IMAGE_NAME), |
| 64 | +] |
8 | 65 |
|
9 | 66 | image_types = { |
10 | 67 | 'clang_check_code': { |
|
30 | 87 | travis_conf = [] |
31 | 88 | print("") |
32 | 89 |
|
33 | | -for pg_version in pg_versions: |
34 | | - pgname = 'pg%s' % pg_version.replace('.', '') |
35 | | - for key, variables in image_types.items(): |
36 | | - image_name = '%s/%s_%s' % (DOCKER_ID, pgname, key) |
37 | | - with open('Dockerfile', 'w') as out: |
38 | | - with open('Dockerfile.tmpl', 'r') as f: |
39 | | - for line in f: |
40 | | - line = line.replace('${PG_VERSION}', pg_version) |
41 | | - for key, value in variables.items(): |
42 | | - varname = '${%s}' % key |
43 | | - line = line.replace(varname, value) |
44 | | - |
45 | | - out.write(line) |
46 | | - |
47 | | - args = [ |
48 | | - 'docker', |
49 | | - 'build', |
50 | | - '-t', image_name, |
51 | | - '.' |
52 | | - ] |
53 | | - subprocess.check_output(args, stderr=subprocess.STDOUT) |
54 | | - print("build ok:", image_name) |
55 | | - subprocess.check_output(['docker', 'push', image_name], |
56 | | - stderr=subprocess.STDOUT) |
57 | | - print("upload ok:", image_name) |
58 | | - travis_conf.append(travis_conf_line % image_name) |
| 90 | +if __name__ == '__main__': |
| 91 | + for pgname, container in pg_containers: |
| 92 | + for key, variables in image_types.items(): |
| 93 | + image_name = '%s/%s_%s' % (DOCKER_ID, pgname, key) |
| 94 | + with open('Dockerfile', 'w') as out: |
| 95 | + with open('Dockerfile.tmpl', 'r') as f: |
| 96 | + for line in f: |
| 97 | + line = line.replace('${PG_IMAGE}', container) |
| 98 | + for key, value in variables.items(): |
| 99 | + varname = '${%s}' % key |
| 100 | + line = line.replace(varname, value) |
| 101 | + |
| 102 | + out.write(line) |
| 103 | + |
| 104 | + args = [ |
| 105 | + 'docker', |
| 106 | + 'build', |
| 107 | + '-t', image_name, |
| 108 | + '.' |
| 109 | + ] |
| 110 | + subprocess.check_output(args, stderr=subprocess.STDOUT) |
| 111 | + print("build ok:", image_name) |
| 112 | + subprocess.check_output(['docker', 'push', image_name], |
| 113 | + stderr=subprocess.STDOUT) |
| 114 | + print("upload ok:", image_name) |
| 115 | + travis_conf.append(travis_conf_line % image_name) |
59 | 116 |
|
60 | 117 | print("\ntravis configuration") |
61 | 118 | print('\n'.join(travis_conf)) |
0 commit comments