Pillow is not installed after removing .temp-builds - django

The error
ERRORS:
app_1 | core.Page.image: (fields.E210) Cannot use ImageField because Pillow is not installed.
It seems that Pillow is detected as not installed in my docker container if I delete the .temp-builds after installing requirements.txt. I say this because if I remove the 'apk del .tmp-deps' the error went away. However, I want to remove the .tmp-builds because I learn it's best practice to make the docker container as lean as possible.
Dockerfile
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update --no-cache postgresql-client && \
apk add --update --no-cache --virtual .tmp-deps \
build-base postgresql-dev musl-dev linux-headers \
python3-dev zlib-dev jpeg-dev gcc musl-dev && \
/py/bin/pip install -r /requirements.txt && \
apk del .tmp-deps
requirements.txt
django>=3.2.3,<3.3
psycopg2>=2.8.6,<2.9
uWSGI>=2.0.19.1,<2.1
djangorestframework >=3.12.4, <3.20.0
Pillow >= 8.4.0, <8.5.0
Any pointer would be greatly appreaciated.

Alright. After looking at the dockerfile, I saw that postgresql-client is not inth e --virtual .tmp-deps. Which means, some dependencies have to stay in the container for some package to work (it was not obvious to me).
What I learn from here is that I need to include jpeg-dev to the line outise the .tmp-deps.
Updated Dockerfile
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update --no-cache postgresql-client jpeg-dev && \
apk add --update --no-cache --virtual .tmp-deps \
build-base postgresql-dev musl-dev linux-headers python3-dev gcc zlib-dev && \
/py/bin/pip install -r /requirements.txt && \
apk del .tmp-deps && \

Related

dockerfile: dlerror:libcudart.so.11.0: cannot open shared object file

trying to build my first dockerfile for vision transformer on ubuntu 20.04. ran into
2022-11-04 09:08:49.205922: W external/org_tensorflow/tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64]
Could not load dynamic library 'libcudart.so.11.0'; dlerror:
libcudart.so.11.0: cannot open shared object file: No such file or
directory; LD_LIBRARY_PATH:
/usr/local/nvidia/lib:/usr/local/nvidia/lib64
it stopped at git clone (since this is the last step appeared in the terminal before the error):
Step 7/11 : RUN git clone
https://github.com/google-research/vision_transformer.git &&cd
vision_transformer && pip3 install pip --upgrade && pip
install -r vit_jax/requirements.txt &&python -m vit_jax.main
--workdir=/tmp/vit-$(date +%s) --config=$(pwd)/vit_jax/configs/vit.py:b16,cifar10 --config.pretrained_dir='gs://vit_models/imagenet21k' && pip cache purge
below is my dockerfile:
FROM pytorch/pytorch:1.8.1-cuda10.2-cudnn7-runtime
ENV DEBIAN_FRONTEND=noninteractive
ARG USERNAME=user
WORKDIR /dockertest
ARG WORKDIR=/dockertest
RUN apt-get update && apt-get install -y \
automake autoconf libpng-dev nano python3-pip \
sudo curl zip unzip libtool swig zlib1g-dev pkg-config \
python3-mock libpython3-dev libpython3-all-dev \
g++ gcc cmake make pciutils cpio gosu wget \
libgtk-3-dev libxtst-dev sudo apt-transport-https \
build-essential gnupg git xz-utils vim libgtk2.0-0 libcanberra-gtk-module\
# libva-drm2 libva-x11-2 vainfo libva-wayland2 libva-glx2 \
libva-dev libdrm-dev xorg xorg-dev protobuf-compiler \
openbox libx11-dev libgl1-mesa-glx libgl1-mesa-dev \
libtbb2 libtbb-dev libopenblas-dev libopenmpi-dev \
&& sed -i 's/# set linenumbers/set linenumbers/g' /etc/nanorc \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/google-research/vision_transformer.git \
&&cd vision_transformer \
&& pip3 install pip --upgrade \
&& pip install -r vit_jax/requirements.txt \
&&python -m vit_jax.main --workdir=/tmp/vit-$(date +%s) \
--config=$(pwd)/vit_jax/configs/vit.py:b16,cifar10 \
--config.pretrained_dir='gs://vit_models/imagenet21k' \
&& pip cache purge
RUN echo "root:root" | chpasswd \
&& adduser --disabled-password --gecos "" "${USERNAME}" \
&& echo "${USERNAME}:${USERNAME}" | chpasswd \
&& echo "%${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${USERNAME} \
&& chmod 0440 /etc/sudoers.d/${USERNAME}
USER ${USERNAME}
RUN sudo chown -R ${USERNAME}:${USERNAME} ${WORKDIR}
WORKDIR ${WORKDIR}

