Add Dockerfile for multi-arch build

master
Robert Jacob 9 months ago
parent 6b0af81d3c
commit cf11d582b4
  1. 1
      .dockerignore
  2. 1
      .gitignore
  3. 29
      Dockerfile
  4. 38
      Makefile

@ -0,0 +1 @@
.gitignore

1
.gitignore vendored

@ -1,3 +1,4 @@
leakybot
config.yaml
state.yaml
image.tar

@ -0,0 +1,29 @@
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.17 AS builder
ARG TARGETOS
ARG TARGETARCH
ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH
WORKDIR /build
COPY go.mod go.sum /build/
RUN go mod download
RUN go mod verify
COPY . /build/
RUN make
FROM --platform=$TARGETPLATFORM docker.io/library/busybox
RUN mkdir -p /data /etc/leakybot/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /build/leakybot /bin/leakybot
USER nobody
VOLUME /data
ENTRYPOINT ["/bin/leakybot"]
CMD ["--config-file", "/etc/leakybot/config.yaml"]

@ -0,0 +1,38 @@
SHELL := /bin/bash
GO ?= go
GO_CMD := CGO_ENABLED=0 $(GO)
GIT_VERSION := $(shell git describe --tags --dirty)
VERSION := $(GIT_VERSION:v%=%)
GIT_COMMIT := $(shell git rev-parse HEAD)
DOCKER_REPO := hacknology.de/projekte/leakybot
DOCKER_TAG := $(shell git rev-parse --short HEAD)
DOCKER_TARGETPLATFORM := linux/arm64
BINARY_NAME := leakybot
.PHONY: all
all: test build-binary
.PHONY: test
test:
$(GO_CMD) test -cover ./...
.PHONY: build-binary
build-binary:
$(GO_CMD) build -tags netgo -ldflags "-w -X main.Version=$(VERSION) -X main.GitCommit=$(GIT_COMMIT)" -o ${BINARY_NAME} .
.PHONY: image
image:
docker buildx build -t "$(DOCKER_REPO):$(DOCKER_TAG)" --load .
.PHONY: image.tar
image.tar:
docker buildx build -t "$(DOCKER_REPO):$(DOCKER_TAG)" --platform $(DOCKER_TARGETPLATFORM) --output=type=docker,dest=image.tar .
.PHONY: all-images
all-images:
docker buildx build -t "$(DOCKER_REPO):$(DOCKER_TAG)" --platform linux/amd64,linux/arm64 --push .
.PHONY: clean
clean:
rm -rf leakybot image.tar
Loading…
Cancel
Save