This repository was archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
85 lines (68 loc) · 2.4 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
81
82
83
84
85
## Global
ARG ARG_FROM_IMAGE=python
ARG ARG_FROM_IMAGE_TAG=3.9-alpine
## Builder stage
# https://hub.docker.com/_/python?tab=tags
FROM python:3.9 AS builder
ARG ARG_VENDOR=veracode
ENV ENV_VENDOR=${ARG_VENDOR}
WORKDIR /usr/src/app/
# requirements.txt is separated to improve caching
COPY "./${ENV_VENDOR}/requirements.txt" "/usr/src/app/${ENV_VENDOR}/requirements.txt"
ENV PATH=/root/.local/bin:$PATH
RUN pip3 install --user -r "${ENV_VENDOR}/requirements.txt"
## CI stage
FROM builder AS ci
# requirements.txt is separated to improve caching
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip3 install --user -r requirements.txt
## Lint Docker
# https://hub.docker.com/r/hadolint/hadolint/tags
FROM hadolint/hadolint:v1 AS lint_docker
WORKDIR /usr/src/app/
ENTRYPOINT ["hadolint"]
CMD ["Dockerfile"]
## Lint Makefile
# https://hub.docker.com/r/cytopia/checkmake/tags
FROM cytopia/checkmake:0.1.0 AS lint_make
WORKDIR /usr/src/app/
ENTRYPOINT ["checkmake"]
CMD ["Makefile"]
## Lint Python
FROM ci AS lint_python
ENTRYPOINT find . -type f -name '*.py' -exec pylint -j 0 {} +
## Lint yaml
FROM ci AS lint_yaml
ENTRYPOINT find . -type f \( -name '*.yml' -o -name '*.yaml' \) -exec yamllint {} +
## Type Annotations Linter
#FROM ci AS lint_types
#ENTRYPOINT find "${ENV_VENDOR}" -type f -name '*.py' -exec mypy {} +
## Complexity Linter
#FROM ci AS lint_complexity
#ENTRYPOINT find "${ENV_VENDOR}" -type f -name '*.py' -exec xenon --max-absolute B {} +
## Unit Tests
FROM ci AS test_unit
ENTRYPOINT ["coverage"]
CMD ["run", "-m", "unittest", "discover", "-s", "tests", "-p", "test_*.py"]
## Security Tests
FROM ci AS test_security
CMD find . -type f -name '*.py' -exec bandit {} + \
; trufflehog --regex --entropy=False file:///usr/src/app/ --exclude_paths .truffleHog-exclude.txt \
; semgrep --config=p/r2c-ci --exclude='tests' --exclude='reports' --strict --verbose /usr/src/app
## easy_sast
FROM "${ARG_FROM_IMAGE}":"${ARG_FROM_IMAGE_TAG}" AS Final
ARG ARG_VERSION
ARG ARG_VENDOR
LABEL MAINTAINER="Seiso"
LABEL AUTHOR="Jon Zeolla"
LABEL COPYRIGHT="(c) 2020 Seiso, LLC"
LABEL LICENSE="BSD-3-Clause"
LABEL VERSION="${ARG_VERSION}"
WORKDIR /usr/src/app/
COPY "./${ARG_VENDOR}" "${ARG_VENDOR}"
COPY ./main.py main.py
COPY --from=builder /root/.local /root/.local
ENV PATH="/root/.local/bin:${PATH}"
# Assumes that the compiled files/debug symbols are in a folder which is volume
# mapped to /build
ENTRYPOINT ["/usr/src/app/main.py"]