-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from underdog-tech/feat/improved-dockerfile
feat: Improved Dockerfile / build / test
- Loading branch information
Showing
5 changed files
with
91 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.editorconfig | ||
.env | ||
.git/ | ||
.github/ | ||
coverage* | ||
*.md | ||
*.toml |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @underdog-tech/vulnbot-contributors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
FROM alpine:3.17 AS base | ||
# We want to build on a canonical Golang image to easily use the latest/greatest | ||
FROM golang:1.20 AS build | ||
|
||
WORKDIR /app | ||
|
||
FROM base AS builder | ||
# Set up pieces necessary for our final release image | ||
RUN echo "nonroot:x:65534:65534:Nonroot:/:" > /etc/passwd.min | ||
|
||
# Make sure the dependency downloading can be cached | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o ./vulnbot | ||
|
||
# This stage is by default un-used, but allows us to easily run our tests inside | ||
# of an actual Docker image. | ||
FROM build as test | ||
|
||
# We do not use -race here because it is not supported on arm64 | ||
# https://github.com/golang/go/issues/29948 | ||
RUN go test -v ./... | ||
|
||
# Final image uses a barebones image | ||
FROM scratch AS release | ||
|
||
RUN apk update && apk upgrade && apk add go | ||
RUN go build . | ||
WORKDIR / | ||
COPY --from=build /etc/passwd.min /etc/passwd | ||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
FROM base AS final | ||
USER nonroot | ||
|
||
COPY --from=builder /app/vulnbot /app/ | ||
COPY --from=build /app/vulnbot /vulnbot | ||
|
||
ENTRYPOINT [ "./vulnbot" ] | ||
ENTRYPOINT [ "/vulnbot" ] |