Skip to content

Commit c81380e

Browse files
committed
Add Postgres 12
- New default tag. - Update upstream entrypoint location, changed in docker-library/postgres#260. - Build only once in tests. - Redefine `CMD` as needed now since moby/moby#5147.
1 parent d4b6c8d commit c81380e

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ stages:
3232

3333
env:
3434
global:
35-
- LATEST_RELEASE=11-alpine
35+
- LATEST_RELEASE=12-alpine
3636
- DOCKER_REPO=tecnativa/postgres-autoconf
3737
jobs:
3838
- DOCKER_TAG=9.6-alpine
3939
- DOCKER_TAG=10-alpine
4040
- DOCKER_TAG=11-alpine
41+
- DOCKER_TAG=12-alpine
4142

4243
jobs:
4344
include:

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ARG BASE_TAG
22
FROM docker.io/postgres:${BASE_TAG}
3-
ENTRYPOINT [ "/autoconf-entrypoint" ]
3+
ENTRYPOINT ["/usr/local/bin/autoconf-entrypoint", "/usr/local/bin/docker-entrypoint.sh"]
4+
CMD ["postgres"]
45
ENV CERTS="{}" \
56
CONF_EXTRA="" \
67
LAN_AUTH_METHOD=md5 \
@@ -25,7 +26,9 @@ RUN apk add --no-cache -t .build \
2526
&& pip3 install --no-cache-dir \
2627
netifaces \
2728
&& apk del .build
28-
COPY autoconf-entrypoint /
29+
# Deprecated location
30+
RUN ln -s /usr/local/bin/autoconf-entrypoint /
31+
COPY autoconf-entrypoint /usr/local/bin/
2932

3033
# Metadata
3134
ARG VCS_REF

autoconf-entrypoint

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,4 @@ permissions_fix(HBA_FILE)
128128

129129
# Continue normal execution
130130
args = sys.argv[1:]
131-
if not args or args[0] == "postgres" or args[0].startswith("-"):
132-
# Need to go through parent image entrypoint, and hardcode conf file
133-
args = ["/docker-entrypoint.sh", *args, "-cconfig_file={}".format(CONF_FILE)]
134131
os.execvp(args[0], args)

tests/test.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,44 @@
1212
local.cwd.chdir(os.path.dirname(__file__))
1313
certgen = local["./certgen"]
1414

15+
# Helpers
16+
CONF_EXTRA = """-eCONF_EXTRA=
17+
log_connections = on
18+
log_min_messages = log
19+
"""
20+
1521

1622
class PostgresAutoconfCase(unittest.TestCase):
1723
"""Test behavior for this docker image"""
1824

19-
def setUp(self):
25+
@classmethod
26+
def setUpClass(cls):
2027
with local.cwd(local.cwd / ".."):
2128
print("Building image")
2229
local["./hooks/build"] & FG
30+
cls.image = "tecnativa/postgres-autoconf:{}".format(local.env["DOCKER_TAG"])
31+
cls.cert_files = {"client.ca.cert.pem", "server.cert.pem", "server.key.pem"}
32+
return super().setUpClass()
33+
34+
def setUp(self):
2335
docker("network", "create", "lan")
2436
docker("network", "create", "wan")
25-
self.version = os.environ["DOCKER_TAG"]
26-
self.image = ("tecnativa/postgres-autoconf:{}".format(self.version),)
27-
self.cert_files = {"client.ca.cert.pem", "server.cert.pem", "server.key.pem"}
2837
return super().setUp()
2938

3039
def tearDown(self):
3140
try:
3241
print("Postgres container logs:")
3342
docker["container", "logs", self.postgres_container] & FG
34-
docker["container", "stop", self.postgres_container] & FG
35-
docker["container", "rm", self.postgres_container] & FG
43+
docker("container", "stop", self.postgres_container)
44+
docker("container", "rm", self.postgres_container)
3645
except AttributeError:
3746
pass # No postgres daemon
3847
docker("network", "rm", "lan", "wan")
3948
return super().tearDown()
4049

