Skip to content

Commit

Permalink
build: add compiler options -buildmode=pie and -trimpath
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Menges <[email protected]>
  • Loading branch information
Garfield96 committed Oct 2, 2022
1 parent 6463d6d commit fc9fdeb
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/fluent-manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ COPY controllers controllers/
COPY pkg pkg/

# Build
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GO111MODULE=on go build -buildmode=pie -trimpath -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluent-watcher/fluentbit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN mkdir -p /code
COPY . /code/
WORKDIR /code
RUN echo $(ls -al /code)
RUN CGO_ENABLED=0 go build -ldflags '-w -s' -o /fluent-bit/fluent-bit /code/cmd/fluent-watcher/fluentbit/main.go
RUN CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags '-w -s' -o /fluent-bit/fluent-bit /code/cmd/fluent-watcher/fluentbit/main.go

FROM fluent/fluent-bit:1.9.9
LABEL Description="Fluent Bit docker image" Vendor="Fluent" Version="1.0"
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluent-watcher/fluentd/Dockerfile.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN mkdir -p /code
COPY . /code/
WORKDIR /code
RUN echo $(ls -al /code)
RUN CGO_ENABLED=0 go build -ldflags '-w -s' -o /fluentd/fluentd-watcher /code/cmd/fluent-watcher/fluentd/main.go
RUN CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags '-w -s' -o /fluentd/fluentd-watcher /code/cmd/fluent-watcher/fluentd/main.go

# Fluentd main image
FROM alpine:3.13
Expand Down
4 changes: 2 additions & 2 deletions cmd/fluent-watcher/fluentd/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ RUN mkdir -p /code
COPY . /code/
WORKDIR /code
RUN echo $(ls -al /code)
RUN CGO_ENABLED=0 go build -ldflags '-w -s' -o /fluentd/fluentd-watcher /code/cmd/fluent-watcher/fluentd/main.go
RUN CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags '-w -s' -o /fluentd/fluentd-watcher /code/cmd/fluent-watcher/fluentd/main.go

# To set multiarch build for Docker hub automated build.
# To set multiarch build -buildmode=pie -trimpath for Docker hub automated build.
FROM golang:alpine AS builderqemu
WORKDIR /go
ENV QEMU_DOWNLOAD_SHA256 5db25cccb40ac7b1ca857653b883376b931d91b06ff34ffe70dcf6180bd07bb8
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluent-watcher/fluentd/Dockerfile.arm64.base
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# To set multiarch build for Docker hub automated build.
# To set multiarch build -buildmode=pie -trimpath for Docker hub automated build.
FROM golang:alpine AS builderqemu
WORKDIR /go
ENV QEMU_DOWNLOAD_SHA256 5db25cccb40ac7b1ca857653b883376b931d91b06ff34ffe70dcf6180bd07bb8
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluent-watcher/fluentd/Dockerfile.arm64.quick
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN mkdir -p /code
COPY . /code/
WORKDIR /code
RUN echo $(ls -al /code)
RUN CGO_ENABLED=0 go build -ldflags '-w -s' -o /fluentd/fluentd-watcher /code/cmd/fluent-watcher/fluentd/main.go
RUN CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags '-w -s' -o /fluentd/fluentd-watcher /code/cmd/fluent-watcher/fluentd/main.go

# Fluentd main image
FROM kubesphere/fluentd:v1.14.6-arm64-base
Expand Down
2 changes: 1 addition & 1 deletion docs/best-practice/forwarding-logs-via-http/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM golang:1.19.1 as builder

WORKDIR /
COPY main.go /go/src/main.go
RUN CGO_ENABLED=0 go build /go/src/main.go
RUN CGO_ENABLED=0 go build -buildmode=pie -trimpath /go/src/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down

0 comments on commit fc9fdeb

Please sign in to comment.