Skip to content

Commit e451059

Browse files
Switch to alpine image to fix vulnerabilities (#43)
* Use separate docker file for alpine-based image * Add pipeline and create script for alpine
1 parent 3638228 commit e451059

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build-env
2+
3+
LABEL maintainer="Stef Heyenrath"
4+
5+
WORKDIR /app
6+
7+
# copy csproj and restore as distinct layers
8+
COPY StandAlone.NETCoreApp.csproj ./
9+
RUN dotnet restore
10+
11+
# copy everything else and build
12+
COPY *.cs ./
13+
RUN dotnet publish -c Release -r alpine-x64 -o out \
14+
--self-contained true \
15+
/p:PublishTrimmed=true \
16+
/p:TrimMode=Link \
17+
/p:PublishSingleFile=true
18+
19+
# build runtime image
20+
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine
21+
# resolve CVE-2023-2975
22+
RUN apk upgrade libssl3 libcrypto3 --no-cache
23+
WORKDIR /app
24+
COPY --from=build-env /app/out ./
25+
EXPOSE 80
26+
ENTRYPOINT ["./wiremock-net", "--Urls", "http://*:80"]
27+
CMD ["--WireMockLogger", "WireMockConsoleLogger"]
28+
29+
# Just some info:
30+
# build with : docker build -t sheyenrath/wiremock.net .
31+
# run with : docker run --rm -p 9091:80 sheyenrath/wiremock.net
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
docker build -t sheyenrath/wiremock.net-alpine -f .\Dockerfile.alpine .
2+
docker rmi $(docker images -f "dangling=true" -q)
3+
docker images

azure-pipelines-alpine.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
variables:
2+
buildConfiguration: 'Release'
3+
imageName: 'wiremock.net-alpine'
4+
buildProjects: '**/StandAlone.NETCoreApp.csproj'
5+
tag: '1.5.32'
6+
7+
trigger: none
8+
9+
pool:
10+
vmImage: 'Ubuntu-latest'
11+
12+
steps:
13+
- task: UseDotNet@2
14+
inputs:
15+
packageType: 'sdk'
16+
version: '6.0.x'
17+
18+
- task: DotNetCoreCLI@2
19+
displayName: Build StandAlone.NETCoreApp
20+
inputs:
21+
command: 'build'
22+
arguments: /p:Configuration=$(buildConfiguration)
23+
projects: $(buildProjects)
24+
25+
- task: Docker@2
26+
displayName: 'Build Docker [$(imageName)(latest,$(tag)]'
27+
inputs:
28+
command: 'build'
29+
containerRegistry: 'DockerRegistry'
30+
repository: '$(DOCKER_ID)/$(imageName)'
31+
dockerfile: '$(Build.SourcesDirectory)/StandAlone.NETCoreApp/Dockerfile.alpine'
32+
tags: |
33+
$(tag)
34+
latest
35+
36+
- task: Docker@2
37+
displayName: 'Push Docker [$(imageName)(latest,$(tag)]'
38+
inputs:
39+
command: 'push'
40+
containerRegistry: 'DockerRegistry'
41+
repository: '$(DOCKER_ID)/$(imageName)'
42+
dockerfile: '$(Build.SourcesDirectory)/StandAlone.NETCoreApp/Dockerfile.alpine'
43+
tags: |
44+
$(tag)
45+
latest

0 commit comments

Comments
 (0)