diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index b79f822..7cdb4bd 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -3,6 +3,8 @@ name: base on: push: paths: + - ".github/workflows/base.yml" + - "*.sh" - "base/**" env: diff --git a/.github/workflows/postgres.yml b/.github/workflows/postgres.yml index 1579a84..5ad1f82 100644 --- a/.github/workflows/postgres.yml +++ b/.github/workflows/postgres.yml @@ -3,6 +3,8 @@ name: postgres on: push: paths: + - ".github/workflows/postgres.yml" + - "*.sh" - "postgres/**" env: @@ -19,12 +21,14 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] + env: + CI_PLATFORM: ${{ matrix.os }} + EXTRA_BUILD_ARG: 12.3-2 + steps: - uses: actions/checkout@v1 - run: bash build.sh - env: - CI_PLATFORM: ${{ matrix.os }} - EXTRA_BUILD_ARG: 12.3-2 + - run: bash test.sh manifest: needs: build diff --git a/.github/workflows/rabbitmq.yml b/.github/workflows/rabbitmq.yml index fe47be6..1516441 100644 --- a/.github/workflows/rabbitmq.yml +++ b/.github/workflows/rabbitmq.yml @@ -3,6 +3,8 @@ name: rabbitmq on: push: paths: + - ".github/workflows/rabbitmq.yml" + - "*.sh" - "rabbitmq/**" env: @@ -19,11 +21,13 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] + env: + CI_PLATFORM: ${{ matrix.os }} + steps: - uses: actions/checkout@v1 - run: bash build.sh - env: - CI_PLATFORM: ${{ matrix.os }} + - run: bash test.sh manifest: needs: build diff --git a/postgres/Dockerfile.linux b/postgres/Dockerfile.linux index f8de131..0a925a5 100644 --- a/postgres/Dockerfile.linux +++ b/postgres/Dockerfile.linux @@ -4,4 +4,4 @@ FROM postgres:$VERSION COPY healthcheck.sh /usr/local/bin/ -HEALTHCHECK CMD ["healthcheck.sh"] +HEALTHCHECK --interval=5s --timeout=60s CMD ["healthcheck.sh"] diff --git a/postgres/healthcheck.sh b/postgres/healthcheck.sh index f448774..5231151 100644 --- a/postgres/healthcheck.sh +++ b/postgres/healthcheck.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash # https://github.com/docker-library/healthcheck/blob/master/postgres/docker-healthcheck diff --git a/rabbitmq/Dockerfile.linux b/rabbitmq/Dockerfile.linux index 534ea12..f2dca77 100644 --- a/rabbitmq/Dockerfile.linux +++ b/rabbitmq/Dockerfile.linux @@ -4,4 +4,4 @@ FROM rabbitmq:$VERSION-management COPY healthcheck.sh /usr/local/bin/ -HEALTHCHECK CMD ["healthcheck.sh"] +HEALTHCHECK --interval=5s --timeout=60s CMD ["healthcheck.sh"] diff --git a/rabbitmq/healthcheck.sh b/rabbitmq/healthcheck.sh index aa70aec..b0b2c45 100644 --- a/rabbitmq/healthcheck.sh +++ b/rabbitmq/healthcheck.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash # https://github.com/docker-library/healthcheck/blob/master/rabbitmq/docker-healthcheck diff --git a/rabbitmq/test.sh b/rabbitmq/test.sh deleted file mode 100644 index 9bb22c2..0000000 --- a/rabbitmq/test.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -healthy=healthy - -# https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746 -function retry { - local retries=$1 - shift - - local count=0 - until "$@"; do - exit=$? - wait=$((2 ** $count)) - count=$(($count + 1)) - if [ $count -lt $retries ]; then - echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." - sleep $wait - else - echo "Retry $count/$retries exited $exit, no more retries left." - return $exit - fi - done - return 0 -} - -function health { - docker inspect --format='{{json .State.Health.Status}}' rabbitmq -} - -function test { - status=`health` - - echo "Got status $status" - - [ $status = "\"$healthy\"" ] -} - -set -e - -docker run \ - --rm \ - --detach \ - -p 4369:4369 \ - -p 5671:5671 \ - -p 5672:5672 \ - -p 15672:15672 \ - --name rabbitmq \ - exivity/rabbitmq:latest - -retry 10 test - -docker stop rabbitmq diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..3e168dc --- /dev/null +++ b/test.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +if [[ $CI_PLATFORM == 'ubuntu-latest' ]]; then + PLATFORM=linux +elif [[ $CI_PLATFORM == 'windows-latest' ]]; then + PLATFORM=windows +fi + +LATEST_TAG=latest-$PLATFORM + +# https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746 +function retry { + local retries=$1 + shift + + local count=0 + until "$@"; do + exit=$? + wait=$((2 ** $count)) + count=$(($count + 1)) + if [ $count -lt $retries ]; then + echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." + sleep $wait + else + echo "Retry $count/$retries exited $exit, no more retries left." + return $exit + fi + done + return 0 +} + +function get_health_status { + docker inspect --format="{{json .State.Health.Status}}" $IMAGE +} + +function check_if_healthy { + status=`get_health_status` + + echo "Got status $status" + + [[ $status == "\"healthy\"" ]] +} + +set -e + +echo "Running Docker image $IMAGE:$TAG in a container named $IMAGE" +docker run \ + --rm \ + --detach \ + --name $IMAGE \ + exivity/$IMAGE:$LATEST_TAG + +echo "Running health check" +# retry 6 means we will wait max 1+2+4+8+16 seconds +retry 6 check_if_healthy + +echo "Stop Docker container $IMAGE" +docker stop $IMAGE