-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
81 lines (69 loc) · 2.56 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
DOCKUSR = fred0cs
REPO = $(DOCKUSR)/
NAME = cpp-dm
ARCH = `uname -m`
TAG = 2021
ARCH := $$(arch=$$(uname -m); if [ "$$arch" = "x86_64" ]; then echo "amd64"; elif [ "$$arch" = "aarch64" ]; then echo "arm64"; else echo $$arch; fi)
ARCHS = amd64 arm64
IMAGES := $(ARCHS:%=$(REPO)$(NAME):$(TAG)-%)
PLATFORMS := $$(first="True"; for a in $(ARCHS); do if [[ $$first == "True" ]]; then printf "linux/%s" $$a; first="False"; else printf ",linux/%s" $$a; fi; done)
# Build image
build:
docker build --build-arg arch=$(ARCH) --tag $(REPO)$(NAME):$(TAG) .
# docker build --build-arg arch=$(ARCH) --tag $(REPO)$(NAME):$(TAG)-$(ARCH) .
@danglingimages=$$(docker images --filter "dangling=true" -q); \
if [[ $$danglingimages != "" ]]; then \
docker rmi $$(docker images --filter "dangling=true" -q); \
fi
# Safe way to build multiarchitecture images:
# - build each image on the matching hardware, with the -$(ARCH) tag
# - push the architecture specific images to Dockerhub
# - build a manifest list referencing those images
# - push the manifest list so that the multiarchitecture image exist
manifest:
docker manifest create $(REPO)$(NAME):$(TAG) $(IMAGES)
@for arch in $(ARCHS); \
do \
echo docker manifest annotate --os linux --arch $$arch $(REPO)$(NAME):$(TAG) $(REPO)$(NAME):$(TAG)-$$arch; \
docker manifest annotate --os linux --arch $$arch $(REPO)$(NAME):$(TAG) $(REPO)$(NAME):$(TAG)-$$arch; \
done
docker manifest push $(REPO)$(NAME):$(TAG)
login:
docker login --username $(DOCKUSR)
logout:
docker logout
rmmanifest:
docker manifest rm $(REPO)$(NAME):$(TAG)
push:
docker push $(REPO)$(NAME):$(TAG)
# docker push $(REPO)$(NAME):$(TAG)-$(ARCH)
save:
docker save $(REPO)$(NAME):$(TAG) | gzip > $(NAME)-$(TAG).tar.gz
# docker save $(REPO)$(NAME):$(TAG)-$(ARCH) | gzip > $(NAME)-$(TAG)-$(ARCH).tar.gz
# Clear caches
clean:
docker builder prune
clobber:
docker rmi $(REPO)$(NAME):$(TAG) $(REPO)$(NAME):$(TAG)-$(ARCH)
docker builder prune --all
run:
docker run --rm --detach \
--env USERNAME=`id -n -u` --env USERID=`id -u` \
--volume "${PWD}":/config/workspace:rw \
--publish 8443:8443 \
--name $(NAME) \
$(REPO)$(NAME):$(TAG)
# $(REPO)$(NAME):$(TAG)-$(ARCH)
sleep 5
open http://localhost:8443 || xdg-open http://localhost:8443 || echo "http://localhost:8443"
stop:
docker kill $(NAME)
debug:
docker run --rm --interactive --tty \
--env USERNAME=`id -n -u` --env USERID=`id -u` \
--volume "${PWD}":/config/workspace:rw \
--publish 8443:8443 \
--name $(NAME) \
--entrypoint "/bin/bash" \
$(REPO)$(NAME):$(TAG)
# $(REPO)$(NAME):$(TAG)-$(ARCH)