From fc617a2de00dd7357ddb69c87475b3ee771cc6fb Mon Sep 17 00:00:00 2001 From: Guillaume HUSTA Date: Mon, 13 Aug 2018 13:21:35 +0200 Subject: [PATCH 1/3] FIX #2 : Add HEALTHCHECK in Dockerfile --- CHANGELOG.md | 3 +++ Dockerfile | 4 ++++ docker-healthcheck | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 docker-healthcheck diff --git a/CHANGELOG.md b/CHANGELOG.md index aecf667..9a64920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## 2.2.1 (2018-08-13) +Add HEALTHCHECK in Dockerfile (#2). + ## 2.2 (2017-10-06) Upgrade to PostgreSQL 10. See https://www.postgresql.org/about/news/1786/ diff --git a/Dockerfile b/Dockerfile index 3f02f29..b297d3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,3 +10,7 @@ ADD scripts/*.sql /docker-entrypoint-initdb.d/ # Copier les scripts d'init dans : #ADD scripts/*.sh /docker-entrypoint-initdb.d/ + +COPY docker-healthcheck /usr/local/bin/ + +HEALTHCHECK CMD ["docker-healthcheck"] diff --git a/docker-healthcheck b/docker-healthcheck new file mode 100644 index 0000000..2994167 --- /dev/null +++ b/docker-healthcheck @@ -0,0 +1,21 @@ +#!/bin/bash +set -eo pipefail + +host="$(hostname -i || echo '127.0.0.1')" +user="${POSTGRES_USER:-postgres}" +db="${POSTGRES_DB:-$POSTGRES_USER}" +export PGPASSWORD="${POSTGRES_PASSWORD:-}" + +args=( + # force postgres to not use the local unix socket (test "external" connectibility) + --host "$host" + --username "$user" + --dbname "$db" + --quiet --no-align --tuples-only +) + +if select="$(echo 'SELECT 1' | psql "${args[@]}")" && [ "$select" = '1' ]; then + exit 0 +fi + +exit 1 From b4d57db5f7065f1561d5cb8f0007b4eac40326d9 Mon Sep 17 00:00:00 2001 From: Guillaume HUSTA Date: Mon, 13 Aug 2018 13:36:26 +0200 Subject: [PATCH 2/3] Force EOL = LF for docker-healthcheck (shell script) --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f36af62 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto +*.sh text eol=lf +docker-healthcheck text eol=lf From 4db0778093684b362fda40204616d8e65f4662e7 Mon Sep 17 00:00:00 2001 From: Guillaume HUSTA Date: Mon, 13 Aug 2018 14:03:02 +0200 Subject: [PATCH 3/3] FIX #2 : Check Healthcheck config in Docker image --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5854e45..27e6863 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ install: script: - docker build --tag ghusta/postgres-world-db . + - docker inspect --format="{{json .Config.Healthcheck}}" ghusta/postgres-world-db after_success: - docker image ls