Skip to content

Commit 91c8d85

Browse files
author
Gonzalo Diaz
committed
[CONFIG] [Docker] building process re-organized.
[StackOverflow] A fatal error was encountered. The library 'libhostpolicy.so' required: https://stackoverflow.com/a/59185091/6366150
1 parent fa60292 commit 91c8d85

File tree

4 files changed

+86
-21
lines changed

4 files changed

+86
-21
lines changed

Dockerfile

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,107 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0.302-alpine3.19-amd64 AS base
44
ENV WORKDIR=/app
55
WORKDIR ${WORKDIR}
66

7+
RUN apk add --update --no-cache make
8+
79
###############################################################################
810
FROM base AS lint
911

1012
ENV WORKDIR=/app
1113
WORKDIR ${WORKDIR}
1214

13-
COPY ./docs ${WORKDIR}/docs
1415
RUN apk add --update --no-cache make nodejs npm
1516
RUN apk add --update --no-cache yamllint
1617

1718
RUN npm install -g --ignore-scripts markdownlint-cli
1819

19-
###############################################################################
20-
FROM base AS development
20+
# [!TIP] Use a bind-mount to "/app" to override following "copys"
21+
# for lint and test against "current" sources in this stage
2122

22-
RUN apk add --update --no-cache make
23+
# YAML sources
24+
COPY ./.github ${WORKDIR}/
25+
COPY ./compose.yaml ${WORKDIR}/
26+
27+
# Markdown sources
28+
COPY ./docs ${WORKDIR}/
29+
COPY ./README.md ${WORKDIR}/
30+
COPY ./LICENSE.md ${WORKDIR}/
31+
COPY ./CODE_OF_CONDUCT.md ${WORKDIR}/
32+
33+
# Code source
34+
COPY ./algorithm-exercises-csharp ${WORKDIR}/algorithm-exercises-csharp
35+
COPY ./algorithm-exercises-csharp-test ${WORKDIR}/algorithm-exercises-csharp-test
36+
COPY ./algorithm-exercises-csharp.sln ${WORKDIR}/algorithm-exercises-csharp.sln
37+
COPY ./Makefile ${WORKDIR}/
38+
39+
# code linting conf
40+
COPY ./.editorconfig ${WORKDIR}/
41+
42+
# markdownlint conf
43+
COPY ./.markdownlint.yaml ${WORKDIR}/
44+
45+
# yamllint conf
46+
COPY ./.yamllint ${WORKDIR}/
47+
COPY ./.yamlignore ${WORKDIR}/
2348

2449
###############################################################################
25-
FROM development AS builder
50+
FROM base AS development
2651

2752
COPY ./algorithm-exercises-csharp ${WORKDIR}/algorithm-exercises-csharp
53+
COPY ./algorithm-exercises-csharp-test ${WORKDIR}/algorithm-exercises-csharp-test
2854
COPY ./algorithm-exercises-csharp.sln ${WORKDIR}/algorithm-exercises-csharp.sln
2955
COPY ./Makefile ${WORKDIR}/
56+
57+
RUN make build
58+
RUN ls -alh
59+
60+
# CMD []
61+
###############################################################################
62+
FROM development AS builder
63+
64+
RUN dotnet publish --self-contained --runtime linux-musl-x64
3065
RUN ls -alh
3166

67+
CMD ["ls", "-alh"]
68+
3269
###############################################################################
3370
### In testing stage, can't use USER, due permissions issue
3471
## in github actions environment:
3572
##
3673
## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
3774
##
38-
FROM builder AS testing
75+
FROM development AS testing
3976

4077
ENV LOG_LEVEL=INFO
4178
ENV BRUTEFORCE=false
4279

4380
WORKDIR /app
4481

45-
COPY ./algorithm-exercises-csharp-test ${WORKDIR}/algorithm-exercises-csharp-test
4682
RUN ls -alh
4783

48-
CMD ["dotnet", "test"]
84+
CMD ["make", "test"]
4985

5086
###############################################################################
5187
### In production stage
5288
## in the production phase, "good practices" such as
53-
## WORKSPACE and USER are maintained
89+
## WORKDIR and USER are maintained
5490
##
55-
FROM builder AS production
91+
FROM mcr.microsoft.com/dotnet/runtime:8.0.3-alpine3.19-amd64 AS production
5692