4150
def _generate_certs(self):
4251
"""Generate certificates for testing the image."""
43-
certgen("example.com", "test_user")
52+
certgen("example.localdomain", "test_user")
4453

4554
def _check_local_connection(self):
4655
"""Check that local connection works fine."""
@@ -105,7 +114,7 @@ def _check_password_auth(self, host=None):
105114
),
106115
)
107116

108-
def _connect_wan_network(self, alias="example.com"):
117+
def _connect_wan_network(self, alias="example.localdomain"):
109118
"""Bind a new network, to imitate WAN connections."""
110119
docker("network", "connect", "--alias", alias, "wan", self.postgres_container)
111120

@@ -131,12 +140,13 @@ def _check_cert_auth(self):
131140
"PGSSLROOTCERT=/certs/server.ca.cert.pem",
132141
"-e",
133142
"PGUSER=test_user",
143+
CONF_EXTRA,
134144
"-v",
135145
"{}:/certs".format(local.cwd),
136146
self.image,
137147
"psql",
138148
"--host",
139-
"example.com",
149+
"example.localdomain",
140150
"--command",
141151
"SELECT 1",
142152
"--no-align",
@@ -164,6 +174,7 @@ def test_server_certs_var(self):
164174
"POSTGRES_PASSWORD=test_password",
165175
"-e",
166176
"POSTGRES_USER=test_user",
177+
CONF_EXTRA,
167178
self.image,
168179
).strip()
169180
self._check_local_connection()
@@ -196,6 +207,7 @@ def test_server_certs_mount(self):
196207
"POSTGRES_PASSWORD=test_password",
197208
"-e",
198209
"POSTGRES_USER=test_user",
210+
CONF_EXTRA,
199211
*cert_vols,
200212
self.image,
201213
).strip()
@@ -218,13 +230,14 @@ def test_no_certs_lan(self):
218230
"POSTGRES_PASSWORD=test_password",
219231
"-e",
220232
"POSTGRES_USER=test_user",
233+
CONF_EXTRA,
221234
self.image,
222235
).strip()
223236
self._check_local_connection()
224237
self._check_password_auth()
225238
self._connect_wan_network()
226239
with self.assertRaises(ProcessExecutionError):
227-
self._check_password_auth("example.com")
240+
self._check_password_auth("example.localdomain")
228241

229242
def test_no_certs_wan(self):
230243
"""Unencrypted WAN access works (although this is dangerous)."""
@@ -244,13 +257,14 @@ def test_no_certs_wan(self):
244257
"WAN_AUTH_METHOD=md5",
245258
"-e",
246259
"WAN_CONNECTION=host",
260+
CONF_EXTRA,
247261
self.image,
248262
).strip()
249263
self._check_local_connection()
250264
self._check_password_auth()
251265
self._connect_wan_network()
252266
with self.assertRaises(ProcessExecutionError):
253-
self._check_password_auth("example.com")
267+
self._check_password_auth("example.localdomain")
254268

255269
def test_certs_falsy_lan(self):
256270
"""Configuration with falsy values for certs works fine."""
@@ -267,6 +281,7 @@ def test_certs_falsy_lan(self):
267281
"-e",
268282
"POSTGRES_USER=test_user",
269283
"-e",
284+
CONF_EXTRA,
270285
"CERTS={}".format(
271286
json.dumps(
272287
{
@@ -282,7 +297,7 @@ def test_certs_falsy_lan(self):
282297
self._check_password_auth()
283298
self._connect_wan_network()
284299
with self.assertRaises(ProcessExecutionError):
285-
self._check_password_auth("example.com")
300+
self._check_password_auth("example.localdomain")
286301

287302

288303
if __name__ == "__main__":

0 commit comments

Comments
 (0)