Skip to content

Commit

Permalink
chore: add tests (#4)
Browse files Browse the repository at this point in the history
* chore: add tests

* chore: give it some time?

* chore: trigger

* fix: healthcheck
  • Loading branch information
hongaar authored Aug 13, 2020
1 parent 2480b52 commit 7535832
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: base
on:
push:
paths:
- ".github/workflows/base.yml"
- "*.sh"
- "base/**"

env:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: postgres
on:
push:
paths:
- ".github/workflows/postgres.yml"
- "*.sh"
- "postgres/**"

env:
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/rabbitmq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: rabbitmq
on:
push:
paths:
- ".github/workflows/rabbitmq.yml"
- "*.sh"
- "rabbitmq/**"

env:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion postgres/Dockerfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion postgres/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash

# https://github.com/docker-library/healthcheck/blob/master/postgres/docker-healthcheck

Expand Down
2 changes: 1 addition & 1 deletion rabbitmq/Dockerfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion rabbitmq/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash

# https://github.com/docker-library/healthcheck/blob/master/rabbitmq/docker-healthcheck

Expand Down
52 changes: 0 additions & 52 deletions rabbitmq/test.sh

This file was deleted.

58 changes: 58 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7535832

Please sign in to comment.