Skip to content

Commit 220d63e

Browse files
committed
updates docker config to run tests with one flaky test
1 parent 7c93a7e commit 220d63e

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ RUN apt-get update && apt-get install -y \
1010
libssl-dev libffi-dev \
1111
--no-install-recommends
1212

13+
RUN apt-get update && apt-get install -y postgresql-client
14+
1315
# Create directory for app
1416
RUN mkdir /app
1517

docker-compose.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ services:
1414

1515
testenv:
1616
build: .
17-
command: tail -f /dev/null
17+
command: sh test.sh
1818
environment:
19-
- SQLALCHEMY_TEST_DATABASE_URI=postgresql+psycopg2://postgres:postgres@localhost:5432/task_list_api_test
20-
- NODE_ENV=test
19+
- SQLALCHEMY_TEST_DATABASE_URI=postgresql://postgres:postgres@postgres:5432/task_list_api_test
20+
- FLASK_ENV=test
2121
depends_on:
2222
postgres:
2323
condition: service_healthy

test.sh

+30
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1+
#!/bin/bash
2+
3+
# must match the name of the service for the database in
4+
# the docker-compose.yml file
5+
DATABASE_SERVICE=postgres
6+
COUNTER=0
7+
EXIT_CODE=1
8+
SECONDS_BEFORE_TIMEOUT=59
9+
10+
# check to see if script is running in docker
11+
if [ -f /.dockerenv ]; then
12+
13+
# spin until database is ready
14+
while [ $EXIT_CODE -ne 0 ]
15+
do
16+
pg_isready -h $DATABASE_SERVICE
17+
EXIT_CODE=$?
18+
COUNTER=`expr $COUNTER + 1`
19+
20+
sleep 1
21+
22+
# Check for time out
23+
if [ $COUNTER -ge $SECONDS_BEFORE_TIMEOUT ]; then
24+
echo "Timed Out - Database not Found"
25+
exit 1
26+
fi
27+
28+
done
29+
fi
30+
131
pytest

0 commit comments

Comments
 (0)