github.com/grafana/pyroscope@v1.18.0/examples/language-sdk-instrumentation/python/rideshare/django/app/Dockerfile.prod (about)

     1  ###########
     2  # BUILDER #
     3  ###########
     4  
     5  # pull official base image
     6  FROM python:3.9.6-alpine as builder
     7  
     8  # set work directory
     9  WORKDIR /usr/src/app
    10  
    11  # set environment variables
    12  ENV PYTHONDONTWRITEBYTECODE 1
    13  ENV PYTHONUNBUFFERED 1
    14  
    15  # install psycopg2 dependencies
    16  RUN apk update \
    17      && apk add postgresql-dev gcc python3-dev musl-dev
    18  
    19  # lint
    20  RUN pip install --upgrade pip
    21  RUN pip install flake8==3.9.2
    22  COPY . .
    23  RUN flake8 --ignore=E501,F401 .
    24  
    25  # install dependencies
    26  COPY ./requirements.txt .
    27  RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
    28  
    29  
    30  #########
    31  # FINAL #
    32  #########
    33  
    34  # pull official base image
    35  FROM python:3.9.6-alpine
    36  
    37  # create directory for the app user
    38  RUN mkdir -p /home/app
    39  
    40  # create the app user
    41  RUN addgroup -S app && adduser -S app -G app
    42  
    43  # create the appropriate directories
    44  ENV HOME=/home/app
    45  ENV APP_HOME=/home/app/web
    46  RUN mkdir $APP_HOME
    47  RUN mkdir $APP_HOME/staticfiles
    48  RUN mkdir $APP_HOME/mediafiles
    49  WORKDIR $APP_HOME
    50  
    51  # install dependencies
    52  RUN apk update && apk add libpq
    53  COPY --from=builder /usr/src/app/wheels /wheels
    54  COPY --from=builder /usr/src/app/requirements.txt .
    55  RUN pip install --no-cache /wheels/*
    56  
    57  # copy entrypoint.prod.sh
    58  COPY ./entrypoint.prod.sh .
    59  RUN sed -i 's/\r$//g'  $APP_HOME/entrypoint.prod.sh
    60  RUN chmod +x  $APP_HOME/entrypoint.prod.sh
    61  
    62  # copy project
    63  COPY . $APP_HOME
    64  
    65  # chown all the files to the app user
    66  RUN chown -R app:app $APP_HOME
    67  
    68  # change to the app user
    69  USER app
    70  
    71  # run entrypoint.prod.sh
    72  ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]