Skip to content

Instantly share code, notes, and snippets.

@ravenjm
Created January 5, 2021 16:35
Show Gist options
  • Save ravenjm/8b44f4ce78fcf1f316c3261719700b25 to your computer and use it in GitHub Desktop.
Save ravenjm/8b44f4ce78fcf1f316c3261719700b25 to your computer and use it in GitHub Desktop.
# STEP 1 build executable binary
FROM golang:alpine as builder
COPY . $GOPATH/src/
WORKDIR $GOPATH/src/
#add git to builder image
RUN apk update && apk add git
#get dependancies
RUN go get -d -v
#build the binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/gocalc
# STEP 2 build a small image
# start from scratch
FROM scratch
# Copy our static executable
COPY --from=builder /go/bin/gocalc /go/bin/gocalc
ENTRYPOINT ["/go/bin/gocalc"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment