-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
80 lines (55 loc) · 1.88 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
ARG PYTHON_VER=3.11
ARG REPO_NAME=download-router-config
##################
### BASE IMAGE ###
##################
FROM python:${PYTHON_VER} AS base
ARG REPO_NAME
LABEL name=${REPO_NAME} prune=true
WORKDIR /app
RUN pip install --no-cache-dir poetry
RUN poetry config virtualenvs.create false
COPY pyproject.toml .
RUN poetry install --only main
##################
### TEST IMAGE ###
##################
FROM base AS test
ARG REPO_NAME
LABEL name=${REPO_NAME} prune=true
WORKDIR /app
COPY pyproject.toml .
COPY tests/ tests/
COPY download_router_config/ download_router_config/
RUN poetry install
RUN echo '-->Running Flake8p' && \
flake8p --config pyproject.toml . && \
echo '-->Running Black' && \
black --config pyproject.toml --check --diff . && \
echo '-->Running isort' && \
find . -path ./tests -prune -name '*.py' | xargs isort && \
echo '-->Running Pylint' && \
find . -name '*.py' | xargs pylint --rcfile=pyproject.toml && \
echo '-->Running pydocstyle' && \
pydocstyle . --config=pyproject.toml && \
echo '-->Running Bandit' && \
bandit --recursive ./ --configfile pyproject.toml && \
echo '-->Running pytest' && \
coverage run -m pytest --color=yes -vvv && \
echo '-->Running coverage' && \
coverage report
###################
### FINAL IMAGE ###
###################
FROM python:${PYTHON_VER}-slim AS cli
ARG PYTHON_VER
WORKDIR /app
RUN addgroup docker && adduser --system --shell /bin/false --disabled-password --no-create-home docker --ingroup docker
RUN mkdir -p /app/log/
COPY --from=base /usr/local/lib/python${PYTHON_VER}/site-packages /usr/local/lib/python${PYTHON_VER}/site-packages
COPY --from=base /usr/local/bin /usr/local/bin
# .dockerignore required to prevent copying unwanted files into image
COPY ./download_router_config .
RUN chown -R docker:docker /app
USER docker
ENTRYPOINT ["python", "download_router_config.py"]