Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiarch #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#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 .
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
Expand Down
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)"