-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix anchore scan for pull requests #53
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d87e8df
Refactoring to properly work with pull requests
ldallmayr 0b9a8bb
Refactor Dockerfile.local
ldallmayr 5978b47
Exclude files not relevant for building container
ldallmayr ca2890a
Add explanations
ldallmayr 83c7e12
Add non-privileged user for running threagile
ldallmayr 94c4450
Restore single qoutes
ldallmayr bcbf6df
Explicitly copy individual plugins
ldallmayr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
**/.git | ||
**/.gitignore | ||
**/.DS_Store | ||
**/*.tmp | ||
**/*.tmp | ||
.github | ||
.dockerignore | ||
Dockerfile | ||
Dockerfile.* |
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,79 +1,89 @@ | ||
# Used for local manual test builds | ||
|
||
###### | ||
## Stage 1: Clone the Git repository | ||
## Stage 1: Build application with Go's build tools | ||
###### | ||
FROM alpine/git as clone | ||
FROM docker.io/library/golang:alpine as build | ||
|
||
# Add build dependencies (gcc, c stdlib) | ||
RUN apk add --no-cache build-base | ||
|
||
WORKDIR /app | ||
#RUN git clone https://github.com/threagile/threagile.git | ||
COPY . /app/threagile | ||
|
||
# Cache build dependencies | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
# Set build-time variables | ||
ARG GOOS=linux | ||
|
||
###### | ||
## Stage 2: Build application with Go's build tools | ||
###### | ||
FROM golang as build | ||
ENV GO111MODULE=on | ||
# https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host | ||
#ENV CGO_ENABLED=0 # cannot be set as otherwise plugins don't run | ||
WORKDIR /app | ||
COPY --from=clone /app/threagile /app | ||
RUN go version | ||
RUN go test ./... | ||
RUN GOOS=linux go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -buildmode=plugin -o raa.so raa/raa/raa.go | ||
RUN GOOS=linux go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -buildmode=plugin -o dummy.so raa/dummy/dummy.go | ||
RUN GOOS=linux go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -buildmode=plugin -o demo-rule.so risks/custom/demo/demo-rule.go | ||
RUN GOOS=linux go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -o threagile | ||
# add the -race parameter to go build call in order to instrument with race condition detector: https://blog.golang.org/race-detector | ||
RUN : \ | ||
&& go version \ | ||
&& go test ./... | ||
|
||
# Build plugins and threagile | ||
RUN : \ | ||
&& go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -buildmode=plugin -o raa.so raa/raa/raa.go \ | ||
&& go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -buildmode=plugin -o dummy.so raa/dummy/dummy.go \ | ||
&& go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -buildmode=plugin -o demo-rule.so risks/custom/demo/demo-rule.go \ | ||
&& go build -a -trimpath -ldflags="-s -w -X main.buildTimestamp=$(date '+%Y%m%d%H%M%S')" -o threagile | ||
|
||
# Copy files in build image to simplify copy instruction | ||
RUN : \ | ||
&& cp /app/demo/example/threagile.yaml /app/demo/example/threagile-example-model.yaml \ | ||
&& cp /app/demo/stub/threagile.yaml /app/demo/stub/threagile-stub-model.yaml | ||
|
||
|
||
###### | ||
## Stage 3: Make final small image | ||
## Stage 2: Make final small image | ||
###### | ||
FROM alpine | ||
FROM docker.io/library/alpine:latest | ||
|
||
# label used in other scripts to filter | ||
# Label used in other scripts to filter | ||
LABEL type="threagile" | ||
|
||
# add certificates | ||
RUN apk add ca-certificates | ||
# add graphviz, fonts | ||
RUN apk add --update --no-cache graphviz ttf-freefont | ||
# https://stackoverflow.com/questions/66963068/docker-alpine-executable-binary-not-found-even-if-in-path | ||
RUN apk add libc6-compat | ||
# https://stackoverflow.com/questions/34729748/installed-go-binary-not-found-in-path-on-alpine-linux-docker | ||
# RUN mkdir -p /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 | ||
# clean apk cache | ||
RUN rm -rf /var/cache/apk/* | ||
RUN apk add --no-cache \ | ||
ca-certificates \ | ||
graphviz \ | ||
ttf-freefont | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /app/threagile /app/threagile | ||
COPY --from=build /app/raa.so /app/raa.so | ||
COPY --from=build /app/dummy.so /app/dummy.so | ||
COPY --from=build /app/demo-rule.so /app/demo-rule.so | ||
COPY --from=build /app/LICENSE.txt /app/LICENSE.txt | ||
COPY --from=build /app/report/template/background.pdf /app/background.pdf | ||
COPY --from=build /app/support/openapi.yaml /app/openapi.yaml | ||
COPY --from=build /app/support/schema.json /app/schema.json | ||
COPY --from=build /app/support/live-templates.txt /app/live-templates.txt | ||
COPY --from=build /app/support/render-data-asset-diagram.sh /app/render-data-asset-diagram.sh | ||
COPY --from=build /app/support/render-data-flow-diagram.sh /app/render-data-flow-diagram.sh | ||
COPY --from=build /app/server /app/server | ||
COPY --from=build /app/demo/example/threagile.yaml /app/threagile-example-model.yaml | ||
COPY --from=build /app/demo/stub/threagile.yaml /app/threagile-stub-model.yaml | ||
|
||
RUN mkdir /data | ||
|
||
RUN chown -R 1000:1000 /app /data | ||
USER 1000:1000 | ||
|
||
ENV PATH=/app:$PATH | ||
ENV GIN_MODE=release | ||
# Add non-privileged user for running threagile | ||
RUN adduser \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kudos for adding best security practices for the project which is about improving security ;) |
||
--disabled-password \ | ||
--gecos "" \ | ||
--home "$(pwd)" \ | ||
--no-create-home \ | ||
threagile | ||
|
||
# Copy necessary files from build image | ||
COPY --from=build \ | ||
/app/raa.so \ | ||
/app/dummy.so \ | ||
/app/demo-rule.so \ | ||
/app/demo/example/threagile-example-model.yaml \ | ||
/app/demo/stub/threagile-stub-model.yaml \ | ||
/app/LICENSE.txt \ | ||
/app/report/template/background.pdf \ | ||
/app/support/ \ | ||
/app/threagile \ | ||
/app/ | ||
|
||
COPY --from=build \ | ||
/app/server \ | ||
/app/server | ||
|
||
RUN : \ | ||
&& mkdir /data \ | ||
&& chown -R threagile:threagile /app /data | ||
|
||
USER threagile | ||
|
||
ENV PATH="${PATH}:/app" \ | ||
GIN_MODE=release | ||
|
||
ENTRYPOINT ["/app/threagile"] | ||
CMD ["-help"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to know the context why adding libc6-compat (
RUN apk add libc6-compat
) was removed. As far as I can see that was a workaround, is adding everything withing oneRUN apk add
fixing the problem and how?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the building step to run in
golang:alpine
instead of the defaultgolang
(which is based on Debian). Because of this we do not needlibc6-compat
as a compatibility layer for glibc anymore.