-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
134 lines (116 loc) · 4.43 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
export IMAGE_NAME?=insightful/alpine-python
export VCS_REF=`git rev-parse --short HEAD`
export VCS_URL=https://github.com/insightfulsystems/alpine-python
export BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
export TAG_DATE=`date -u +"%Y%m%d"`
export ALPINE_VERSION=3.13
export BASE_IMAGE=alpine
export BUILD_IMAGE=local/alpine-base
export TARGET_ARCHITECTURES=amd64 arm32v6 arm32v7
export PYTHON_VERSIONS=2.7 3.8
export QEMU_VERSION=5.2.0-2
export QEMU_ARCHITECTURES=arm aarch64
export SHELL=/bin/bash
# Make sure make ignores the folders (I like short target names, but these collide with the folder structure)
.PHONY: 2.7 3.8 qemu wrap push manifest clean
qemu:
-docker run --rm --privileged multiarch/qemu-user-static:register --reset
-mkdir tmp
$(foreach ARCH, $(QEMU_ARCHITECTURES), make fetch-qemu-$(ARCH);)
@echo "==> Done setting up QEMU"
fetch-qemu-%:
$(eval ARCH := $*)
@echo "--> Fetching QEMU binary for $(ARCH)"
cd tmp && \
curl -L -o qemu-$(ARCH)-static.tar.gz \
https://github.com/multiarch/qemu-user-static/releases/download/v$(QEMU_VERSION)/qemu-$(ARCH)-static.tar.gz && \
tar xzf qemu-$(ARCH)-static.tar.gz && \
cp qemu-$(ARCH)-static ../qemu/
@echo "--> Done."
wrap:
@echo "==> Building local base containers"
$(foreach ARCH, $(TARGET_ARCHITECTURES), make wrap-$(ARCH);)
@echo "==> Done."
wrap-amd64:
docker pull amd64/$(BASE_IMAGE):$(ALPINE_VERSION)
docker tag amd64/$(BASE_IMAGE):$(ALPINE_VERSION) $(BUILD_IMAGE):amd64
wrap-translate-%:
@if [[ "$*" == "arm64v8" ]] ; then \
echo "aarch64"; \
else \
echo "arm"; \
fi
wrap-%:
$(eval ARCH := $*)
@echo "--> Building local base container for $(ARCH)"
docker build --build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg ARCH=$(shell make -s wrap-translate-$(ARCH)) \
--build-arg BASE=$(ARCH)/$(BASE_IMAGE):$(ALPINE_VERSION) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
-t $(BUILD_IMAGE):$(ARCH) qemu | sed -e 's/^/local $(ARCH): /;'
@echo "--> Done building local base container for $(ARCH)"
2.7:
$(foreach var, $(TARGET_ARCHITECTURES), make 2.7-$(var);)
2.7-%: # This assumes we have a folder for each major version
$(eval ARCH := $*)
docker build --build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg ARCH=$(ARCH) \
--build-arg BASE=$(BUILD_IMAGE):$(ARCH) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
-t $(IMAGE_NAME):2.7-$(ARCH) 2.7
docker build --build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg ARCH=$(ARCH) \
--build-arg BASE=$(IMAGE_NAME):2.7-$(ARCH) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
-t $(IMAGE_NAME):2.7-onbuild-$(ARCH) onbuild
echo "\n---\nDone building $(ARCH)\n---\n"
3.8:
$(foreach var, $(TARGET_ARCHITECTURES), make 3.8-$(var);)
3.8-%: # This assumes we have a folder for each major version
$(eval ARCH := $*)
docker build --build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg ARCH=$(ARCH) \
--build-arg BASE=$(BUILD_IMAGE):$(ARCH) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
-t $(IMAGE_NAME):3.8-$(ARCH) 3.8
docker build --build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg ARCH=$(ARCH) \
--build-arg BASE=$(IMAGE_NAME):3.8-$(ARCH) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
-t $(IMAGE_NAME):3.8-onbuild-$(ARCH) onbuild
echo "\n---\nDone building $(ARCH)\n---\n"
push:
docker push $(IMAGE_NAME)
expand-%: # expand architecture variants for manifest
@if [ "$*" == "amd64" ] ; then \
echo '--arch $*'; \
elif [[ "$*" == *"arm"* ]] ; then \
echo '--arch arm --variant $*' | cut -c 1-21,27-; \
fi
manifest:
docker manifest create --amend \
$(IMAGE_NAME):latest \
$(foreach arch, $(TARGET_ARCHITECTURES), $(IMAGE_NAME):3.8-$(arch))
$(foreach arch, $(TARGET_ARCHITECTURES), \
docker manifest annotate \
$(IMAGE_NAME):latest \
$(IMAGE_NAME):3.8-$(arch) $(shell make expand-$(arch));)
docker manifest push $(IMAGE_NAME):latest
docker manifest create --amend \
$(IMAGE_NAME):onbuild \
$(foreach arch, $(TARGET_ARCHITECTURES), $(IMAGE_NAME):3.8-onbuild-$(arch) )
$(foreach arch, $(TARGET_ARCHITECTURES), \
docker manifest annotate \
$(IMAGE_NAME):onbuild \
$(IMAGE_NAME):3.8-onbuild-$(arch) $(shell make expand-$(arch));)
docker manifest push $(IMAGE_NAME):onbuild
clean:
-docker rm -fv $$(docker ps -a -q -f status=exited)
-docker rmi -f $$(docker images -q -f dangling=true)
-docker rmi -f $(BUILD_IMAGE)
-docker rmi -f $$(docker images --format '{{.Repository}}:{{.Tag}}' | grep $(IMAGE_NAME))