-
Notifications
You must be signed in to change notification settings - Fork 525
/
docker.mk
108 lines (91 loc) · 3.78 KB
/
docker.mk
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
# Copyright 2021 The Dapr Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Common make targets for samples' Docker images.
SAMPLE_REGISTRY ?= docker.io/dapriosamples
TARGET_OS ?= linux
TARGET_ARCH ?= amd64
REL_VERSION ?= latest
ifeq ($(REL_VERSION),edge)
REL_VERSION := latest
endif
# Docker image build and push setting
DOCKER:=docker
DOCKERFILE:=Dockerfile
DOCKERMUTI_ARCH=linux-amd64 linux-arm linux-arm64
ifeq ($(TARGET_ARCH),arm)
DOCKER_IMAGE_PLATFORM:=$(TARGET_OS)/arm/v7
else ifeq ($(TARGET_ARCH),arm64)
DOCKER_IMAGE_PLATFORM:=$(TARGET_OS)/arm64/v8
else
DOCKER_IMAGE_PLATFORM:=$(TARGET_OS)/amd64
endif
.PHONY: build
BUILD_APPS:=$(foreach ITEM,$(APPS),build-$(ITEM))
build: $(BUILD_APPS)
# Generate docker image build targets
define genDockerImageBuild
.PHONY: build-$(1)
build-$(1):
ifeq ($(TARGET_ARCH),amd64)
$(DOCKER) build --build-arg PKG_FILES=* --platform $(DOCKER_IMAGE_PLATFORM) -f $(1)/$(DOCKERFILE) $(1)/. -t $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(REL_VERSION)-$(TARGET_OS)-$(TARGET_ARCH)
else
-$(DOCKER) buildx create --use --name daprsamplesbuild
-$(DOCKER) run --rm --privileged multiarch/qemu-user-static --reset -p yes
$(DOCKER) buildx build --build-arg PKG_FILES=* --platform $(DOCKER_IMAGE_PLATFORM) -f $(1)/$(DOCKERFILE) $(1)/. -t $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(REL_VERSION)-$(TARGET_OS)-$(TARGET_ARCH)
endif
endef
# Generate docker image build targets
$(foreach ITEM,$(APPS),$(eval $(call genDockerImageBuild,$(ITEM))))
# push docker image to the registry
.PHONY: push
PUSH_APPS:=$(foreach ITEM,$(APPS),push-$(ITEM))
push: $(PUSH_APPS)
# Generate docker image push targets
define genDockerImagePush
.PHONY: push-$(1)
push-$(1):
ifeq ($(TARGET_ARCH),amd64)
$(DOCKER) push $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(REL_VERSION)-$(TARGET_OS)-$(TARGET_ARCH)
else
-$(DOCKER) buildx create --use --name daprsamplesbuild
-$(DOCKER) run --rm --privileged multiarch/qemu-user-static --reset -p yes
$(DOCKER) buildx build --build-arg PKG_FILES=* --platform $(DOCKER_IMAGE_PLATFORM) -f $(1)/$(DOCKERFILE) $(1)/. -t $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(REL_VERSION)-$(TARGET_OS)-$(TARGET_ARCH) --push
endif
endef
# Generate docker image push targets
$(foreach ITEM,$(APPS),$(eval $(call genDockerImagePush,$(ITEM))))
# Create docker manifest
.PHONY: manifest-create
CREATE_MANIFEST_APPS:=$(foreach ITEM,$(APPS),manifest-create-$(ITEM))
manifest-create: $(CREATE_MANIFEST_APPS)
# Generate docker manifest create
define genDockerManifestCreate
.PHONY: manifest-create-$(1)
manifest-create-$(1):
$(DOCKER) manifest create $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(REL_VERSION) $(DOCKERMUTI_ARCH:%=$(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(REL_VERSION)-%)
endef
# Generate docker manifest create
$(foreach ITEM,$(APPS),$(eval $(call genDockerManifestCreate,$(ITEM))))
# Push docker manifest
.PHONY: manifest-push
PUSH_MANIFEST_APPS:=$(foreach ITEM,$(APPS),manifest-push-$(ITEM))
manifest-push: $(PUSH_MANIFEST_APPS)
# Generate docker manifest create
define genDockerManifestPush
.PHONY: manifest-push-$(1)
manifest-push-$(1):
$(DOCKER) manifest push $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(REL_VERSION)
endef
# Generate docker manifest create
$(foreach ITEM,$(APPS),$(eval $(call genDockerManifestPush,$(ITEM))))