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 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 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