Update docker config to help out devs
This commit is contained in:
Родитель
7482faa80c
Коммит
5c7095f2ea
|
@ -0,0 +1,11 @@
|
|||
[run]
|
||||
source = mozaggregator
|
||||
branch = True
|
||||
data_file = /tmp/.coverage
|
||||
|
||||
[report]
|
||||
omit =
|
||||
tests/*
|
||||
|
||||
[xml]
|
||||
output = /tmp/coverage.xml
|
|
@ -13,7 +13,9 @@ RUN mkdir -p /usr/share/man/man7
|
|||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
libsnappy-dev liblzma-dev g++ gcc awscli redis-server curl libpq-dev bzip2 libffi-dev net-tools \
|
||||
# Production only libs on next line.
|
||||
gcc awscli net-tools \
|
||||
libsnappy-dev liblzma-dev g++ redis-server curl libpq-dev bzip2 libffi-dev \
|
||||
python-numpy python-pandas python-scipy wget ca-certificates openssl libssl-dev \
|
||||
postgresql-9.4 postgresql-contrib-9.4 postgresql-server-dev-9.4 \
|
||||
openjdk-7-jdk && \
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
FROM python:2-slim
|
||||
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
POSTGRES_HOST=db \
|
||||
POSTGRES_USER=postgres \
|
||||
PORT=5000
|
||||
|
@ -40,11 +41,11 @@ WORKDIR /app
|
|||
COPY . /app
|
||||
|
||||
# Install spark
|
||||
RUN wget https://d3kbcqa49mib13.cloudfront.net/spark-2.0.2-bin-hadoop2.7.tgz -O spark.tgz && \
|
||||
tar -xzf spark.tgz
|
||||
RUN wget https://d3kbcqa49mib13.cloudfront.net/spark-2.0.2-bin-hadoop2.7.tgz -O /opt/spark.tgz && \
|
||||
tar -xzf /opt/spark.tgz -C /opt
|
||||
|
||||
ENV SPARK_HOME=/app/spark-2.0.2-bin-hadoop2.7 \
|
||||
PYTHONPATH=/app/spark-2.0.2-bin-hadoop2.7/python:/app/spark-2.0.2-bin-hadoop2.7/python/lib/py4j-0.10.3-src.zip
|
||||
ENV SPARK_HOME=/opt/spark-2.0.2-bin-hadoop2.7 \
|
||||
PYTHONPATH=/opt/spark-2.0.2-bin-hadoop2.7/python:/opt/spark-2.0.2-bin-hadoop2.7/python/lib/py4j-0.10.3-src.zip
|
||||
|
||||
RUN chown -R 10001:10001 /app
|
||||
|
||||
|
|
3
Makefile
3
Makefile
|
@ -22,6 +22,9 @@ shell: build
|
|||
test:
|
||||
docker-compose up --build --abort-on-container-exit test
|
||||
|
||||
runtests:
|
||||
docker-compose up test
|
||||
|
||||
stop:
|
||||
docker-compose down
|
||||
docker-compose stop
|
||||
|
|
|
@ -21,6 +21,8 @@ services:
|
|||
dockerfile: Dockerfile.dev
|
||||
ports:
|
||||
- "8000:5000"
|
||||
volumes:
|
||||
- .:/app
|
||||
depends_on:
|
||||
- db
|
||||
links:
|
||||
|
|
56
run-tests.sh
56
run-tests.sh
|
@ -16,58 +16,16 @@ if [ -z "$POSTGRES_USER" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# see https://github.com/travis-ci/travis-ci/issues/7940
|
||||
# See https://github.com/travis-ci/travis-ci/issues/7940
|
||||
export BOTO_CONFIG=/dev/null
|
||||
|
||||
# make sure mozaggregator is properly importable
|
||||
# this is mainly needed for TravisCI support
|
||||
export PYTHONPATH=$PYTHONPATH:.
|
||||
|
||||
# set connection string needed to access the database
|
||||
# this is used by `./mozaggregator/service.py` and `nosetests ./tests/`
|
||||
|
||||
export DB_TEST_URL="dbname=postgres user=${POSTGRES_USER} host=${POSTGRES_HOST}"
|
||||
|
||||
check_for_cmd () {
|
||||
which "$1" >/dev/null 2>&1 || {
|
||||
echo "Could not find '$1' command" >&2
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
# Allow mozaggregator to be imported.
|
||||
export PYTHONPATH=$PYTHONPATH:.
|
||||
|
||||
wait_for_line () {
|
||||
echo "Waiting for '$1' to appear in file '$2'..."
|
||||
timeout 20 grep -q "$1" < "$2" || {
|
||||
echo "ERROR: waiting for '$1' to appear in file '$2' failed or timed out" >&2
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
python ./mozaggregator/service.py -d &
|
||||
|
||||
PGSQL_DATA=$(mktemp -d /tmp/PGSQL-XXXXX) # temp dir for database storage, and the database output FIFO
|
||||
PGSQL_PATH=$(pg_config --bindir) # PostgreSQL binaries path
|
||||
python "$(which nosetests)" --with-coverage --cover-package=mozaggregator ./tests/*.py || exit 1
|
||||
|
||||
# make sure we have everything we need to run
|
||||
check_for_cmd ${PGSQL_PATH}/initdb
|
||||
check_for_cmd ${PGSQL_PATH}/postgres
|
||||
check_for_cmd nosetests
|
||||
|
||||
# start a PostgreSQL database server in the background with a new database
|
||||
${PGSQL_PATH}/initdb ${PGSQL_DATA} # initialize the database
|
||||
echo "host all all 0.0.0.0/0 trust" >> $PGSQL_DATA/pg_hba.conf # allow anyone to access the database
|
||||
mkfifo ${PGSQL_DATA}/out # create output FIFO for the database to let us read the output programmatically
|
||||
${PGSQL_PATH}/postgres -h '*' -F -k ${PGSQL_DATA} -D ${PGSQL_DATA} > ${PGSQL_DATA}/out 2>&1 & # start the database server
|
||||
wait_for_line "database system is ready to accept connections" ${PGSQL_DATA}/out || { # wait for PostgreSQL to start listening for connections
|
||||
cat ${PGSQL_DATA}/out # print out the log for convenience
|
||||
exit 1
|
||||
}
|
||||
|
||||
# launch the HTTP API service in the background
|
||||
mkfifo ${PGSQL_DATA}/out_service
|
||||
python ./mozaggregator/service.py -d > ${PGSQL_DATA}/out_service 2>&1 &
|
||||
wait_for_line "* Running " ${PGSQL_DATA}/out_service || {
|
||||
cat ${PGSQL_DATA}/out_service # print out the log for convenience
|
||||
exit 1
|
||||
}
|
||||
|
||||
python "$(which nosetests)" -x ./tests/*.py || exit 1
|
||||
# Show a text coverage report after a test run.
|
||||
coverage report -m
|
||||
|
|
Загрузка…
Ссылка в новой задаче