Browse Source

Migra imagem do SAPL de Alpine para Debian (#3256)

* Migra imagem do SAPL de Alpine para Debian (slim-buster)

* Otimiza criação de imagem

* Mais refactorings

Co-authored-by: eribeiro <edwardr@senado.leg.br>
pull/3261/head
Edward 4 years ago
committed by GitHub
parent
commit
85be85f75e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      Dockerfile
  2. 9
      gunicorn_start.sh
  3. 2
      start.sh

50
Dockerfile

@ -1,36 +1,41 @@
FROM alpine:3.10 FROM python:3.7-slim-buster
ENV BUILD_PACKAGES postgresql-dev graphviz-dev graphviz build-base git pkgconfig \ # Setup env
python3-dev libxml2-dev jpeg-dev libressl-dev libffi-dev libxslt-dev \ ENV LANG C.UTF-8
nodejs py3-lxml py3-magic postgresql-client poppler-utils antiword \ ENV LC_ALL C.UTF-8
curl jq openssh-client vim bash postgresql-client cairo-dev ENV PYTHONDONTWRITEBYTECODE 1
RUN apk update --update-cache && apk upgrade #ENV PYTHONFAULTHANDLER 1
RUN apk --update add fontconfig ttf-dejavu && fc-cache -fv ENV DEBIAN_FRONTEND noninteractive
RUN apk add --no-cache python3 nginx tzdata && \ ENV BUILD_PACKAGES apt-file libpq-dev graphviz-dev graphviz build-essential git pkg-config \
python3 -m ensurepip && \ python3-dev libxml2-dev libjpeg-dev libssl-dev libffi-dev libxslt1-dev \
rm -r /usr/lib/python*/ensurepip && \ python3-lxml python3-magic postgresql-client libcairo2-dev \
pip3 install --upgrade pip setuptools && \ python3-psycopg2 poppler-utils vim curl jq vim bash software-properties-common \
pip3 install wheel && \ software-properties-common python3-setuptools python3-venv nginx tzdata nodejs
rm -r /root/.cache && \
rm -f /etc/nginx/conf.d/*
RUN mkdir -p /var/interlegis/sapl && \ RUN mkdir -p /var/interlegis/sapl
apk add --update --no-cache $BUILD_PACKAGES
WORKDIR /var/interlegis/sapl/ WORKDIR /var/interlegis/sapl/
ADD . /var/interlegis/sapl/ ADD . /var/interlegis/sapl/
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends apt-utils && \
mkdir -p /usr/share/man/man1 && mkdir -p /usr/share/man/man7 && \
apt-get install -y fontconfig ttf-dejavu && fc-cache -fv && \
apt-get install -y --no-install-recommends $BUILD_PACKAGES && \
apt-get install -y python python3-pip && \
pip3 install --upgrade pip setuptools && \
rm -f /etc/nginx/conf.d/* && \
pip install -r /var/interlegis/sapl/requirements/dev-requirements.txt --upgrade setuptools && \
rm -r /root/.cache && \
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*
COPY start.sh /var/interlegis/sapl/ COPY start.sh /var/interlegis/sapl/
COPY config/nginx/sapl.conf /etc/nginx/conf.d COPY config/nginx/sapl.conf /etc/nginx/conf.d
COPY config/nginx/nginx.conf /etc/nginx/nginx.conf COPY config/nginx/nginx.conf /etc/nginx/nginx.conf
RUN pip install -r /var/interlegis/sapl/requirements/dev-requirements.txt --upgrade setuptools && \
rm -r /root/.cache
COPY config/env_dockerfile /var/interlegis/sapl/sapl/.env COPY config/env_dockerfile /var/interlegis/sapl/sapl/.env
RUN python3 manage.py collectstatic --noinput --clear RUN python3 manage.py collectstatic --noinput --clear
@ -46,6 +51,13 @@ RUN chmod +x /var/interlegis/sapl/start.sh && \
mkdir /var/log/sapl/ && touch /var/interlegis/sapl/sapl.log && \ mkdir /var/log/sapl/ && touch /var/interlegis/sapl/sapl.log && \
ln -s /var/interlegis/sapl/sapl.log /var/log/sapl/sapl.log ln -s /var/interlegis/sapl/sapl.log /var/log/sapl/sapl.log
# Debian não possui usuário 'nginx' necessário para o Debian
RUN useradd --no-create-home nginx
ENV DEBIAN_FRONTEND teletype
EXPOSE 80/tcp 443/tcp
VOLUME ["/var/interlegis/sapl/data", "/var/interlegis/sapl/media"] VOLUME ["/var/interlegis/sapl/data", "/var/interlegis/sapl/media"]
CMD ["/var/interlegis/sapl/start.sh"] CMD ["/var/interlegis/sapl/start.sh"]

9
gunicorn_start.sh

@ -25,15 +25,6 @@ DJANGO_WSGI_MODULE=sapl.wsgi # WSGI module name (*)
echo "Starting $NAME as `whoami` on base dir $SAPL_DIR" echo "Starting $NAME as `whoami` on base dir $SAPL_DIR"
# parameter can be passed to run without virtualenv
if [[ "$@" != "no-venv" ]]; then
# Activate the virtual environment
cd $DJANGODIR
source /var/interlegis/.virtualenvs/sapl/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
fi
# Create the run directory if it doesn't exist # Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE) RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR test -d $RUNDIR || mkdir -p $RUNDIR

2
start.sh

@ -117,5 +117,5 @@ echo "| ███████║██║ ██║██║ ████
echo "| ╚══════╝╚═╝ ╚═╝╚═╝ ╚══════╝ |" echo "| ╚══════╝╚═╝ ╚═╝╚═╝ ╚══════╝ |"
echo "-------------------------------------" echo "-------------------------------------"
/bin/sh gunicorn_start.sh no-venv & /bin/sh gunicorn_start.sh &
/usr/sbin/nginx -g "daemon off;" /usr/sbin/nginx -g "daemon off;"

Loading…
Cancel
Save