57-
ENV LOG_LEVEL=INFO
93+
ENV LOG_LEVEL=info
5894
ENV BRUTEFORCE=false
95+
ENV WORKDIR=/app
96+
WORKDIR ${WORKDIR}
5997

6098
RUN adduser -D worker
6199
RUN mkdir -p /app
62100
RUN chown worker:worker /app
63101

64-
WORKDIR /app
102+
RUN apk add --update --no-cache make
103+
COPY ./Makefile ${WORKDIR}/
104+
COPY --from=builder /app/algorithm-exercises-csharp/bin/Release/net8.0/algorithm-exercises-csharp.dll ${WORKDIR}/
105+
COPY --from=builder /app/algorithm-exercises-csharp/bin/Release/net8.0/algorithm-exercises-csharp.runtimeconfig.json ${WORKDIR}/
65106

66-
COPY ./.pylintrc ${WORKDIR}/
67-
COPY ./.coveragerc ${WORKDIR}/
68107
RUN ls -alh
69108

70109
USER worker
71-
CMD ["make", "test", "-e", "{DEBUG}"]
110+
CMD ["make", "run"]

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ format:
8787
build: env dependencies
8888
${PACKAGE_TOOL} build --verbosity ${VERBOSITY_LEVEL}
8989

90+
release: dependencies
91+
${PACKAGE_TOOL} publish --verbosity ${VERBOSITY_LEVEL}
92+
9093
test: build
9194
${PACKAGE_TOOL} test --verbosity ${VERBOSITY_LEVEL} --collect:"Code Coverage"
9295

@@ -119,10 +122,12 @@ clean:
119122
compose/build: env
120123
docker-compose --profile lint build
121124
docker-compose --profile testing build
125+
docker-compose --profile production build
122126

123127
compose/rebuild: env
124128
docker-compose --profile lint build --no-cache
125129
docker-compose --profile testing build --no-cache
130+
docker-compose --profile production build --no-cache
126131

127132
compose/lint/markdown: compose/build
128133
docker-compose --profile lint run --rm algorithm-exercises-csharp-lint make lint/markdown
@@ -134,11 +139,17 @@ compose/test/styling: compose/build
134139
docker-compose --profile lint run --rm algorithm-exercises-csharp-lint make test/styling
135140

136141
compose/test/static: compose/build
137-
docker-compose --profile testing run --rm algorithm-exercises-csharp make test/static
142+
docker-compose --profile lint run --rm algorithm-exercises-csharp-lint make test/static
138143

139144
compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static
140145

146+
compose/test: compose/build
147+
docker-compose --profile testing run --rm algorithm-exercises-csharp-test make test
148+
141149
compose/run: compose/build
142-
docker-compose --profile testing run --rm algorithm-exercises-csharp make test
150+
docker-compose --profile production run --rm algorithm-exercises-csharp make run
143151

144152
all: lint coverage
153+
154+
run:
155+
ls -alh

algorithm-exercises-csharp/algorithm-exercises-csharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88

9+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
10+
911
<!-- Static Analysis -->
1012
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1113
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

compose.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
services:
3-
algorithm-exercises-csharp:
4-
image: algorithm-exercises-csharp:latest
3+
algorithm-exercises-csharp-test:
4+
image: algorithm-exercises-csharp:test
55
build:
66
context: .
77
target: testing
@@ -18,8 +18,8 @@ services:
1818
context: .
1919
target: lint
2020
# environment:
21-
#  LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
22-
#  BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
21+
# LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
22+
# BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
2323
volumes:
2424
- ./:/app
2525
profiles: ["lint"]
@@ -35,6 +35,19 @@ services:
3535
volumes:
3636
- ./:/app
3737
profiles: ["development"]
38+
39+
algorithm-exercises-csharp:
40+
image: algorithm-exercises-csharp:latest
41+
build:
42+
context: .
43+
target: production
44+
environment:
45+
LOG_LEVEL: ${LOG_LEVEL:-INFO}
46+
BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
47+
# volumes:
48+
# - ./:/app
49+
profiles: ["production"]
50+
3851
## REFERENCES:
3952
## (1) Passing Environment variable with fallback value:
4053
## https://stackoverflow.com/a/70772707/6366150

0 commit comments

Comments
 (0)