blob: 058263f12bf17f63a826a2e4346df6afdd265df9 (
plain)
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
|
# ---------------------------------------------------
# --- base variables
# ---------------------------------------------------
REGISTRY=docker.automotivelinux.org
REPO=agl
NAME=worker
VERSION=$(shell tail -1 VERSION)
FLAVOUR=generic
# ---------------------------------------------------
# --- computed - don't touch !
# ---------------------------------------------------
IMAGE_NAME=$(REGISTRY)/$(REPO)/$(NAME)-$(FLAVOUR):$(VERSION)
IMAGE_LATEST=$(REGISTRY)/$(REPO)/$(NAME)-$(FLAVOUR):latest
CNAME=vm-$(NAME)-$(FLAVOUR)
help:
@echo "Available targets:"
@echo "- clean: drop existing container and image"
@echo "- distclean: drop temp images (the one produced by a bad Dockerfile...)"
@echo "- build: create new image"
@echo "- build-debug: create new image (debug mode = break and wait at first error)"
@echo "- test: start a new test container and enter in it. After exit, the container is destoyed"
@echo "- push: push the image to registry $(REGISTRY)"
@echo "- push-latest: push the image to registry $(REGISTRY) and also tag as 'latest'"
@echo "- export: export the image to a compressed archive"
@echo "- export-latest: export the latest image to a compressed archive"
@echo "- show-image: dumps the current image name"
@echo ""
@echo "Variables:"
@echo "- Docker registry: REGISTRY=$(REGISTRY)"
@echo "- Image repository: REPO=$(REPO)"
@echo "- Image name: NAME=$(NAME)"
@echo "- Flavour: FLAVOUR=$(FLAVOUR)"
@echo "- Image version: VERSION=$(VERSION)"
@echo "- Container name/host name: CNAME=$(CNAME)"
@echo
@echo "Containers:"
@docker ps -a
@echo
@echo "Images:"
@docker images
@echo
@echo "Available flavours:"
@echo "- generic (default) : can be used for most of the tasks (platform builds, sdk builds, ...)"
@echo "- xds : dedicated to daemons and tools part of XDS (cross development system)"
.PHONY:clean
clean:
@docker inspect $(CNAME) &>/dev/null && { \
echo "Stopping and removing container $(CNAME)" ; \
docker stop $(CNAME) || true; \
docker rm $(CNAME); \
} || true
@docker inspect $(IMAGE_NAME) &>/dev/null && { \
echo "Removing image $(IMAGE_NAME)"; \
docker rmi $(IMAGE_NAME) ; \
} || true
@docker inspect $(IMAGE_LATEST) &>/dev/null && { \
echo "Removing image $(IMAGE_LATEST)"; \
docker rmi $(IMAGE_LATEST) ; \
} || true
@rm -f INSTALL/DEBUG
# remove spurious containers and images left by broken builds
.PHONY:distclean
distclean: clean
for imgid in $$(docker images | grep "^<none>" | awk '{print $$3}'); do \
echo "Remove image $$imgid"; \
docker rmi $$imgid; \
done
.PHONY:build-debug
build-debug: INSTALL/flavours/$(FLAVOUR).tasks
@echo "------------------- Building image $(NAME)-$(FLAVOUR) (debug mode) -------------------"
@touch INSTALL/DEBUG
@echo "FLAVOUR=$(FLAVOUR)" >INSTALL/flavour.conf
@docker build --no-cache=true --rm --pull -t $(IMAGE_NAME) . | awk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $$0 }' | tee build_$(FLAVOUR)_debug.log
@rm -f INSTALL/DEBUG INSTALL/flavour.conf
@docker images
# inside jenkins, we don't want the build script to break and wait for interaction
# after first error. So we remove the file inside INSTALL dir which indicates to the
# setup script to enable DEBUG.
.PHONY:build
build: INSTALL/flavours/$(FLAVOUR).tasks
@echo "------------------- Building image $(NAME)-$(FLAVOUR) -------------------"
@rm -f INSTALL/DEBUG
@echo "FLAVOUR=$(FLAVOUR)" >INSTALL/flavour.conf
@docker build --no-cache=true --rm --pull -t $(IMAGE_NAME) . | awk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $$0 }' | tee build_$(FLAVOUR).log
@rm -f INSTALL/flavour.conf
@docker images
.PHONY:test
test:
docker run \
--detach=true \
--hostname=$(CNAME) \
--name=$(CNAME) \
--privileged \
-it \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
$(IMAGE_NAME)
docker exec -it $(CNAME) /bin/bash || true
docker stop $(CNAME) || true
docker rm $(CNAME) || true
.PHONY:push
push:
docker push $(IMAGE_NAME)
.PHONY:push-latest
push-latest: push
docker tag $(IMAGE_NAME) $(IMAGE_LATEST)
docker push $(IMAGE_LATEST)
.PHONY:export
export:
@echo "Export image to docker_$(REPO)_$(NAME)-$(FLAVOUR)-$(VERSION).tar.xz"
docker save $(IMAGE_NAME) | xz -T0 -c >docker_$(REPO)_$(NAME)-$(FLAVOUR)-$(VERSION).tar.xz
.PHONY:export-latest
export-latest:
docker tag $(IMAGE_NAME) $(IMAGE_LATEST)
@echo "Export image to docker_$(REPO)_$(NAME)-$(FLAVOUR)-latest.tar.xz"
docker save $(IMAGE_LATEST) | xz -T0 -c >docker_$(REPO)_$(NAME)-$(FLAVOUR)-latest.tar.xz
.PHONY:show-image
show-image:
@echo $(IMAGE_NAME)
|