Skip to content

Commit

Permalink
chore: improved docker build ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
leonsteinhaeuser committed Aug 15, 2023
1 parent 9ce4763 commit f38b2b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
29 changes: 22 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
**
!controllers/
!api/
!pkg/
!go.mod
!go.sum
!main.go

# folders
_data/
.github/
bin/
config/
e2e/
hack/

# files
.envrc
.gitignore
.goreleaser.yaml
CODE_OF_CONDUCT.md
docker-compose.yaml
Dockerfile
Dockerfile.dev
LICENSE
Makefile
PROJECT.md
README.md
SECURITY.md
10 changes: 3 additions & 7 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@ WORKDIR /workspace
# Copy the go source
ADD . .

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager controller
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/controller"]
ENTRYPOINT ["/manager"]

0 comments on commit f38b2b4

Please sign in to comment.