Skip to content

Commit

Permalink
Merge pull request #3 from ghusta/feature/issue-2
Browse files Browse the repository at this point in the history
Feature/issue 2
  • Loading branch information
Guillaume Husta authored Aug 13, 2018
2 parents b7f71e6 + 4db0778 commit 1cf3a13
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.sh text eol=lf
docker-healthcheck text eol=lf
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
21 changes: 21 additions & 0 deletions docker-healthcheck
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1cf3a13

Please sign in to comment.