How to add django-crontab in docker container with non-rooted user django project

Working on a Django project which is running on docker-container with python:3.9-alpine3.13
FROM python:3.9-alpine3.13
LABEL maintainer=<do not want to show>
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
COPY ./app /app
COPY ./scripts /scripts
WORKDIR /app
EXPOSE 8000
RUN python -m venv /py && \
apk add --update --no-cache postgresql-client && \
apk add --update --no-cache --virtual .tmp-deps \
build-base postgresql-dev musl-dev gcc python3-dev bash openssl-dev libffi-dev libsodium-dev linux-headers && \
apk add jpeg-dev zlib-dev libjpeg && \
apk add --update busybox-suid && \
apk --no-cache add dcron libcap && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /requirements.txt && \
apk del .tmp-deps && \
adduser --disabled-password --no-create-home app &&\
mkdir -p /vol/web/static && \
chown -R app:app /vol && \
chmod -R 755 /vol && \
chmod -R +x /scripts
ENV PATH="/scripts:/py/bin:$PATH"
USER app
CMD ["run.sh"]
I used this tutorial for implementation and I don't this error is because of this because
I am getting this error.
sumit#LAPTOP-RT539Q9C MINGW64 ~/Desktop/RentYug/rentyug-backend-deployment (main)
$ docker-compose run --rm app sh -c "python manage.py crontab show"
WARNING: Found orphan containers (rentyug-backend-deployment_proxy_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Creating rentyug-backend-deployment_app_run ... done
/bin/sh: /usr/bin/crontab: Permission denied
Currently active jobs in crontab:
I used these lines for that
apk add --update busybox-suid && \
apk --no-cache add dcron libcap && \
I found my answer that is, cron should run as the root user. I found that answer there.

Translate Dockerfile from python-alpine to python-slim-buster (debian-based)

I am trying to improve the Dockerfile we use for deploying a Django-based app at work and first thing I would like to do is change the base image of python from alpine to slim-buster but I have to translate it to a debian-based image. I would like some suggestions on how I could translate it since I have zero to none experience with alpine. This is the original snippet from Docker.
FROM python:3.8.6-alpine3.12
RUN apk update && \
apk add --virtual build-deps gcc g++ musl-dev && \
apk add postgresql-dev vim bash nginx supervisor curl && \
apk add libffi-dev && \
apk add --update npm && \
apk add git make cmake
You'd need to
use apt-get instead
find the equivalents of those packages in the Debian repositories
Some of these will likely be wrong, but you get the gist.
FROM python:3.8.6-slim-buster
RUN apt-get update && \
apt-get install -y \
bash \
build-essential \
cmake
curl \
git \
libffi-dev \
libpostgresql-dev \
make \
nginx \
nodejs \
supervisor \
vim

Missing dirs and files when migrating PHP-Apache2 from Debian to Alpine

I'm trying to migrate a dockerized PHP-Apache2 server from Debian to Alpine.
The Debian dockerfile:
FROM php:7.3.24-apache-buster
COPY conf/php.ini /usr/local/etc/php
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
curl git \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libxml2-dev \
libpng-dev \
python-setuptools python-dev build-essential python-pip \
libzip-dev
RUN pecl install mcrypt-1.0.2 \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install zip \
&& docker-php-ext-install soap
RUN pip install --upgrade virtualenv && pip install xhtml2pdf
WORKDIR /var/www/app
COPY ./ /var/www/app
RUN cd /var/www/app && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
php composer.phar install --ignore-platform-reqs --prefer-dist
COPY ./conf/default.conf /etc/apache2/sites-enabled/000-default.conf
COPY ./conf/cert /etc/apache2/cert
RUN mkdir /var/log/gts && chmod 777 -R /var/log/gts
RUN mv /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
RUN mv /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled/ssl.load
COPY conf/apache2.conf /etc/apache2/apache2.conf
RUN mv /etc/apache2/mods-available/remoteip.load /etc/apache2/mods-enabled/remoteip.load
EXPOSE 443
The Alpine dockerfile:
FROM webdevops/php-apache:7.3-alpine
COPY conf/php.ini /usr/local/etc/php
RUN apk update && apk upgrade && apk add \
git \
curl \
autoconf \
freetype-dev \
libjpeg-turbo-dev \
libmcrypt-dev \
libxml2-dev \
libpng-dev \
libzip-dev \
py-setuptools \
python3-dev \
build-base \
py-pip \
libzip-dev \
apache2-dev
RUN PHP_AUTOCONF="/usr/bin/autoconf" \
&& pecl install mcrypt-1.0.2 \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN pip install --upgrade --ignore-installed virtualenv && pip install xhtml2pdf
WORKDIR /var/www/app
COPY ./ /var/www/app
RUN cd /var/www/app && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
php composer.phar install --ignore-platform-reqs --prefer-dist
COPY ./conf/default.conf /etc/apache2/sites-enabled/000-default.conf
COPY ./conf/cert /etc/apache2/cert
RUN mkdir /var/log/gts && chmod 777 -R /var/log/gts
RUN mv /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load \
&& mv /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled/ssl.load
COPY conf/apache2.conf /etc/apache2/apache2.conf
RUN mv /etc/apache2/mods-available/remoteip.load /etc/apache2/mods-enabled/remoteip.load
EXPOSE 443
The Alpine build failed:
mv: can't rename '/etc/apache2/mods-available/rewrite.load': No such file or directory
Turns out that the Alpine container:
Has no /etc/apache2/mods-* directories and no *.load files
Has only *.so files in /usr/lib/apache2 (similar to the list of *.so files in /usr/lib/apache2/modules on Debian).
Questions:
Why don't I have *.load files in the Alpine container?
Why don't I have /etc/apache2/mods-* directories in the Alpine container?
Are *.so files equivalent to *.load files?
If the previous is true, then how do I use the *.so files?
PS: I prefer not to change httpd.conf if possible.
I try to answer your questions one by one:
Why don't I have *.load files in the Alpine container?
The load-files normally just contain one line to load the specific module and can be seen as a convenience method to toggle modules with a shell script (a2enmod)
Why don't I have /etc/apache2/mods-* directories in the Alpine container?
Alpine tries to be minimalistic. This also means you should not install modules you don't need. So having modules installed you don't need (e.g. only in mods-available) is bad practice.
Are *.so files equivalent to *.load files?
The so-files are also present in debian and are the modules itself. The load-files are configuration fragments to load these .so files.
If the previous is true, then how do I use the *.so files?
Just take a look into the load-Files. For example, you can load the rewrite module by using this configuration line:
LoadModule rewrite_module modules/mod_rewrite.so
You shouldn't change httpd.conf, your preference is right here. But you can put custom configuration into the /etc/apache2/conf.d and load all your modules there. Just make sure your configfiles there end with a .conf

resolve pipenv install weasyprint error in Docker

I'm using Alpine linux for my Docker setup.
Here is the Dockerfile.
# pull official base image
FROM python:3.7.4-alpine
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apk --update --upgrade --no-cache add cairo-dev pango-dev gdk-pixbuf
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev jpeg-dev zlib-dev libffi-dev\
&& apk add postgresql \
&& apk add postgresql-dev \
&& pip install psycopg2 \
&& apk add jpeg-dev zlib-dev libjpeg \
&& pip install Pillow \
&& apk del build-deps
# install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
COPY ./Pipfile /usr/src/app/Pipfile
RUN pipenv install --skip-lock --system --dev
# copy entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
# copy project
COPY . /usr/src/app/
# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
which results in stalling on the installation of cairocffi and giving the error of
unable to execute 'gcc': No such file or directory.
This page is gonna save your life, no matter if you're using pipenv or not,
For Alpine(>=3.6), use
apk --update --upgrade add gcc musl-dev jpeg-dev zlib-dev libffi-dev cairo-dev pango-dev gdk-pixbuf-dev
I found this link however, which recommends adding the line:
RUN apk add --update python python-dev py-pip build-base
to the build file and works.