Based Docker image on alpine to have a smaller (and faster to build) image

This commit is contained in:
Eliot Berriot 2019-01-21 13:54:46 +01:00
parent 385bc29705
commit 0d461bef5e
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
6 changed files with 70 additions and 69 deletions

View File

@ -1,25 +1,47 @@
FROM python:3.6 FROM alpine:3.8
ENV PYTHONUNBUFFERED 1 RUN \
echo 'installing dependencies' && \
# Requirements have to be pulled and installed here, otherwise caching won't work apk add \
RUN echo 'deb http://httpredir.debian.org/debian/ jessie-backports main' > /etc/apt/sources.list.d/ffmpeg.list bash \
COPY ./requirements.apt /requirements.apt git \
RUN apt-get update; \ gettext \
grep "^[^#;]" requirements.apt | \ musl-dev \
grep -Fv "python3-dev" | \ gcc \
xargs apt-get install -y --no-install-recommends; \ postgresql-dev \
rm -rf /usr/share/doc/* /usr/share/locale/* python3-dev \
py3-psycopg2 \
py3-pillow \
libldap \
ffmpeg \
libpq \
libmagic \
libffi-dev \
zlib-dev \
openldap-dev && \
\
\
ln -s /usr/bin/python3 /usr/bin/python
RUN mkdir /requirements
COPY ./requirements/base.txt /requirements/base.txt COPY ./requirements/base.txt /requirements/base.txt
RUN pip install -r /requirements/base.txt RUN \
echo 'fixing requirements file for alpine' && \
sed -i '/Pillow/d' /requirements/base.txt && \
\
\
echo 'installing pip requirements' && \
pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir setuptools wheel && \
pip3 install --no-cache-dir -r /requirements/base.txt
COPY . /app ARG install_dev_deps=0
COPY ./requirements/*.txt /requirements/
# Since youtube-dl code is updated fairly often, we split it here RUN \
RUN pip install --upgrade youtube-dl if [ "$install_dev_deps" = "1" ] ; then echo "Installing dev dependencies" && pip3 install --no-cache-dir -r /requirements/local.txt -r /requirements/test.txt ; else echo "Skipping dev deps installation" ; fi
WORKDIR /app
ENTRYPOINT ["./compose/django/entrypoint.sh"] ENTRYPOINT ["./compose/django/entrypoint.sh"]
CMD ["./compose/django/daphne.sh"] CMD ["./compose/django/daphne.sh"]
COPY . /app
WORKDIR /app

View File

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/sh
set -e set -e
exec "$@" exec "$@"

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
set -e set -e
# This entrypoint is used to play nicely with the current cookiecutter configuration. # This entrypoint is used to play nicely with the current cookiecutter configuration.
# Since docker-compose relies heavily on environment variables itself for configuration, we'd have to define multiple # Since docker-compose relies heavily on environment variables itself for configuration, we'd have to define multiple

View File

@ -1,24 +0,0 @@
FROM python:3.6
ENV PYTHONUNBUFFERED 1
# Requirements have to be pulled and installed here, otherwise caching won't work
RUN echo 'deb http://httpredir.debian.org/debian/ jessie-backports main' > /etc/apt/sources.list.d/ffmpeg.list
COPY ./requirements.apt /requirements.apt
RUN apt-get update; \
grep "^[^#;]" requirements.apt | \
grep -Fv "python3-dev" | \
xargs apt-get install -y --no-install-recommends; \
rm -rf /usr/share/doc/* /usr/share/locale/*
RUN mkdir /requirements
COPY ./requirements/base.txt /requirements/base.txt
RUN pip install -r /requirements/base.txt
COPY ./requirements/local.txt /requirements/local.txt
RUN pip install -r /requirements/local.txt
COPY ./requirements/test.txt /requirements/test.txt
RUN pip install -r /requirements/test.txt
COPY . /app
WORKDIR /app
ENTRYPOINT ["compose/django/dev-entrypoint.sh"]

View File

@ -0,0 +1 @@
Based Docker image on alpine to have a smaller (and faster to build) image

52
dev.yml
View File

@ -39,36 +39,16 @@ services:
networks: networks:
- internal - internal
celeryworker:
env_file:
- .env.dev
- .env
build:
context: ./api
dockerfile: docker/Dockerfile.test
links:
- postgres
- redis
command: celery -A funkwhale_api.taskapp worker -l debug -B
environment:
- "FUNKWHALE_HOSTNAME=${FUNKWHALE_HOSTNAME-localhost}"
- "FUNKWHALE_HOSTNAME_SUFFIX=funkwhale.test"
- "FUNKWHALE_HOSTNAME_PREFIX=${COMPOSE_PROJECT_NAME}"
- "FUNKWHALE_PROTOCOL=${FUNKWHALE_PROTOCOL-http}"
- "DATABASE_URL=postgresql://postgres@postgres/postgres"
- "CACHE_URL=redis://redis:6379/0"
volumes:
- ./api:/app
- "${MUSIC_DIRECTORY_PATH-./data/music}:/music:ro"
networks:
- internal
api: api:
env_file: env_file:
- .env.dev - .env.dev
- .env - .env
build: build: &backend
context: ./api context: ./api
dockerfile: docker/Dockerfile.test dockerfile: Dockerfile
args:
install_dev_deps: 1
entrypoint: compose/django/dev-entrypoint.sh
command: python /app/manage.py runserver 0.0.0.0:${FUNKWHALE_API_PORT-5000} command: python /app/manage.py runserver 0.0.0.0:${FUNKWHALE_API_PORT-5000}
volumes: volumes:
- ./api:/app - ./api:/app
@ -87,6 +67,28 @@ services:
- internal - internal
cap_add: cap_add:
- SYS_PTRACE - SYS_PTRACE
celeryworker:
env_file:
- .env.dev
- .env
build: *backend
links:
- postgres
- redis
command: celery -A funkwhale_api.taskapp worker -l debug -B
environment:
- "FUNKWHALE_HOSTNAME=${FUNKWHALE_HOSTNAME-localhost}"
- "FUNKWHALE_HOSTNAME_SUFFIX=funkwhale.test"
- "FUNKWHALE_HOSTNAME_PREFIX=${COMPOSE_PROJECT_NAME}"
- "FUNKWHALE_PROTOCOL=${FUNKWHALE_PROTOCOL-http}"
- "DATABASE_URL=postgresql://postgres@postgres/postgres"
- "CACHE_URL=redis://redis:6379/0"
volumes:
- ./api:/app
- "${MUSIC_DIRECTORY_PATH-./data/music}:/music:ro"
networks:
- internal
nginx: nginx:
command: /entrypoint.sh command: /entrypoint.sh
env_file: env_file: