|
@@ -0,0 +1,38 @@
|
|
1
|
+#! /usr/bin/env python3
|
|
2
|
+
|
|
3
|
+import argparse
|
|
4
|
+import re
|
|
5
|
+import sys
|
|
6
|
+from subprocess import call
|
|
7
|
+
|
|
8
|
+def main():
|
|
9
|
+ parser = argparse.ArgumentParser(description='Build postgresql in docker')
|
|
10
|
+ parser.add_argument('--pg-version', dest='pg_version', default='9.6.3', help='Postgres version to build')
|
|
11
|
+ parser.add_argument('--docker-tag', dest='docker_tag', default='postgres-custom', help='Docker tag to apply to the image. The version will be automatically added.')
|
|
12
|
+
|
|
13
|
+ args = parser.parse_args()
|
|
14
|
+
|
|
15
|
+ pg_version = args.pg_version
|
|
16
|
+ docker_tag = args.docker_tag
|
|
17
|
+
|
|
18
|
+ if not re.match('^[0-9]+\.[0-9]+\.[0-9]+', pg_version):
|
|
19
|
+ print("Bad version format. Should be major.minor.fix (eg: 9.6.3)")
|
|
20
|
+ sys.exit(64)
|
|
21
|
+
|
|
22
|
+ pg_version_ = pg_version.replace('.', '_')
|
|
23
|
+ split = pg_version.split('.')
|
|
24
|
+ pg_major = split[0] + '.' + split[1]
|
|
25
|
+ docker_tag_full = '%s:%s' % (docker_tag, pg_version)
|
|
26
|
+
|
|
27
|
+ print('Building postgres:\nPG_MAJOR=%s\nPG_VERSION=%s\nPG_VERSION_=%s\nDocker tag: %s' %
|
|
28
|
+ (pg_major, pg_version, pg_version_, docker_tag_full))
|
|
29
|
+
|
|
30
|
+ call(['docker', 'build',
|
|
31
|
+ '-t', docker_tag_full,
|
|
32
|
+ '--build-arg', 'PG_MAJOR=%s' % pg_major,
|
|
33
|
+ '--build-arg', 'PG_VERSION=%s' % pg_version,
|
|
34
|
+ '--build-arg', 'PG_VERSION_=%s' % pg_version_,
|
|
35
|
+ '.'])
|
|
36
|
+
|
|
37
|
+if __name__ == '__main__':
|
|
38
|
+ main()
|