summaryrefslogtreecommitdiff
path: root/util/docker
diff options
context:
space:
mode:
authorMartin Roth <gaumless@gmail.com>2016-12-31 14:59:29 -0700
committerMartin Roth <martinroth@google.com>2017-04-04 01:49:59 +0200
commit85782b21527b54ae5ac496bf27c1416e4d6aae68 (patch)
treee5594b9d74ceebc9c09919c94025afe383268a02 /util/docker
parente0c53af470feae1d7d66dc4aa9d067402a468626 (diff)
util/docker: Update makefile for servers and local use
- Add some variables to allow server customizations. - Verify that coreboot images and containers exist before trying to remove them. - Add a couple of convenience targets: clean & cleanall to remove coreboot containers and images or ALL containers and images. - Add docker-what-jenkins-does target to run a test build locally inside a docker image. - Add docker-jenkins-server target to test the server configuration and run the jenkins docker image. - Add docker-jenkins-shell and docker-shell targets to run the coreboot-sdk and coreboot-jenkins-server images. - Update the help. Change-Id: I1896f33e7eddfe3248f44ae780de65ce50d5dd99 Signed-off-by: Martin Roth <gaumless@gmail.com> Reviewed-on: https://review.coreboot.org/18004 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/docker')
-rw-r--r--util/docker/Makefile112
1 files changed, 104 insertions, 8 deletions
diff --git a/util/docker/Makefile b/util/docker/Makefile
index 7df68514ae..ef43d37dda 100644
--- a/util/docker/Makefile
+++ b/util/docker/Makefile
@@ -16,6 +16,18 @@ export top=$(abspath $(CURDIR)/../..)
export crossgcc_version=$(shell $(top)/util/crossgcc/buildgcc --version | grep 'cross toolchain' | sed 's/^.*\sv//' | sed 's/\s.*$$//')
export DOCKER:=$(shell $(SHELL) -c "command -v docker")
+# Local port to forward to the jenkins image for the test server
+export COREBOOT_JENKINS_PORT?=49151
+
+# Local cache directory - for storing files shared with the docker image
+export COREBOOT_JENKINS_CACHE_DIR?=/srv/docker/coreboot-builder/cache
+
+# Local ccache directory
+export COREBOOT_JENKINS_CCACHE_DIR?=/srv/docker/coreboot-builder/ccache
+
+# Name of the jenkins container
+export COREBOOT_JENKINS_CONTAINER?=coreboot_jenkins
+
# Version of the jenkins / sdk container
export COREBOOT_CONTAINER_VERSION?=$(crossgcc_version)
@@ -58,10 +70,26 @@ docker-killall: test-docker
fi
clean-coreboot-containers: docker-killall
- $(DOCKER) rm $(docker ps -a | grep 'coreboot' | sed 's|\s.*$||')
+ @if [ -n "$$($(DOCKER) ps -a | grep 'coreboot')" ]; then \
+ $(DOCKER) rm $$($(DOCKER) ps -a | grep 'coreboot' | sed 's|\s.*$$||'); \
+ fi
clean-coreboot-images: docker-killall
- $(DOCKER) rmi $(docker images | grep coreboot | sed 's|^\S\+\s\+\S\+\s\+||' | sed 's|\s.*$||')
+ @if [ -n "$$($(DOCKER) images | grep 'coreboot')" ]; then \
+ $(DOCKER) rmi $$($(DOCKER) images | grep coreboot | sed 's|^\S\+\s\+\S\+\s\+||' | sed 's|\s.*$$||'); \
+ fi
+
+docker-clean: clean-coreboot-containers
+ @$(MAKE) clean-coreboot-images
+
+docker-cleanall:
+ @if [ -n "$$($(DOCKER) ps -a | grep -v "CONTAINER")" ]; then \
+ $(DOCKER) kill $$($(DOCKER) ps -a | grep -v "CONTAINER" | sed 's|\s.*$$||'); \
+ $(DOCKER) rm $$($(DOCKER) ps -a | grep -v "CONTAINER" | sed 's|\s.*$$||'); \
+ fi
+ @if [ -n "$$($(DOCKER) images | grep -v "REPOSITORY")" ]; then \
+ $(DOCKER) rmi $$($(DOCKER) images | grep -v "REPOSITORY" | tr -s ' ' | cut -f3 -d ' '); \
+ fi
docker-build-coreboot: test-docker
$(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \
@@ -83,26 +111,94 @@ docker-abuild: test-docker
@echo "Exiting now will leave built files owned by root"
sudo chown -R $$(whoami):$$(id -gn $$(whoami)) $(top)
+docker-what-jenkins-does: test-docker
+ $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \
+ --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
+ /bin/bash -c "cd /home/coreboot/coreboot && \
+ make clean && make what-jenkins-does CPUS=$(CPUS)"
+
+docker-jenkins-server: test-docker
+ @if [ ! -d "$(COREBOOT_JENKINS_CACHE_DIR)" ]; then \
+ printf "\nError: %s does not exist.\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
+ printf "Please run:\nsudo mkdir -p %s\n\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
+ false; \
+ fi
+ @if ! touch "$(COREBOOT_JENKINS_CACHE_DIR)/testfile" 2>/dev/null; then \
+ printf "\nError: Cannot create file in %s." "$(COREBOOT_JENKINS_CACHE_DIR)"; \
+ printf "Please run:\nsudo chown -R $(whoami):$(whoami) %s\n\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
+ else \
+ rm -f "$(COREBOOT_JENKINS_CACHE_DIR)/testfile"; \
+ fi
+ @if [ ! -d "$(COREBOOT_JENKINS_CCACHE_DIR)" ]; then \
+ printf "\nError: %s does not exist.\n" "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
+ printf "Please run:\nsudo mkdir -p %s\n\n" "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
+ false; \
+ fi
+ @if ! touch "$(COREBOOT_JENKINS_CCACHE_DIR)/testfile" 2>/dev/null; then \
+ printf "\nError: Cannot create file in %s." "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
+ printf 'Please run:\nsudo chown -R $$(whoami):$$(whoami) %s\n\n' "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
+ else \
+ rm -f "$(COREBOOT_JENKINS_CCACHE_DIR)/testfile"; \
+ fi
+ $(DOCKER) run -d --privileged --restart=always \
+ -p $(COREBOOT_JENKINS_PORT):49151 \
+ -v $(COREBOOT_JENKINS_CACHE_DIR):/data/cache \
+ -v $(COREBOOT_JENKINS_CCACHE_DIR):/home/coreboot/.ccache \
+ --name=$(COREBOOT_JENKINS_CONTAINER) \
+ coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION)
+
+docker-jenkins-shell: test-docker
+ @if [ ! -d $(COREBOOT_JENKINS_CACHE_DIR) ]; then printf "\nError: %s does not exist.\nPlease run:\nsudo mkdir -p %s\n\n" "$(COREBOOT_JENKINS_CACHE_DIR)" "$(COREBOOT_JENKINS_CACHE_DIR)"; false; fi
+ @if [ ! -d $(COREBOOT_JENKINS_CCACHE_DIR) ]; then printf "\nError: %s does not exist.\nPlease run:\nsudo mkdir -p %s\n\n" "$(COREBOOT_JENKINS_CCACHE_DIR)" "$(COREBOOT_JENKINS_CCACHE_DIR)"; false; fi
+ $(DOCKER) run -u root -it --privileged \
+ --entrypoint="/bin/bash" \
+ -p $(COREBOOT_JENKINS_PORT):49151 \
+ -v $(top):/home/coreboot/coreboot \
+ -v $(COREBOOT_JENKINS_CACHE_DIR):/data/cache \
+ -v $(COREBOOT_JENKINS_CCACHE_DIR):/home/coreboot/.ccache \
+ --name=$(COREBOOT_JENKINS_CONTAINER) \
+ --rm coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION)
+
+docker-shell: USER=coreboot
+docker-shell: test-docker
+ $(DOCKER) run -u $(USER) -it \
+ -w /home/coreboot/coreboot \
+ -v $(top):/home/coreboot/coreboot \
+ --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
+ /bin/bash -l
+
help:
@echo "Commands for working with docker images:"
@echo " coreboot-sdk - Build coreboot-sdk container"
@echo " upload-coreboot-sdk - Upload coreboot-sdk to hub.docker.com"
@echo " coreboot-jenkins-node - Build coreboot-jenkins-node container"
@echo " upload-coreboot-jenkins-node - Upload coreboot-jenkins-node to hub.docker.com"
- @echo " clean-coreboot-containers - remove all docker coreboot containers"
- @echo " clean-coreboot-images - remove all docker coreboot images"
+ @echo " clean-coreboot-containers - Remove all docker coreboot containers"
+ @echo " clean-coreboot-images - Remove all docker coreboot images"
+ @echo " clean-docker - Remove docker coreboot containers & images"
@echo
@echo "Commands for using docker images"
- @echo " docker-build-coreboot <BUILD_CMD=target> - Build coreboot under coreboot-sdk"
- @echo " docker-abuild <ABUILD_ARGS='-a -B'> - Run abuild under coreboot-sdk"
+ @echo " docker-build-coreboot - Build coreboot under coreboot-sdk"
+ @echo " <BUILD_CMD=target> "
+ @echo " docker-abuild - Run abuild under coreboot-sdk"
+ @echo " <ABUILD_ARGS='-a -B'>"
+ @echo " docker-what-jenkins-does - Run 'what-jenkins-does' target"
+ @echo " docker-shell - Bash prompt in coreboot-jenkins-node"
+ @echo " <USER=root or USER=coreboot>"
+ @echo " docker-jenkins-server - Run coreboot-jenkins-node image (for server)"
@echo
@echo "Variables:"
- @echo " COREBOOT_CONTAINER_VERSION = $(COREBOOT_CONTAINER_VERSION)"
- @echo " DOCKER_COMMIT = $(DOCKER_COMMIT)"
+ @echo " COREBOOT_JENKINS_PORT=$(COREBOOT_JENKINS_PORT)"
+ @echo " COREBOOT_JENKINS_CACHE_DIR=$(COREBOOT_JENKINS_CACHE_DIR)"
+ @echo " COREBOOT_JENKINS_CCACHE_DIR=$(COREBOOT_JENKINS_CCACHE_DIR)"
+ @echo " COREBOOT_JENKINS_CONTAINER=$(COREBOOT_JENKINS_CONTAINER)"
+ @echo " COREBOOT_CONTAINER_VERSION=$(COREBOOT_CONTAINER_VERSION)"
+ @echo " DOCKER_COMMIT=$(DOCKER_COMMIT)"
.PHONY: test-docker test-docker-login
.PHONY: coreboot-jenkins-node upload-coreboot-jenkins-node
.PHONY: coreboot-sdk upload-coreboot-sdk
.PHONY: clean-coreboot-containers clean-coreboot-images
.PHONY: docker-abuild
+.PHONY: docker-what-jenkins-does docker-shell docker-jenkins-server
.PHONY: help