|
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/9.6/alpine/' |
| 14 | +ALPINE_ENTRYPOINT = 'docker-entrypoint.sh' |
| 15 | +ALPINE_PATCH = b''' |
| 16 | +diff --git a/Dockerfile b/Dockerfile |
| 17 | +index 9878023..ba215bc 100644 |
| 18 | +--- a/Dockerfile |
| 19 | ++++ b/Dockerfile |
| 20 | +@@ -80,6 +80,7 @@ RUN set -ex \\ |
| 21 | + # configure options taken from: |
| 22 | + # https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5 |
| 23 | + && ./configure \\ |
| 24 | ++ --enable-cassert \\ |
| 25 | + --build="$gnuArch" \\ |
| 26 | + # "/usr/src/postgresql/src/backend/access/common/tupconvert.c:105: undefined reference to `libintl_gettext'" |
| 27 | + # --enable-nls \\ |
| 28 | +''' |
| 29 | +CUSTOM_IMAGE_NAME = "%s/postgres_stable" % DOCKER_ID |
| 30 | + |
| 31 | +def make_alpine_image(image_name): |
| 32 | + dockerfile = urlopen(urljoin(ALPINE_BASE_URL, 'Dockerfile')).read() |
| 33 | + entrypoint_sh = urlopen(urljoin(ALPINE_BASE_URL, ALPINE_ENTRYPOINT)).read() |
| 34 | + |
| 35 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 36 | + print("Creating build in %s" % tmpdir) |
| 37 | + with open(os.path.join(tmpdir, 'Dockerfile'), 'w') as f: |
| 38 | + f.write(dockerfile.decode()) |
| 39 | + |
| 40 | + with open(os.path.join(tmpdir, ALPINE_ENTRYPOINT), 'w') as f: |
| 41 | + f.write(entrypoint_sh.decode()) |
| 42 | + |
| 43 | + with open(os.path.join(tmpdir, 'cassert.patch'), 'w') as f: |
| 44 | + f.write(ALPINE_PATCH.decode()) |
| 45 | + |
| 46 | + subprocess.check_output(["git", "apply", "cassert.patch"], cwd=tmpdir) |
| 47 | + print("patch applied") |
| 48 | + subprocess.check_output(["docker", "build", ".", '-t', image_name], cwd=tmpdir) |
| 49 | + print("build ok: ", image_name) |
| 50 | + subprocess.check_output(['docker', 'push', image_name], |
| 51 | + stderr=subprocess.STDOUT) |
| 52 | + print("upload ok:", image_name) |
| 53 | + |
| 54 | +make_alpine_image(CUSTOM_IMAGE_NAME) |
| 55 | + |
| 56 | +pg_containers = [ |
| 57 | + ('pg95', 'postgres:9.5-alpine'), |
| 58 | + ('pg96', 'postgres:9.6-alpine'), |
| 59 | + ('pg10', 'postgres:10-alpine'), |
| 60 | + ('pg96_ca', CUSTOM_IMAGE_NAME), |
| 61 | +] |
8 | 62 |
|
9 | 63 | image_types = {
|
10 | 64 | 'clang_check_code': {
|
|
30 | 84 | travis_conf = []
|
31 | 85 | print("")
|
32 | 86 |
|
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) |
| 87 | +if __name__ == '__main__': |
| 88 | + for pgname, container in pg_containers: |
| 89 | + for key, variables in image_types.items(): |
| 90 | + image_name = '%s/%s_%s' % (DOCKER_ID, pgname, key) |
| 91 | + with open('Dockerfile', 'w') as out: |
| 92 | + with open('Dockerfile.tmpl', 'r') as f: |
| 93 | + for line in f: |
| 94 | + line = line.replace('${PG_IMAGE}', container) |
| 95 | + for key, value in variables.items(): |
| 96 | + varname = '${%s}' % key |
| 97 | + line = line.replace(varname, value) |
| 98 | + |
| 99 | + out.write(line) |
| 100 | + |
| 101 | + args = [ |
| 102 | + 'docker', |
| 103 | + 'build', |
| 104 | + '-t', image_name, |
| 105 | + '.' |
| 106 | + ] |
| 107 | + subprocess.check_output(args, stderr=subprocess.STDOUT) |
| 108 | + print("build ok:", image_name) |
| 109 | + subprocess.check_output(['docker', 'push', image_name], |
| 110 | + stderr=subprocess.STDOUT) |
| 111 | + print("upload ok:", image_name) |
| 112 | + travis_conf.append(travis_conf_line % image_name) |
59 | 113 |
|
60 | 114 | print("\ntravis configuration")
|
61 | 115 | print('\n'.join(travis_conf))
|
0 commit comments