Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Commit

Permalink
Add docker healthy status waiting to fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
donce committed Apr 11, 2019
1 parent a71d6b2 commit dbcca03
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 73 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ RUN pip install -r requirements.txt

ADD . .

HEALTHCHECK --interval=5s --timeout=5s --retries=15\
CMD curl -f http://localhost || exit 1

ENTRYPOINT ["python", "server.py"]
7 changes: 6 additions & 1 deletion dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from werkzeug.contrib.cache import SimpleCache
from dashboard.helpers import get_week_range
from flask import Flask, render_template, request, abort
from flask import Flask, render_template, request, abort, jsonify
from datetime import datetime
from models import db
import settings
Expand Down Expand Up @@ -184,6 +184,11 @@ def sessions_country():
)


@app.route('/ping')
def ping():
return jsonify({'status': 'ok'})


def init_db(custom_config=None):
if custom_config is not None:
app.config['SQLALCHEMY_DATABASE_URI'] =\
Expand Down
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ services:
- .:/code
depends_on:
- db
healthcheck:
test: curl -f http://localhost
interval: 5s
timeout: 5s
retries: 15

dashboard:
build:
Expand All @@ -32,11 +37,15 @@ services:
DB_NAME: myst_api
DB_USER: myst_api
DB_PASSWORD: myst_api

volumes:
- .:/code
depends_on:
- db
healthcheck:
test: curl -f http://localhost/ping
interval: 5s
timeout: 5s
retries: 15

db:
image: percona:5.7
Expand All @@ -49,3 +58,8 @@ services:
MYSQL_DATABASE: myst_api
MYSQL_USER: myst_api
MYSQL_PASSWORD: myst_api
healthcheck:
test: mysqladmin ping --silent
interval: 5s
timeout: 5s
retries: 15
11 changes: 10 additions & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ services:
dockerfile: Dockerfile
container_name: mysterium-api-test
environment:
APP_PORT: 80
DB_HOST: mysterium-mysql-test
DB_NAME: myst_api
DB_USER: myst_api
Expand All @@ -16,6 +15,11 @@ services:
- ..:/code
depends_on:
- db
healthcheck:
test: curl -f http://localhost
interval: 5s
timeout: 5s
retries: 15

db:
image: percona:5.7
Expand All @@ -27,3 +31,8 @@ services:
MYSQL_DATABASE: myst_api
MYSQL_USER: myst_api
MYSQL_PASSWORD: myst_api
healthcheck:
test: mysqladmin ping --silent
interval: 5s
timeout: 5s
retries: 15
11 changes: 9 additions & 2 deletions tests/run_tests
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/sh

(cd tests; docker-compose up --build -d)
printf "Sleeping for 10s until everything initializes...\n"
sleep 10

printf "Waiting until db initializes..."
until [ "` (docker inspect $(cd tests; docker-compose ps -q db) -f {{.State.Health.Status}})`" == "healthy" ]; do
printf "."
sleep 1
done;
sleep 3 # needed for db to fully initialize
printf "\n"

(cd tests; docker-compose exec api bin/db-upgrade)

DISABLE_LOGS=1 bin/test
68 changes: 0 additions & 68 deletions tests/test_settings.py

This file was deleted.

0 comments on commit dbcca03

Please sign in to comment.