Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker architecture update for version 2.1 (#43)
* docker architecture update for version 2.1 * docker-compose update * moving Dockerfile and requirments.txt to docker folder * access to Dockerfile via context * applying @lechup suggestions to PR * remove container build from travis * versioning postgis image * readme update * travis fix * requirements.txt updated with pip-complie
- Loading branch information
Showing
15 changed files
with
168 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
docker-compose.yml | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
sudo: required | ||
|
||
language: python | ||
|
||
python: | ||
- "3.5" | ||
|
||
services: | ||
- docker | ||
- docker | ||
|
||
env: | ||
global: | ||
- DOCKER_VERSION=1.13.0-0~ubuntu-trusty | ||
- DOCKER_COMPOSE_VERSION=1.10.0 | ||
|
||
before_install: | ||
# upgrade docker-engine to specific version | ||
- sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION} | ||
|
||
# reinstall docker-compose at specific version | ||
- sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | ||
- sudo chmod +x /usr/local/bin/docker-compose | ||
|
||
script: | ||
- ln -s ./docker/docker-compose.yml ./docker-compose.yml | ||
- docker-compose build | ||
# test if we are able to setup database schema properly | ||
# should catch most typical errors in migrations | ||
- docker-compose run --rm web python manage.py migrate | ||
- docker-compose run --rm web py.test --cov=. | ||
- docker-compose run --rm test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ | |
'NAME': 'docker', | ||
'USER': 'docker', | ||
'PASSWORD': 'docker', | ||
'HOST': 'postgis' | ||
'HOST': 'db' | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
version: '2.1' | ||
|
||
services: | ||
|
||
db: | ||
build: | ||
context: ./docker/db/ | ||
dockerfile: Dockerfile | ||
environment: | ||
POSTGRES_USER: docker | ||
POSTGRES_PASSWORD: docker | ||
POSTGRES_DB: docker | ||
healthcheck: | ||
test: "exit 0" | ||
|
||
web: | ||
build: | ||
context: ./docker/web/ | ||
dockerfile: Dockerfile | ||
user: root | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
volumes: | ||
- .:/code/ | ||
ports: | ||
- "8080:8000" | ||
environment: | ||
DJANGO_SETTINGS_MODULE: EnviroMonitorWeb.settings.dev | ||
command: python manage.py runserver 0.0.0.0:8080 | ||
restart: unless-stopped | ||
|
||
test: | ||
build: | ||
context: ./docker/web/ | ||
dockerfile: Dockerfile | ||
user: root | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
volumes: | ||
- .:/code/ | ||
environment: | ||
DJANGO_SETTINGS_MODULE: EnviroMonitorWeb.settings.test | ||
command: py.test -s --cov=. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM mdillon/postgis:9.6 | ||
COPY db-healthcheck /usr/local/bin/ | ||
RUN chmod +x /usr/local/bin/db-healthcheck | ||
HEALTHCHECK CMD ["db-healthcheck"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## To manually monitor conatiner state use below command | ||
`docker inspect --format='{{json .State.Health}}' enviromonitorweb_db_1` | ||
|
||
I.e. message below: | ||
```json | ||
{"Status":"healthy","FailingStreak":0,"Log":[{"Start":"2017-02-02T18:50:42.83427782+01:00","End":"2017-02-02T18:50:42.869961142+01:00","ExitCode":0,"Output":""},{"Start":"2017-02-02T18:51:12.870148749+01:00","End":"2017-02-02T18:51:12.911524939+01:00","ExitCode":0,"Output":""}]} | ||
``` | ||
|
||
With `docker ps` your container status should be healthy | ||
|
||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | ||
5f3cf5212031 enviromonitorweb_test "py.test -s --cov=." About a minute ago Restarting (0) 4 seconds ago enviromonitorweb_test_1 | ||
7765dc8099d9 enviromonitorweb_db "/docker-entrypoint.s" 2 minutes ago Up 2 minutes (healthy) 5432/tcp enviromonitorweb_db_1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
host="$(hostname --ip-address || echo '127.0.0.1')" | ||
user="${POSTGRES_USER:-postgres}" | ||
export PGPASSWORD="${POSTGRES_PASSWORD:-}" | ||
|
||
args=( | ||
# force postgres to not use the local unix socket (test "external" connectibility) | ||
--host "$host" | ||
--username "$user" | ||
--quiet --no-align --tuples-only | ||
) | ||
|
||
if select="$(echo 'SELECT 1' | psql "${args[@]}")" && [ "$select" = '1' ]; then | ||
exit 0 | ||
fi | ||
|
||
exit 1 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,14 @@ | ||
FROM python:3.5 | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
# change owner of all files created during any cmd, | ||
# override them in Yours docker-compose.yml file | ||
ENV DEFAULT_UID=1000 | ||
ENV DEFAULT_GID=1000 | ||
|
||
WORKDIR /code/ | ||
|
||
# update packages and install apt-reqs | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
# apt requirements | ||
## common | ||
g++ curl ca-certificates \ | ||
# pip apt requirements | ||
## common | ||
python3-dev \ | ||
## psycopg2 | ||
postgresql-server-dev-all \ | ||
## manage.py dbshell | ||
postgresql-client \ | ||
## django.contrib.gis | ||
binutils libproj-dev gdal-bin \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
binutils libproj-dev gdal-bin | ||
|
||
RUN mkdir /code | ||
WORKDIR /code | ||
ADD requirements.txt /code/ | ||
# get newest pip wheel and setuptools | ||
RUN curl https://bootstrap.pypa.io/get-pip.py | python | ||
|
||
# add pip dependencies | ||
ADD requirements.txt / | ||
RUN pip install -r /requirements.txt | ||
|
||
# add cmd | ||
ADD cmd.sh / | ||
CMD ["/cmd.sh"] | ||
|
||
# add entrypoint | ||
ADD wait-for-it.sh / | ||
ADD docker_entrypoint.sh / | ||
ENTRYPOINT ["/docker_entrypoint.sh"] | ||
RUN pip install -r requirements.txt |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,58 @@ | ||
Django==1.10.4 | ||
# | ||
# This file is autogenerated by pip-compile | ||
# To update, run: | ||
# | ||
# pip-compile --output-file requirements.txt requirements.txt | ||
# | ||
appdirs==1.4.0 # via setuptools | ||
argh==0.26.2 # via watchdog | ||
colorama==0.3.7 # via pytest-watch | ||
coreapi==2.1.1 # via django-rest-swagger, openapi-codec | ||
coverage==4.3.4 # via pytest-cov | ||
decorator==4.0.11 # via ipython, traitlets | ||
defusedxml==0.4.1 # via djangorestframework-xml | ||
django-crispy-forms==1.6.1 | ||
django-extensions==1.7.5 | ||
django-geoposition==0.3.0 | ||
djangorestframework==3.5.3 | ||
djangorestframework-xml==1.3.0 | ||
django-filter==1.0.1 | ||
six==1.10.0 | ||
django-geoposition==0.3.0 | ||
django-rest-swagger==2.1.0 | ||
pytest==3.0.5 | ||
Django==1.10.4 | ||
djangorestframework-xml==1.3.0 | ||
djangorestframework==3.5.3 | ||
docopt==0.6.2 # via pytest-watch | ||
factory-boy==2.8.1 | ||
Faker==0.7.7 # via factory-boy | ||
ipython-genutils==0.1.0 # via traitlets | ||
ipython==5.1.0 | ||
itypes==1.1.0 # via coreapi | ||
olefile==0.44 # via pillow | ||
openapi-codec==1.2.1 # via django-rest-swagger | ||
packaging==16.8 # via setuptools | ||
pathtools==0.1.2 # via watchdog | ||
pexpect==4.2.1 # via ipython | ||
pickleshare==0.7.4 # via ipython | ||
Pillow==4.0.0 | ||
prompt-toolkit==1.0.13 # via ipython | ||
psycopg2==2.6.2 | ||
ptyprocess==0.5.1 # via pexpect | ||
py==1.4.32 # via pytest | ||
pygments==2.2.0 # via ipython | ||
pyparsing==2.1.10 # via packaging | ||
pytest-cov==2.4.0 | ||
pytest-django==3.1.2 | ||
pytest-watch==4.1.0 | ||
factory-boy==2.8.1 | ||
psycopg2==2.6.2 | ||
ipython==5.1.0 | ||
pytest==3.0.5 | ||
python-dateutil==2.6.0 # via faker | ||
PyYAML==3.12 # via watchdog | ||
requests==2.13.0 # via coreapi | ||
simplegeneric==0.8.1 # via ipython | ||
simplejson==3.10.0 # via django-rest-swagger | ||
six==1.10.0 | ||
tqdm==4.11.2 | ||
Pillow==4.0.0 | ||
traitlets==4.3.1 # via ipython | ||
uritemplate==3.0.0 # via coreapi | ||
watchdog==0.8.3 # via pytest-watch | ||
wcwidth==0.1.7 # via prompt-toolkit | ||
|
||
# The following packages are considered to be unsafe in a requirements file: | ||
# setuptools # via ipython |
Oops, something went wrong.