net/flask/Dockerfile

70 lines
1.4 KiB
Text
Raw Normal View History

2023-11-17 19:58:12 -05:00
###########
# BUILDER #
###########
2022-02-03 17:27:25 -05:00
# pull official base image
2023-11-17 19:58:12 -05:00
FROM python:3 as builder
2022-02-03 17:27:25 -05:00
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install system dependencies
2023-11-17 19:58:12 -05:00
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc
# lint
RUN pip install --upgrade pip
RUN pip install flake8
COPY . /usr/src/app/
2023-11-17 20:13:22 -05:00
#RUN flake8 --ignore=E501,F401 .
2023-11-17 19:58:12 -05:00
# install python dependencies
COPY ./requirements.txt .
2023-11-17 21:07:16 -05:00
RUN --mount=type=cache,target=/root/.cache \
pip install --wheel-dir /usr/src/app/wheels -r requirements.txt
2023-11-17 19:58:12 -05:00
#########
# FINAL #
#########
# pull official base image
FROM python:3
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup --system app && adduser --system --group app
# create the appropriate directories
2023-11-17 21:07:16 -05:00
ENV APP_HOME=/app
2023-11-17 19:58:12 -05:00
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
2022-02-03 17:27:25 -05:00
# install dependencies
2023-11-17 20:13:22 -05:00
RUN apt-get update && apt-get install -y --no-install-recommends netcat-openbsd
2023-11-17 19:58:12 -05:00
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
2022-02-03 17:27:25 -05:00
RUN pip install --upgrade pip
2023-11-17 19:58:12 -05:00
RUN pip install --no-cache /wheels/*
# copy entrypoint.sh
COPY ./entrypoint.sh $APP_HOME
2022-02-03 17:27:25 -05:00
# copy project
2023-11-17 19:58:12 -05:00
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
2022-02-03 17:27:25 -05:00
# run entrypoint.sh
2023-11-17 19:58:12 -05:00
ENTRYPOINT ["/home/app/web/entrypoint.sh"]