fix: slim container image... (#6)

* fix: slim container image...

- Add ignore all exept go files in .dockerignore
- Remove unnecessary spaces
* fix: alpine based image, install g++ in build ...
* For trimpath and ldflags s w

* fix: scratch base, static bin, utilize buildkit...

- Use scratch base image
- Use golang buster as build image
- Static bunary
- Utilize buildkit with gomod and build caching

Authored-by: pratikbin <pratikbin+010101@no-reply-github.com>
This commit is contained in:
pratikbin
2022-09-07 12:16:26 +05:30
committed by GitHub
parent 778108e17a
commit 4f8f0cadeb
4 changed files with 28 additions and 23 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
# Ignore everything
*
# But these files...
!**/go.**
!**.go

View File

@@ -1,13 +1,12 @@
FROM golang:alpine3.15 # syntax = docker/dockerfile:latest
FROM golang as build
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod tidy; \
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o lazytainer ./...
WORKDIR /root/ FROM scratch
COPY ./go.mod ./go.sum ./ COPY --from=build /app/lazytainer /usr/local/bin/lazytainer
RUN go mod download ENTRYPOINT ["/usr/local/bin/lazytainer"]
COPY ./lazytainer.go .
RUN go build lazytainer.go
FROM alpine:latest
WORKDIR /root/
COPY --from=0 /root/lazytainer ./
CMD ["./lazytainer"]