-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
130 lines (94 loc) · 4.11 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
###############################################################################
FROM mcr.microsoft.com/dotnet/sdk:8.0.402-alpine3.19-amd64 AS init
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
RUN apk add --update --no-cache make \
&& apk upgrade --no-cache # Avoid some CVE reports updating basic packages.
###############################################################################
FROM init AS base
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
COPY ./Makefile ${WORKDIR}/
COPY ./algorithm_exercises_csharp.sln ${WORKDIR}/algorithm_exercises_csharp.sln
COPY ./algorithm_exercises_csharp/algorithm_exercises_csharp.csproj ${WORKDIR}/algorithm_exercises_csharp/algorithm_exercises_csharp.csproj
COPY ./algorithm_exercises_csharp_base/algorithm_exercises_csharp_base.csproj ${WORKDIR}/algorithm_exercises_csharp_base/algorithm_exercises_csharp_base.csproj
COPY ./algorithm_exercises_csharp_test/algorithm_exercises_csharp_test.csproj ${WORKDIR}/algorithm_exercises_csharp_test/algorithm_exercises_csharp_test.csproj
RUN make dependencies
###############################################################################
FROM base AS lint
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
RUN apk add --update --no-cache make nodejs npm \
&& apk add --update --no-cache yamllint \
&& npm install -g --ignore-scripts markdownlint-cli
# [!TIP] Use a bind-mount to "/app" to override following "copys"
# for lint and test against "current" sources in this stage
# YAML sources
COPY ./.github ${WORKDIR}/
COPY ./compose.yaml ${WORKDIR}/
# Markdown sources
COPY ./docs ${WORKDIR}/
COPY ./README.md ${WORKDIR}/
COPY ./LICENSE.md ${WORKDIR}/
COPY ./CODE_OF_CONDUCT.md ${WORKDIR}/
# Code source
COPY ./algorithm_exercises_csharp.sln ${WORKDIR}/algorithm_exercises_csharp.sln
COPY ./algorithm_exercises_csharp ${WORKDIR}/algorithm_exercises_csharp
COPY ./algorithm_exercises_csharp_base ${WORKDIR}/algorithm_exercises_csharp_base
COPY ./algorithm_exercises_csharp_test ${WORKDIR}/algorithm_exercises_csharp_test
# code linting conf
COPY ./.editorconfig ${WORKDIR}/
# markdownlint conf
COPY ./.markdownlint.yaml ${WORKDIR}/
# yamllint conf
COPY ./.yamllint ${WORKDIR}/
COPY ./.yamlignore ${WORKDIR}/
CMD ["make", "lint"]
###############################################################################
FROM base AS development
COPY ./algorithm_exercises_csharp.sln ${WORKDIR}/algorithm_exercises_csharp.sln
COPY ./algorithm_exercises_csharp ${WORKDIR}/algorithm_exercises_csharp
COPY ./algorithm_exercises_csharp_base ${WORKDIR}/algorithm_exercises_csharp_base
COPY ./algorithm_exercises_csharp_test ${WORKDIR}/algorithm_exercises_csharp_test
RUN make build \
&& ls -alh
# CMD []
###############################################################################
FROM development AS builder
RUN dotnet publish --self-contained --runtime linux-musl-x64 \
&& ls -alh
CMD ["ls", "-alh"]
###############################################################################
### In testing stage, can't use USER, due permissions issue
## in github actions environment:
##
## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
##
FROM development AS testing
ENV LOG_LEVEL=INFO
ENV BRUTEFORCE=false
WORKDIR /app
RUN ls -alh
CMD ["make", "test"]
###############################################################################
### In production stage
## in the production phase, "good practices" such as
## WORKDIR and USER are maintained
##
FROM mcr.microsoft.com/dotnet/runtime:8.0.8-alpine3.19-amd64 AS production
RUN apk add --update --no-cache make \
&& apk upgrade --no-cache # Avoid some CVE reports updating basic packages.
ENV LOG_LEVEL=info
ENV BRUTEFORCE=false
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
RUN adduser -D worker \
&& mkdir -p /app \
&& chown worker:worker /app
COPY ./Makefile ${WORKDIR}/
COPY --from=builder /app/algorithm_exercises_csharp/bin/Release/net8.0/algorithm_exercises_csharp.dll ${WORKDIR}/
COPY --from=builder /app/algorithm_exercises_csharp/bin/Release/net8.0/algorithm_exercises_csharp.runtimeconfig.json ${WORKDIR}/
RUN ls -alh
USER worker
CMD ["make", "run"]
# checkov:skip= CKV_DOCKER_2: production image isn't a service process (yet)