I am trying to deploy a small Django app dockerized using cookiecutter-django on a Raspberry Pi 4 running Rasbian (Linux raspberrypi 4.19.97-v7l+). I would say that my setup is pretty vanilla and am hoping I am not the only one who ran into this.
cookiecutter==1.7.2 django==3.0.5
The build fails and I have tried to install:
sudo apt-get install python3-dev libffi-dev libssl-dev openssl-dev build-essential
Didn't help though. I keep getting the following output when running:
$ docker-compose -f production.yml build
OUTPUT
redis uses an image, skipping
Building postgres
Step 1/4 : FROM postgres:11.3
---> 9ff9cc2df728
Step 2/4 : COPY ./compose/production/postgres/maintenance /usr/local/bin/maintenance
---> Using cache
---> 2ee1f827b4bb
Step 3/4 : RUN chmod +x /usr/local/bin/maintenance/*
---> Using cache
---> 861e846adc6b
Step 4/4 : RUN mv /usr/local/bin/maintenance/* /usr/local/bin && rmdir /usr/local/bin/maintenance
---> Using cache
---> cb799d694f3e
Successfully built cb799d694f3e
Successfully tagged mysite_production_postgres:latest
Building django
Step 1/18 : FROM python:3.8-slim-buster
---> a852e8fce952
Step 2/18 : ENV PYTHONUNBUFFERED 1
---> Using cache
---> bfea44a6a6a9
Step 3/18 : RUN apt-get update && apt-get install -y build-essential && apt-get install -y libpq-dev && apt-get install -y gettext && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && rm -rf /var/lib/apt/lists/*
---> Using cache
---> df6cdd6db821
Step 4/18 : RUN addgroup --system django && adduser --system --ingroup django django
---> Using cache
---> 3803ac7cd551
Step 5/18 : COPY ./requirements /requirements
---> Using cache
---> e6a184f5e700
Step 6/18 : RUN pip install --no-cache-dir -r /requirements/production.txt && rm -rf /requirements
---> Running in 2394f8b40e4a
Collecting pytz==2020.1
Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
Collecting python-slugify==4.0.0
Downloading python-slugify-4.0.0.tar.gz (8.8 kB)
Collecting Pillow==7.1.2
Downloading Pillow-7.1.2.tar.gz (38.9 MB)
Collecting rcssmin==1.0.6
Downloading rcssmin-1.0.6.tar.gz (582 kB)
Collecting argon2-cffi==19.2.0
Downloading argon2-cffi-19.2.0.tar.gz (1.8 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-g3gfug52/overlay --no-warn-script-location --no-binary psycopg2 --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.0'
cwd: None
Complete output (100 lines):
Collecting setuptools>=40.6.0
Downloading setuptools-46.3.0-py3-none-any.whl (582 kB)
Collecting wheel
Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)
Collecting cffi>=1.0
Downloading cffi-1.14.0.tar.gz (463 kB)
Collecting pycparser
Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
Building wheels for collected packages: cffi
Building wheel for cffi (setup.py): started
Building wheel for cffi (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-53k9e4tn/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-53k9e4tn/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-jkqn8qyk
cwd: /tmp/pip-install-53k9e4tn/cffi/
Complete output (36 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.8
creating build/lib.linux-armv7l-3.8/cffi
copying cffi/cparser.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/recompiler.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/commontypes.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/ffiplatform.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/vengine_gen.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/verifier.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/pkgconfig.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/model.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/error.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/__init__.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/api.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/lock.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/_cffi_include.h -> build/lib.linux-armv7l-3.8/cffi
copying cffi/parse_c_type.h -> build/lib.linux-armv7l-3.8/cffi
copying cffi/_embedding.h -> build/lib.linux-armv7l-3.8/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-armv7l-3.8/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-armv7l-3.8
creating build/temp.linux-armv7l-3.8/c
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.8 -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.8/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for cffi
Running setup.py clean for cffi
Failed to build cffi
Installing collected packages: setuptools, wheel, pycparser, cffi
Running setup.py install for cffi: started
Running setup.py install for cffi: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-53k9e4tn/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-53k9e4tn/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-x_f5jys4/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-g3gfug52/overlay --compile --install-headers /tmp/pip-build-env-g3gfug52/overlay/include/python3.8/cffi
cwd: /tmp/pip-install-53k9e4tn/cffi/
Complete output (36 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.8
creating build/lib.linux-armv7l-3.8/cffi
copying cffi/cparser.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/recompiler.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/commontypes.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/ffiplatform.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/vengine_gen.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/verifier.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/pkgconfig.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/model.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/error.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/__init__.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/api.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/lock.py -> build/lib.linux-armv7l-3.8/cffi
copying cffi/_cffi_include.h -> build/lib.linux-armv7l-3.8/cffi
copying cffi/parse_c_type.h -> build/lib.linux-armv7l-3.8/cffi
copying cffi/_embedding.h -> build/lib.linux-armv7l-3.8/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-armv7l-3.8/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-armv7l-3.8
creating build/temp.linux-armv7l-3.8/c
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.8 -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.8/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-53k9e4tn/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-53k9e4tn/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-x_f5jys4/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-g3gfug52/overlay --compile --install-headers /tmp/pip-build-env-g3gfug52/overlay/include/python3.8/cffi Check the logs for full command output.
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-g3gfug52/overlay --no-warn-script-location --no-binary psycopg2 --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.0' Check the logs for full command output.
ERROR: Service 'django' failed to build: The command '/bin/sh -c pip install --no-cache-dir -r /requirements/production.txt && rm -rf /requirements' returned a non-zero code: 1
compose/production/django/dockerfile:
FROM python:3.8-slim-buster
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
# dependencies for building Python packages
&& apt-get install -y build-essential \
# psycopg2 dependencies
&& apt-get install -y libpq-dev \
# Translations dependencies
&& apt-get install -y gettext \
# cleaning up unused files
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
RUN addgroup --system django \
&& adduser --system --ingroup django django
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install --no-cache-dir -r /requirements/production.txt \
&& rm -rf /requirements
COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint
RUN chown django /entrypoint
COPY ./compose/production/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
RUN chown django /start
COPY --chown=django:django . /app
USER django
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
Thing is python docker container 3.8 slim-buster should have libffi-dev installed
you can still check if following helps. By adding additional line to dockerfile
&& apt-get install -y libffi-dev \