Added a multi-stage Dockerfile for easier local image builds

This commit is contained in:
Geoff Bourne 2021-12-04 18:31:18 -06:00
parent 1b1f8e5f22
commit ca55bde751
No known key found for this signature in database
GPG Key ID: FA2F6C35D87E88ED
5 changed files with 30 additions and 11 deletions

7
.dockerignore Normal file
View File

@ -0,0 +1,7 @@
Dockerfile*
.git/**
dist/**
.goreleaser.yml
.github/**
docs/**
README*

View File

@ -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:

View File

@ -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 <itzgeoff@gmail.com>"
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

8
Dockerfile.release Normal file
View File

@ -0,0 +1,8 @@
FROM scratch
LABEL org.opencontainers.image.authors="Geoff Bourne <itzgeoff@gmail.com>"
LABEL org.opencontainers.image.title="mc-router"
LABEL org.opencontainers.image.source="https://github.com/itzg/mc-router"
COPY mc-router /
ENTRYPOINT ["/mc-router"]

View File

@ -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