diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4a5020b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +Dockerfile* +.git/** +dist/** +.goreleaser.yml +.github/** +docs/** +README* diff --git a/.goreleaser.yml b/.goreleaser.yml index f4ab517..dcf38aa 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -43,6 +43,7 @@ snapshot: dockers: - image_templates: - "itzg/{{ .ProjectName }}:{{ .Version }}-amd64" + dockerfile: Dockerfile.release goarch: amd64 build_flag_templates: - --platform @@ -53,6 +54,7 @@ dockers: - image_templates: - "itzg/{{ .ProjectName }}:{{ .Version }}-arm64" + dockerfile: Dockerfile.release goarch: arm64 build_flag_templates: - --platform @@ -62,6 +64,7 @@ dockers: - --label=org.opencontainers.image.revision={{ .FullCommit }} - image_templates: - "itzg/{{ .ProjectName }}:{{ .Version }}-arm32v6" + dockerfile: Dockerfile.release goarch: arm goarm: "6" build_flag_templates: diff --git a/Dockerfile b/Dockerfile index daccec0..2a14775 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,13 @@ +FROM golang:1.17 as builder + +WORKDIR /build + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN CGO_ENABLED=0 go build ./cmd/mc-router + FROM scratch - -LABEL org.opencontainers.image.authors="Geoff Bourne " -LABEL org.opencontainers.image.title="mc-router" -LABEL org.opencontainers.image.source="https://github.com/itzg/mc-router" - -COPY mc-router / ENTRYPOINT ["/mc-router"] +COPY --from=builder /build/mc-router /mc-router diff --git a/Dockerfile.release b/Dockerfile.release new file mode 100644 index 0000000..daccec0 --- /dev/null +++ b/Dockerfile.release @@ -0,0 +1,8 @@ +FROM scratch + +LABEL org.opencontainers.image.authors="Geoff Bourne " +LABEL org.opencontainers.image.title="mc-router" +LABEL org.opencontainers.image.source="https://github.com/itzg/mc-router" + +COPY mc-router / +ENTRYPOINT ["/mc-router"] diff --git a/README.md b/README.md index c997dc9..58acc1d 100644 --- a/README.md +++ b/README.md @@ -165,11 +165,7 @@ kubectl apply -f https://raw.githubusercontent.com/itzg/mc-router/master/docs/k8 ## Building locally with Docker ```bash -docker run -it --rm \ - -v gopkg:/go/pkg \ - -v ${PWD}:/build -w /build \ - golang:1.17.3 \ - go build ./cmd/mc-router +docker build -t mc-router . ``` ## Skaffold