logs-collector/Dockerfile

64 lines
1.6 KiB
Docker
Raw Normal View History

2023-08-30 21:26:53 +08:00
# app/Dockerfile
# pull the official docker image
FROM python:3.10-alpine as base
# set env variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
# install app dependences
2023-08-30 21:26:53 +08:00
COPY requirements.txt ./
RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt
# now multistage builds
2023-08-30 21:26:53 +08:00
FROM python:3.10-alpine
# set env variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# default build args
ARG VERSION=0.1.0 \
APP_DIR=/app \
SRC_DIR=./logs_collector \
SCRIPTS_DIR=./scripts \
WEB_PORT=8000 \
USER_NAME=collector \
USER_GROUP=collector \
APP_UID=1000 \
APP_GID=1000
# copy app dependences
2023-08-30 21:26:53 +08:00
COPY --from=base /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/
COPY --from=base /usr/local/bin/ /usr/local/bin/
# add curl and createa user to avoid running container as root
RUN apk add --no-cache --upgrade curl && \
addgroup --system ${USER_GROUP} --gid ${APP_GID} && \
adduser --system --uid ${APP_UID} --ingroup ${USER_GROUP} ${USER_NAME}
# switch to user
USER ${USER_NAME}
# copy src and entrypoint.sh to app dir
COPY --chown=${USER_NAME}:${USER_GROUP} ${SRC_DIR} ${APP_DIR}
COPY --chown=${USER_NAME}:${USER_GROUP} ${SCRIPTS_DIR}/entrypoint.sh ${APP_DIR}/
# set workdir
WORKDIR ${APP_DIR}
# app listens on this port by default
EXPOSE ${WEB_PORT}
2023-08-30 21:26:53 +08:00
# set lables about app
LABEL maintainer="s.zhukovskii@ispsystem.com"
LABEL me.zhukovsky.logs-collector.version=v${VERSION}
2023-08-30 21:26:53 +08:00
# call the health check endpoint of app
HEALTHCHECK CMD curl --fail http://localhost:${WEB_PORT} || exit 1
2023-08-30 21:26:53 +08:00
# run app
2023-08-30 21:26:53 +08:00
ENTRYPOINT [ "sh", "entrypoint.sh" ]