Skip to content

Commit

Permalink
Speed up via caching and cross compiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jum committed May 11, 2024
1 parent 20b0de2 commit a556adb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM golang:1.22.1-alpine as build
FROM --platform=$BUILDPLATFORM golang:1.22.1-alpine as build

COPY *.go /go/src/github.com/nanoandrew4/ngcplogs/
COPY go.mod /go/src/github.com/nanoandrew4/ngcplogs/
COPY go.sum /go/src/github.com/nanoandrew4/ngcplogs/

RUN cd /go/src/github.com/nanoandrew4/ngcplogs && go get && go build --ldflags '-extldflags "-static"' -o /usr/bin/ngcplogs
WORKDIR /goapp
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go mod download
COPY *.go ./
ARG TARGETOS TARGETARCH
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o ngcplogs .

FROM alpine:3.19.1
COPY --from=build /usr/bin/ngcplogs usr/bin
COPY --from=build /goapp/ngcplogs usr/bin

WORKDIR /usr/bin
ENTRYPOINT [ "/usr/bin/ngcplogs" ]
ENTRYPOINT [ "/usr/bin/ngcplogs" ]

0 comments on commit a556adb

Please sign in to comment.