Skip to content

Commit

Permalink
docker: enhancement to choose light containers with Alpine and debian…
Browse files Browse the repository at this point in the history
…:slim (base)
  • Loading branch information
blankoworld committed Nov 30, 2019
1 parent 9f1f82b commit ba4fb79
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ To generate correct files, please provide the following input to Cookiecutter:
without one (`None`).
`datamodel_extension_class` Name of the class of your custom datamodel.
`datamodel_pid_name` Name of the Persistent IDentifier attribute of the datamodel.
`docker_size` Either you want to use Alpine Docker containers or normal
ones.
============================ ==============================================================

Further documentation is available on https://invenio.readthedocs.io/
3 changes: 2 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"elasticsearch": ["6", "5"],
"datamodel": ["Custom", "None"],
"datamodel_extension_class": "{{ cookiecutter.project_name | replace('-', '') | replace(' ', '') }}",
"datamodel_pid_name": "id"
"datamodel_pid_name": "id",
"docker_size": ["light", "normal"]
}
19 changes: 19 additions & 0 deletions {{cookiecutter.project_shortname}}/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
# and includes Pip, Pipenv, Node.js, NPM and some few standard libraries
# Invenio usually needs.

{%- if cookiecutter.docker_size == 'light'%}
FROM inveniosoftware/debian10-python:3.6-slim
{%- else %}
FROM inveniosoftware/centos7-python:3.6
{%- endif %}
COPY Pipfile Pipfile.lock ./
{%- if cookiecutter.docker_size == 'light'%}
# As we get a tiny image, we install needed packages (to build UWSGI deps)
RUN set -ex \
&& buildDeps=' \
gcc \
python-dev \
' \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
$buildDeps \
&& pipenv install --deploy --system \
&& apt-get purge -y --autoremove $buildDeps \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
{%- else %}
RUN pipenv install --deploy --system
{%- endif %}
12 changes: 12 additions & 0 deletions {{cookiecutter.project_shortname}}/docker-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@ services:
- "80"
- "443"
cache:
{%- if cookiecutter.docker_size == 'light'%}
image: redis:alpine
{%- else %}
image: redis
{%- endif %}
restart: "always"
read_only: true
ports:
- "6379:6379"
db:
{%- if cookiecutter.database == 'postgresql'%}
{%- if cookiecutter.docker_size == 'light'%}
image: postgres:9.6-alpine
{%- else %}
image: postgres:9.6
{%- endif %}
restart: "always"
environment:
- "POSTGRES_USER={{cookiecutter.project_shortname}}"
Expand All @@ -66,7 +74,11 @@ services:
- "3306:3306"
{%- endif %}
mq:
{%- if cookiecutter.docker_size == 'light'%}
image: rabbitmq:3-management-alpine
{%- else %}
image: rabbitmq:3-management
{%- endif %}
restart: "always"
ports:
- "15672:15672"
Expand Down
4 changes: 4 additions & 0 deletions {{cookiecutter.project_shortname}}/docker/haproxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% include 'misc/header.py' %}
{%- if cookiecutter.docker_size == 'light'%}
FROM haproxy:1.8-alpine
{%- else %}
FROM haproxy:1.8
{%- endif %}
RUN mkdir -p /usr/local/var/lib/haproxy/
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
COPY haproxy_cert.pem /usr/local/etc/cert.pem
4 changes: 4 additions & 0 deletions {{cookiecutter.project_shortname}}/docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% include 'misc/header.py' %}
{%- if cookiecutter.docker_size == 'light'%}
FROM nginx:alpine
{%- else %}
FROM nginx
{%- endif %}
COPY nginx.conf /etc/nginx/nginx.conf
COPY conf.d/* /etc/nginx/conf.d/
COPY test.key /etc/ssl/private/test.key
Expand Down
4 changes: 4 additions & 0 deletions {{cookiecutter.project_shortname}}/docker/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{% include 'misc/header.py' %}
{%- if cookiecutter.docker_size == 'light'%}
FROM postgres:9.6-alpine
{%- else %}
FROM postgres:9.6
{%- endif %}
COPY ./init-app-db.sh /docker-entrypoint-initdb.d/10-init-app-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ check_ready "MySQL" _db_check
_es_check(){ curl --output /dev/null --silent --head --fail http://localhost:9200 &>/dev/null; }
check_ready "Elasticsearch" _es_check

{%- if cookiecutter.docker_size == 'light'%}
_redis_check(){ docker-compose exec cache sh -c 'redis-cli ping' | grep 'PONG' &> /dev/null; }
{%- else %}
_redis_check(){ docker-compose exec cache bash -c 'redis-cli ping' | grep 'PONG' &> /dev/null; }
{%- endif %}
check_ready "Redis" _redis_check

_rabbit_check(){ docker-compose exec mq bash -c "rabbitmqctl status" &>/dev/null; }
Expand Down

0 comments on commit ba4fb79

Please sign in to comment.