# --------------------------------------------------- # --- 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 "^" | 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) . | 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) . | 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)