diff --git a/Dockerfile b/Dockerfile index c8ca4d4..a6ca6fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,12 @@ -#FROM registry.access.redhat.com/ubi8/ubi-minimal -FROM golang:1.17.8-alpine AS build-env +FROM --platform=$BUILDPLATFORM golang:1.17.8-alpine AS build-env + +ARG TARGETOS +ARG TARGETARCH + +ENV GOOS=${TARGETOS} \ + GOARCH=${TARGETARCH} \ + GOARM=${TARGETVARIANT} + RUN mkdir /build WORKDIR /build COPY *.go . @@ -7,15 +14,7 @@ COPY go.mod . COPY go.sum . RUN go mod download RUN go mod tidy -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -a -installsuffix cgo -o app -#RUN go build -o /app -# dev -#WORKDIR /go/src/github.com/weshayutin/todolist-mariadb-go -# -#COPY ./ . -# -#RUN chmod -R 777 ./ -#RUN go mod download +RUN CGO_ENABLED=0 go build -v -a -installsuffix cgo -o app FROM scratch COPY --from=build-env /build/app /app diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ffefe8b --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +REGISTRY ?= quay.io/mferrato +REPO ?= todolist-mariadb-go +IMAGE ?= $(REGISTRY)/$(REPO) + +DOCKERFILE ?= Dockerfile + +VERSION ?= v1 + +TAG_LATEST ?= false + +ifeq ($(TAG_LATEST), true) + IMAGE_TAGS ?= $(IMAGE):$(VERSION) $(IMAGE):latest +else + IMAGE_TAGS ?= $(IMAGE):$(VERSION) +endif + +ifeq ($(shell docker buildx inspect 2>/dev/null | awk '/Status/ { print $$2 }'), running) + BUILDX_ENABLED ?= true +else + BUILDX_ENABLED ?= false +endif + +define BUILDX_ERROR +buildx not enabled, refusing to run this recipe +endef + +PLATFORMS ?= linux-amd64,linux-arm64,linux-ppc64le,linux-s390x +BUILDX_PLATFORMS := $(shell echo '$(PLATFORMS)' | sed -e "s/-/\//g" ) +BUILDX_OUTPUT_TYPE ?= registry + +containers: +ifneq ($(BUILDX_ENABLED), true) + $(error $(BUILDX_ERROR)) +endif + @echo "Buildx plaforms: $(BUILDX_PLATFORMS)" + @docker buildx build \ + --output=type=$(BUILDX_OUTPUT_TYPE) \ + --platform $(BUILDX_PLATFORMS) \ + $(addprefix -t , $(IMAGE_TAGS)) \ + -f $(DOCKERFILE) . + @echo "manifest: $(IMAGE_TAGS)"