Skip to content

Commit

Permalink
Create a base docker image for c2cwsgiutils
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Valsecchi committed Jun 9, 2017
1 parent 1ec56e2 commit 5f1b567
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 50 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*
!c2cwsgiutils
!c2cwsgiutils_*
!LICENSE.txt
!README.md
!rel_requirements.txt
!setup.py
!setup.cfg
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
__pycache__
*.pyc
/.venv/
/acceptance_tests/app/c2cwsgiutils
/acceptance_tests/app/c2cwsgiutils_coverage_report.py
/acceptance_tests/app/c2cwsgiutils_run
/acceptance_tests/app/c2cwsgiutils_genversion.py
/acceptance_tests/app/c2cwsgiutils_stats_db.py
/acceptance_tests/app/rel_requirements.txt
/acceptance_tests/app/setup.cfg
/acceptance_tests/tests/c2cwsgiutils
/acceptance_tests/tests/rel_requirements.txt
/acceptance_tests/tests/setup.cfg
/build/
/c2cwsgiutils.egg-info/
/dist/
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.6

RUN apt-get update && \
apt-get install -y libpq-dev libgeos-dev libproj-dev libjpeg-dev postgresql-client graphviz: && \
apt-get clean && \
rm -r /var/lib/apt/lists/*
COPY rel_requirements.txt /c2cwsgiutils/
RUN pip install --no-cache-dir -r /c2cwsgiutils/rel_requirements.txt

COPY . /c2cwsgiutils/
RUN flake8 /c2cwsgiutils && \
pip install --no-cache-dir -e /c2cwsgiutils

ENV LOG_TYPE=console \
LOG_HOST=localhost \
LOG_PORT=514 \
SQL_LOG_LEVEL=WARN \
OTHER_LOG_LEVEL=WARN \
DEVELOPMENT=0

CMD ["c2cwsgiutils_run"]
15 changes: 15 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env.DOCKER_TAG = env.BUILD_TAG
// We don't want to publish the same branch twice at the same time.
dockerBuild {
checkout scm

stage('Update docker') {
sh 'make pull'
}
Expand All @@ -23,4 +24,18 @@ dockerBuild {
junit keepLongStdio: true, testResults: 'reports/*.xml'
}
}

def CURRENT_TAG = sh(returnStdout: true, script: "git fetch --tags && git tag -l --points-at HEAD | tail -1").trim()
if (CURRENT_TAG != "") {
stage("publish ${CURRENT_TAG} on docker hub") {
sh "docker tag camptocamp/c2cwsgiutils:latest camptocamp/c2cwsgiutils:${CURRENT_TAG}"

withCredentials([[$class : 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub',
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh 'docker login -u "$USERNAME" -p "$PASSWORD"'
docker.image("camptocamp/c2cwsgiutils:${CURRENT_TAG}").push()
sh 'rm -rf ~/.docker*'
}
}
}
}
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DOCKER_TAG ?= latest
DOCKER_TAG = latest
DOCKER_BASE = camptocamp/c2cwsgiutils

#Get the docker version (must use the same version for acceptance tests)
Expand Down Expand Up @@ -41,7 +41,7 @@ acceptance: build_acceptance build_test_app
docker rm c2cwsgiutils_acceptance_$(DOCKER_TAG)_$$PPID; \
status=$$status$$?; \
#generate the HTML report for code coverage \
docker run -v $(THIS_DIR)/reports/coverage/api:/reports/coverage/api:ro --name c2cwsgiutils_acceptance_reports_$(DOCKER_TAG)_$$PPID $(DOCKER_BASE)_test_app:$(DOCKER_TAG) ./c2cwsgiutils_coverage_report.py c2cwsgiutils c2cwsgiutils_app; \
docker run -v $(THIS_DIR)/reports/coverage/api:/reports/coverage/api:ro --name c2cwsgiutils_acceptance_reports_$(DOCKER_TAG)_$$PPID $(DOCKER_BASE)_test_app:$(DOCKER_TAG) c2cwsgiutils_coverage_report.py c2cwsgiutils c2cwsgiutils_app; \
status=$$status$$?; \
#copy the HTML locally \
docker cp c2cwsgiutils_acceptance_reports_$(DOCKER_TAG)_$$PPID:/tmp/coverage/api reports/coverage; \
Expand All @@ -52,14 +52,16 @@ acceptance: build_acceptance build_test_app
docker rm c2cwsgiutils_acceptance_reports_$(DOCKER_TAG)_$$PPID; \
exit $$status$$?

.PHONY: build_docker
build_docker:
docker build -t $(DOCKER_BASE):$(DOCKER_TAG) .

.PHONY: build_acceptance
build_acceptance:
rsync -a c2cwsgiutils rel_requirements.txt setup.cfg acceptance_tests/tests/
build_acceptance: build_docker
docker build --build-arg DOCKER_VERSION="$(DOCKER_VERSION)" --build-arg DOCKER_COMPOSE_VERSION="$(DOCKER_COMPOSE_VERSION)" -t $(DOCKER_BASE)_acceptance:$(DOCKER_TAG) acceptance_tests/tests

.PHONY: build_test_app
build_test_app:
rsync -a c2cwsgiutils c2cwsgiutils_run c2cwsgiutils_genversion.py c2cwsgiutils_coverage_report.py c2cwsgiutils_stats_db.py rel_requirements.txt setup.cfg acceptance_tests/app/
build_test_app: build_docker
docker build -t $(DOCKER_BASE)_test_app:$(DOCKER_TAG) --build-arg "GIT_TAG=$(GIT_TAG)" --build-arg "GIT_HASH=$(GIT_HASH)" acceptance_tests/app

.venv/timestamp: rel_requirements.txt dev_requirements.txt
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,5 @@ Make sure you are strict with the version numbers:
To make a release:

* Change the the version in [setup.py](setup.py)
* run `make release`
* run `make release` to publish to PYPI
* Tag the GIT commit and make sure to push the tag before the branch
20 changes: 5 additions & 15 deletions acceptance_tests/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
FROM python:3.5
FROM camptocamp/c2cwsgiutils:latest
MAINTAINER Camptocamp "[email protected]"

# Doing things in two steps to avoid needing to re-install everything when we do a rebuild
# after changing code

# Step #1 copy only the stuff needed to install the dependencies and run the script
WORKDIR /app
COPY requirements.txt rel_requirements.txt /app/
RUN pip install -r requirements.txt

EXPOSE 80

ENV LOG_TYPE console
ENV LOG_HOST localhost
ENV LOG_PORT 514
ENV SQL_LOG_LEVEL WARN
ENV OTHER_LOG_LEVEL WARN
ENV DEVELOPMENT 0
ENV SQLALCHEMY_URL postgresql://www-data:www-data@db:5432/test
ENV SQLALCHEMY_URL_SLAVE postgresql://www-data:www-data@db_slave:5432/test
ENV SQLALCHEMY_URL=postgresql://www-data:www-data@db:5432/test \
SQLALCHEMY_URL_SLAVE=postgresql://www-data:www-data@db_slave:5432/test

# Step #2 copy the rest of the files (watch for the .dockerignore)
COPY . /app
Expand All @@ -29,7 +21,5 @@ ARG GIT_HASH
RUN python ./setup.py install && \
./models_graph.py > models.dot && \
./models_graph.py Hello > models_hello.dot && \
./c2cwsgiutils_genversion.py $GIT_TAG $GIT_HASH && \
flake8 c2cwsgiutils c2cwsgiutils_app

CMD ["./c2cwsgiutils_run"]
c2cwsgiutils_genversion.py $GIT_TAG $GIT_HASH && \
flake8 c2cwsgiutils_app
3 changes: 0 additions & 3 deletions acceptance_tests/app/requirements.txt

This file was deleted.

3 changes: 3 additions & 0 deletions acceptance_tests/app/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
ignore = E121,E123,E126,E226,E24,E704
max-line-length = 110
12 changes: 4 additions & 8 deletions acceptance_tests/tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
FROM python:3.5
FROM camptocamp/c2cwsgiutils:latest

ARG DOCKER_VERSION=1.12.0
ARG DOCKER_COMPOSE_VERSION=1.10.0

WORKDIR /acceptance_tests

ENV DOCKER_RUN 1
ENV PYTHONPATH /acceptance_tests
ENV DOCKER_RUN=1 \
PYTHONPATH=/acceptance_tests

# Install all Debian dependencies except nodejs which requires https transport
COPY dockerproject.org.asc /acceptance_tests/
RUN echo "deb http://apt.dockerproject.org/repo debian-jessie main" >> /etc/apt/sources.list && \
echo 'deb http://http.debian.net/debian jessie-backports main' >> /etc/apt/sources.list && \
apt-key adv --import /acceptance_tests/dockerproject.org.asc && \
apt-get update && \
apt-get install -y docker-engine=${DOCKER_VERSION}* libpq-dev postgresql-client && \
apt-get install -y docker-engine=${DOCKER_VERSION}* && \
apt-get clean && \
rm -r /var/lib/apt/lists/*

# Install matching docker-compose version
RUN curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/bin/docker-compose && \
chmod a+x /usr/bin/docker-compose

# Install python requirements
COPY requirements.txt rel_requirements.txt /acceptance_tests/
RUN pip install -r ./requirements.txt

COPY . ./

RUN flake8 tests
Expand Down
2 changes: 0 additions & 2 deletions acceptance_tests/tests/requirements.txt

This file was deleted.

3 changes: 3 additions & 0 deletions acceptance_tests/tests/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
ignore = E121,E123,E126,E226,E24,E704
max-line-length = 110
6 changes: 3 additions & 3 deletions acceptance_tests/tests/tests/test_stats_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@


def test_no_extra(app_connection, composition):
composition.run('run_test', './c2cwsgiutils_stats_db.py',
composition.run('run_test', 'c2cwsgiutils_stats_db.py',
'--db', 'postgresql://www-data:www-data@db:5432/test', '--schema', 'public')


def test_with_extra(app_connection, composition):
composition.run('run_test', './c2cwsgiutils_stats_db.py',
composition.run('run_test', 'c2cwsgiutils_stats_db.py',
'--db', 'postgresql://www-data:www-data@db:5432/test', '--schema', 'public',
'--extra', "select 'toto', 42")


def test_error(app_connection, composition):
with pytest.raises(subprocess.CalledProcessError):
composition.run('run_test', './c2cwsgiutils_stats_db.py',
composition.run('run_test', 'c2cwsgiutils_stats_db.py',
'--db', 'postgresql://www-data:www-data@db:5432/test', '--schema', 'public',
'--extra', "select 'toto, 42")
1 change: 1 addition & 0 deletions c2cwsgiutils_coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def main():
cov.xml_report(outfile=os.path.join(dest_dir, 'coverage.xml'), ignore_errors=True)
cov.report(ignore_errors=True)


main()
1 change: 0 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
flake8==3.3.0
junit2html
twine
2 changes: 2 additions & 0 deletions rel_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
alembic==0.9.2
cee_syslog_handler==0.4.1
cornice==2.4.0
flake8==3.3.0
gunicorn==19.7.1
lxml==3.8.0
netifaces==0.10.6
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages


VERSION = '0.15.0'
VERSION = '0.16.0'
HERE = os.path.abspath(os.path.dirname(__file__))
INSTALL_REQUIRES = open(os.path.join(HERE, 'rel_requirements.txt')).read().splitlines()

Expand Down

0 comments on commit 5f1b567

Please sign in to comment.