Skip to content

Instantly share code, notes, and snippets.

@khaerulumam42
Created December 20, 2021 04:10
Show Gist options
  • Save khaerulumam42/1c33a130685a783d546fda52f472e64e to your computer and use it in GitHub Desktop.
Save khaerulumam42/1c33a130685a783d546fda52f472e64e to your computer and use it in GitHub Desktop.
FROM python:3.9-slim-buster as builder
LABEL MAINTAINER "Khaerul Umam <[email protected]>"
LABEL DESCRIPTION "consumer"
RUN apt-get update && apt-get upgrade -y \
&& apt-get install -y python3 python3-pip \
python3-setuptools gfortran liblapack-dev liblapack3 nano \
default-libmysqlclient-dev\
supervisor locales \
&& python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt
FROM python:3.9-slim-buster as run
ARG APP_USER="consumer"
ARG WORK_DIRECTORY="/app"
COPY . /app
WORKDIR $WORK_DIRECTORY
RUN apt-get update -y && apt-get upgrade -y \
&& apt-get install -y --no-install-recommends libgomp1 locales dumb-init default-libmysqlclient-dev \
&& useradd -rm -d $WORK_DIRECTORY -s /bin/bash -U $APP_USER \
&& chown -R $APP_USER:$APP_USER $WORK_DIRECTORY \
&& locale-gen en_US.UTF-8 \
&& export LC_ALL=en_US.UTF-8 \
&& export LANG=en_US.UTF-8 \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone \
&& apt-get clean
USER $APP_USER
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
ENV PYTHONPATH="${WORK_DIRECTORY}:$PYTHONPATH"
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["python3"]
FROM python:3.9-slim-buster as builder
LABEL MAINTAINER "Khaerul Umam <[email protected]>"
LABEL DESCRIPTION "producer"
RUN apt-get update && apt-get upgrade -y \
&& apt-get install -y python3 python3-pip \
python3-setuptools gfortran liblapack-dev liblapack3 nano \
default-libmysqlclient-dev\
supervisor locales \
&& python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt
FROM python:3.9-slim-buster as run
ARG APP_USER="producer"
ARG WORK_DIRECTORY="/app"
COPY . /app
WORKDIR $WORK_DIRECTORY
RUN apt-get update -y && apt-get upgrade -y \
&& apt-get install -y --no-install-recommends libgomp1 locales dumb-init default-libmysqlclient-dev \
&& useradd -rm -d $WORK_DIRECTORY -s /bin/bash -U $APP_USER \
&& chown -R $APP_USER:$APP_USER $WORK_DIRECTORY \
&& locale-gen en_US.UTF-8 \
&& export LC_ALL=en_US.UTF-8 \
&& export LANG=en_US.UTF-8 \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone \
&& apt-get clean
USER $APP_USER
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
ENV PYTHONPATH="${WORK_DIRECTORY}:$PYTHONPATH"
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["python3"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment