-
Notifications
You must be signed in to change notification settings - Fork 533
/
Makefile.common.mk
88 lines (73 loc) · 2.74 KB
/
Makefile.common.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
ifeq ($(__inc_Makefile_common_mk),)
__inc_Makefile_common_mk:=1
ifeq ($(ModName),)
$(error ModName must be set, e.g. yunion.io/x/onecloud)
endif
ModBaseName:=$(notdir $(ModName))
DockerImageRegistry?=registry.cn-beijing.aliyuncs.com
DockerImageAlpineBuild?=$(DockerImageRegistry)/yunionio/alpine-build:3.19.0-go-1.21.10-0
DockerImageCentOSBuild?=$(DockerImageRegistry)/yunionio/centos-build:go-1.21.10-0
EnvIf=$(if $($(1)),$(1)=$($(1)))
define dockerCentOSBuildCmd
set -o xtrace
set -o errexit
set -o pipefail
git config --global --add safe.directory /root/go/src/yunion.io/x/$(ModBaseName)
cd /root/go/src/yunion.io/x/$(ModBaseName)
env \
$(call EnvIf,GOARCH) \
$(call EnvIf,GOOS) \
$(call EnvIf,CGO_ENABLED) \
make $(1)
chown -R $(shell id -u):$(shell id -g) _output
endef
tmpName=$(ModBaseName)-$(shell date +"%Y%m%d.%H%M%S%3N")
docker-centos-build: export dockerCentOSBuildCmd:=$(call dockerCentOSBuildCmd,$(F))
docker-centos-build:
docker rm --force docker-centos-build-$(tmpName) &>/dev/null || true
docker run \
--rm \
--name docker-centos-build-$(tmpName) \
-v $(CURDIR):/root/go/src/yunion.io/x/$(ModBaseName) \
-v $(CURDIR)/_output/centos-build:/root/go/src/yunion.io/x/$(ModBaseName)/_output \
-v $(CURDIR)/_output/centos-build/_cache:/root/.cache \
$(DockerImageCentOSBuild) \
/bin/bash -c "$$dockerCentOSBuildCmd"
ls -lh _output/centos-build/bin
# NOTE we need a way to stop and remove the container started by docker-build.
# No --tty, --stop-signal won't work
docker-centos-build-stop:
docker stop --time 0 docker-centos-build-$(tmpName) || true
.PHONY: docker-centos-build
.PHONY: docker-centos-build-stop
define dockerAlpineBuildCmd
set -o xtrace
set -o errexit
set -o pipefail
git config --global --add safe.directory /root/go/src/yunion.io/x/$(ModBaseName)
cd /root/go/src/yunion.io/x/$(ModBaseName)
git config --global --add safe.directory /root/go/src/yunion.io/x/onecloud
env \
$(call EnvIf,GOARCH) \
$(call EnvIf,GOOS) \
$(call EnvIf,CGO_ENABLED) \
make $(1)
chown -R $(shell id -u):$(shell id -g) _output
endef
docker-alpine-build: export dockerAlpineBuildCmd:=$(call dockerAlpineBuildCmd,$(F))
docker-alpine-build:
docker rm --force docker-alpine-build-$(tmpName) &>/dev/null || true
docker run \
--rm \
--name docker-alpine-build-$(tmpName) \
-v $(CURDIR):/root/go/src/yunion.io/x/$(ModBaseName) \
-v $(CURDIR)/_output/alpine-build:/root/go/src/yunion.io/x/$(ModBaseName)/_output \
-v $(CURDIR)/_output/alpine-build/_cache:/root/.cache \
$(DockerImageAlpineBuild) \
/bin/sh -c "$$dockerAlpineBuildCmd"
ls -lh _output/alpine-build/bin
docker-alpine-build-stop:
docker stop --time 0 docker-alpine-build-$(tmpName) || true
.PHONY: docker-alpine-build
.PHONY: docker-alpine-build-stop
endif # __inc_Makefile_common_mk