-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
53 lines (45 loc) · 2.05 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Multi architecture builds
TARGETS = amd64 arm64
PLATFORM = linux
BUILD_TARGETS = $(TARGETS:=.build)
BUILD_CI_TARGETS = $(TARGETS:=.docker)
IMAGE_PUSH_TARGETS = $(TARGETS:=.push-image)
MANIFEST_CREATE_TARGETS = $(PLATFORM:=.create-manifest)
MANIFEST_PUSH_TARGETS = $(PLATFORM:=.push-manifest)
BUILD_OPT=""
IMAGE_TAG=0.1
IMAGE_PREFIX=k8s-fuse-plugin
IMAGE_REGISTRY=quay.io/nextflow
BINARY=k8s-fuse-plugin
.DEFAULT_GOAL := build
# Build binary and docker and then push to docker hub
.PHONY: all
all: build docker push-image create-manifest push-manifest
# Build go binaries
PHONY: build $(BUILD_TARGETS)
build: $(BUILD_TARGETS)
%.build:
TARGET=$(*) GOOS=linux GOARCH=$(*) CGO_ENABLED=0 go build -o $(BINARY)-${PLATFORM}-$(*)
# Build docker image
PHONY: docker $(BUILD_CI_TARGETS)
docker: $(BUILD_CI_TARGETS)
%.docker:
TARGET=$(*) docker build . --platform ${PLATFORM}/$(*) -t $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):build-$(*)-${IMAGE_TAG} --build-arg build_arch=${PLATFORM}-${*}
#Docker image push
PHONY: push-image $(IMAGE_PUSH_TARGETS)
push-image: $(IMAGE_PUSH_TARGETS)
%.push-image:
TARGET=$(*) docker push $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):build-$(*)-${IMAGE_TAG}
# Create docker manifest for amd64 and arm64
PHONY: create-manifest $(MANIFEST_CREATE_TARGETS)
create-manifest: $(MANIFEST_CREATE_TARGETS)
%.create-manifest:
docker manifest create $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):${IMAGE_TAG} -a $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):build-amd64-${IMAGE_TAG} -a $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):build-arm64-${IMAGE_TAG}
docker manifest annotate --arch amd64 $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):${IMAGE_TAG} $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):build-amd64-${IMAGE_TAG}
docker manifest annotate --arch arm64 $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):${IMAGE_TAG} $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):build-arm64-${IMAGE_TAG}
# docker push manifest and inspect
PHONY: push-manifest $(MANIFEST_PUSH_TARGETS)
push-manifest: $(MANIFEST_PUSH_TARGETS)
%.push-manifest:
docker manifest push $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):${IMAGE_TAG}
docker manifest inspect $(IMAGE_REGISTRY)/$(IMAGE_PREFIX):${IMAGE_TAG}