blob: f70ee8908ef5fb301247db7290a5a4d017a61eb0 [file] [log] [blame]
Martin Rothcbaab7e2016-08-31 21:26:17 -06001##
2## This file is part of the coreboot project.
3##
4## Copyright (C) 2016 Google, Inc.
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; version 2 of the License.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13## GNU General Public License for more details.
14##
15export top=$(abspath $(CURDIR)/../..)
16export crossgcc_version=$(shell $(top)/util/crossgcc/buildgcc --version | grep 'cross toolchain' | sed 's/^.*\sv//' | sed 's/\s.*$$//')
Martin Roth561f3682016-12-30 17:00:19 -070017export DOCKER:=$(shell $(SHELL) -c "command -v docker")
18
Martin Roth85782b22016-12-31 14:59:29 -070019# Local port to forward to the jenkins image for the test server
20export COREBOOT_JENKINS_PORT?=49151
21
22# Local cache directory - for storing files shared with the docker image
23export COREBOOT_JENKINS_CACHE_DIR?=/srv/docker/coreboot-builder/cache
24
25# Local ccache directory
26export COREBOOT_JENKINS_CCACHE_DIR?=/srv/docker/coreboot-builder/ccache
27
28# Name of the jenkins container
29export COREBOOT_JENKINS_CONTAINER?=coreboot_jenkins
30
Martin Roth561f3682016-12-30 17:00:19 -070031# Version of the jenkins / sdk container
32export COREBOOT_CONTAINER_VERSION?=$(crossgcc_version)
33
34# Commit id to build from
35export DOCKER_COMMIT?=$(shell git log -n 1 --pretty=%h)
Martin Rothcbaab7e2016-08-31 21:26:17 -060036
Piotr Król64f87f32017-10-20 12:17:34 +020037# SDK architecture
38export COREBOOT_CROSSGCC_PARAM?=all_without_gdb
39
Martin Roth9ee70ce2016-12-30 16:26:13 -070040test-docker:
Martin Rothcbaab7e2016-08-31 21:26:17 -060041 $(if $(DOCKER),,\
42 $(warning Docker command not found. Please install docker) \
43 $(warning https://docs.docker.com/engine/installation ) \
44 $(error halting))
45
Martin Roth9ee70ce2016-12-30 16:26:13 -070046test-docker-login: test-docker
Martin Rothcbaab7e2016-08-31 21:26:17 -060047 $(if $(shell if [ ! -f ~/.docker/config.json ]; then \
48 echo "docker authentication file not found"; fi), \
49 $(error Docker authentication file not found. Run 'docker login'))
50
Martin Roth9ee70ce2016-12-30 16:26:13 -070051coreboot-sdk: test-docker
Martin Roth561f3682016-12-30 17:00:19 -070052 @echo "Building coreboot SDK $(crossgcc_version) from commit $(DOCKER_COMMIT)"
53 cat coreboot-sdk/Dockerfile | \
54 sed "s/{{DOCKER_COMMIT}}/$(DOCKER_COMMIT)/" | \
55 sed "s/{{SDK_VERSION}}/$(COREBOOT_CONTAINER_VERSION)/" | \
Piotr Król64f87f32017-10-20 12:17:34 +020056 sed "s/{{CROSSGCC_PARAM}}/$(COREBOOT_CROSSGCC_PARAM)/" | \
Martin Roth561f3682016-12-30 17:00:19 -070057 $(DOCKER) build -t coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) -
Martin Rothcbaab7e2016-08-31 21:26:17 -060058
Martin Roth9ee70ce2016-12-30 16:26:13 -070059upload-coreboot-sdk: test-docker-login
Martin Roth561f3682016-12-30 17:00:19 -070060 $(DOCKER) push coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION)
Martin Rothcbaab7e2016-08-31 21:26:17 -060061
Martin Roth9ee70ce2016-12-30 16:26:13 -070062coreboot-jenkins-node: test-docker
Martin Roth561f3682016-12-30 17:00:19 -070063 cat coreboot-jenkins-node/Dockerfile | \
64 sed "s/{{SDK_VERSION}}/$(COREBOOT_CONTAINER_VERSION)/" | \
65 sed "s|{{SSH_KEY}}|$$(cat coreboot-jenkins-node/authorized_keys)|" | \
66 $(DOCKER) build -t coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION) -
Martin Rothcbaab7e2016-08-31 21:26:17 -060067
Martin Roth9ee70ce2016-12-30 16:26:13 -070068upload-coreboot-jenkins-node: test-docker-login
Martin Roth561f3682016-12-30 17:00:19 -070069 $(DOCKER) push coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION)
Martin Rothcbaab7e2016-08-31 21:26:17 -060070
Martin Roth9ee70ce2016-12-30 16:26:13 -070071docker-killall: test-docker
Martin Rothaf25fd72016-12-30 16:12:30 -070072 @if [ -n "$$($(DOCKER) ps | grep 'coreboot')" ]; then \
73 $(DOCKER) kill $$($(DOCKER) ps | grep 'coreboot' | cut -f1 -d ' '); \
74 fi
75
Martin Roth9ee70ce2016-12-30 16:26:13 -070076clean-coreboot-containers: docker-killall
Martin Roth85782b22016-12-31 14:59:29 -070077 @if [ -n "$$($(DOCKER) ps -a | grep 'coreboot')" ]; then \
78 $(DOCKER) rm $$($(DOCKER) ps -a | grep 'coreboot' | sed 's|\s.*$$||'); \
79 fi
Martin Rothcbaab7e2016-08-31 21:26:17 -060080
Martin Roth9ee70ce2016-12-30 16:26:13 -070081clean-coreboot-images: docker-killall
Martin Roth85782b22016-12-31 14:59:29 -070082 @if [ -n "$$($(DOCKER) images | grep 'coreboot')" ]; then \
83 $(DOCKER) rmi $$($(DOCKER) images | grep coreboot | sed 's|^\S\+\s\+\S\+\s\+||' | sed 's|\s.*$$||'); \
84 fi
85
86docker-clean: clean-coreboot-containers
87 @$(MAKE) clean-coreboot-images
88
89docker-cleanall:
90 @if [ -n "$$($(DOCKER) ps -a | grep -v "CONTAINER")" ]; then \
91 $(DOCKER) kill $$($(DOCKER) ps -a | grep -v "CONTAINER" | sed 's|\s.*$$||'); \
92 $(DOCKER) rm $$($(DOCKER) ps -a | grep -v "CONTAINER" | sed 's|\s.*$$||'); \
93 fi
94 @if [ -n "$$($(DOCKER) images | grep -v "REPOSITORY")" ]; then \
95 $(DOCKER) rmi $$($(DOCKER) images | grep -v "REPOSITORY" | tr -s ' ' | cut -f3 -d ' '); \
96 fi
Martin Rothcbaab7e2016-08-31 21:26:17 -060097
Martin Roth9ee70ce2016-12-30 16:26:13 -070098docker-build-coreboot: test-docker
Martin Rothcbaab7e2016-08-31 21:26:17 -060099 $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \
Martin Roth561f3682016-12-30 17:00:19 -0700100 --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
Martin Rothcbaab7e2016-08-31 21:26:17 -0600101 /bin/bash -c "cd /home/coreboot/coreboot && \
102 make clean && \
103 make $(BUILD_CMD)"
104 @echo "Enter root password to chown files to $$(whoami):$$(id -gn $$(whoami))"
105 @echo "Exiting now will leave built files owned by root"
106 sudo chown -R $$(whoami):$$(id -gn $$(whoami)) $(top)
107
Martin Roth9ee70ce2016-12-30 16:26:13 -0700108docker-abuild: test-docker
Martin Rothcbaab7e2016-08-31 21:26:17 -0600109 $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \
Martin Roth561f3682016-12-30 17:00:19 -0700110 --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
Martin Rothcbaab7e2016-08-31 21:26:17 -0600111 /bin/bash -c "cd /home/coreboot/coreboot && \
112 make clean && \
113 util/abuild/abuild $(ABUILD_ARGS)"
114 @echo "Enter root password to chown files to $$(whoami):$$(id -gn $$(whoami))"
115 @echo "Exiting now will leave built files owned by root"
116 sudo chown -R $$(whoami):$$(id -gn $$(whoami)) $(top)
117
Martin Roth85782b22016-12-31 14:59:29 -0700118docker-what-jenkins-does: test-docker
119 $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \
120 --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
121 /bin/bash -c "cd /home/coreboot/coreboot && \
122 make clean && make what-jenkins-does CPUS=$(CPUS)"
123
124docker-jenkins-server: test-docker
125 @if [ ! -d "$(COREBOOT_JENKINS_CACHE_DIR)" ]; then \
126 printf "\nError: %s does not exist.\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
127 printf "Please run:\nsudo mkdir -p %s\n\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
128 false; \
129 fi
130 @if ! touch "$(COREBOOT_JENKINS_CACHE_DIR)/testfile" 2>/dev/null; then \
131 printf "\nError: Cannot create file in %s." "$(COREBOOT_JENKINS_CACHE_DIR)"; \
132 printf "Please run:\nsudo chown -R $(whoami):$(whoami) %s\n\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
133 else \
134 rm -f "$(COREBOOT_JENKINS_CACHE_DIR)/testfile"; \
135 fi
136 @if [ ! -d "$(COREBOOT_JENKINS_CCACHE_DIR)" ]; then \
137 printf "\nError: %s does not exist.\n" "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
138 printf "Please run:\nsudo mkdir -p %s\n\n" "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
139 false; \
140 fi
141 @if ! touch "$(COREBOOT_JENKINS_CCACHE_DIR)/testfile" 2>/dev/null; then \
142 printf "\nError: Cannot create file in %s." "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
143 printf 'Please run:\nsudo chown -R $$(whoami):$$(whoami) %s\n\n' "$(COREBOOT_JENKINS_CCACHE_DIR)"; \
144 else \
145 rm -f "$(COREBOOT_JENKINS_CCACHE_DIR)/testfile"; \
146 fi
147 $(DOCKER) run -d --privileged --restart=always \
148 -p $(COREBOOT_JENKINS_PORT):49151 \
149 -v $(COREBOOT_JENKINS_CACHE_DIR):/data/cache \
150 -v $(COREBOOT_JENKINS_CCACHE_DIR):/home/coreboot/.ccache \
151 --name=$(COREBOOT_JENKINS_CONTAINER) \
152 coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION)
153
154docker-jenkins-shell: test-docker
155 @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
156 @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
157 $(DOCKER) run -u root -it --privileged \
158 --entrypoint="/bin/bash" \
159 -p $(COREBOOT_JENKINS_PORT):49151 \
160 -v $(top):/home/coreboot/coreboot \
161 -v $(COREBOOT_JENKINS_CACHE_DIR):/data/cache \
162 -v $(COREBOOT_JENKINS_CCACHE_DIR):/home/coreboot/.ccache \
163 --name=$(COREBOOT_JENKINS_CONTAINER) \
164 --rm coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION)
165
166docker-shell: USER=coreboot
167docker-shell: test-docker
168 $(DOCKER) run -u $(USER) -it \
169 -w /home/coreboot/coreboot \
170 -v $(top):/home/coreboot/coreboot \
171 --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
172 /bin/bash -l
173
Martin Rothcbaab7e2016-08-31 21:26:17 -0600174help:
175 @echo "Commands for working with docker images:"
Martin Roth9ee70ce2016-12-30 16:26:13 -0700176 @echo " coreboot-sdk - Build coreboot-sdk container"
Martin Rothcbaab7e2016-08-31 21:26:17 -0600177 @echo " upload-coreboot-sdk - Upload coreboot-sdk to hub.docker.com"
Martin Roth9ee70ce2016-12-30 16:26:13 -0700178 @echo " coreboot-jenkins-node - Build coreboot-jenkins-node container"
Martin Rothcbaab7e2016-08-31 21:26:17 -0600179 @echo " upload-coreboot-jenkins-node - Upload coreboot-jenkins-node to hub.docker.com"
Martin Roth85782b22016-12-31 14:59:29 -0700180 @echo " clean-coreboot-containers - Remove all docker coreboot containers"
181 @echo " clean-coreboot-images - Remove all docker coreboot images"
182 @echo " clean-docker - Remove docker coreboot containers & images"
Martin Rothcbaab7e2016-08-31 21:26:17 -0600183 @echo
184 @echo "Commands for using docker images"
Martin Roth85782b22016-12-31 14:59:29 -0700185 @echo " docker-build-coreboot - Build coreboot under coreboot-sdk"
186 @echo " <BUILD_CMD=target> "
187 @echo " docker-abuild - Run abuild under coreboot-sdk"
188 @echo " <ABUILD_ARGS='-a -B'>"
189 @echo " docker-what-jenkins-does - Run 'what-jenkins-does' target"
190 @echo " docker-shell - Bash prompt in coreboot-jenkins-node"
191 @echo " <USER=root or USER=coreboot>"
192 @echo " docker-jenkins-server - Run coreboot-jenkins-node image (for server)"
Martin Roth561f3682016-12-30 17:00:19 -0700193 @echo
194 @echo "Variables:"
Martin Roth85782b22016-12-31 14:59:29 -0700195 @echo " COREBOOT_JENKINS_PORT=$(COREBOOT_JENKINS_PORT)"
196 @echo " COREBOOT_JENKINS_CACHE_DIR=$(COREBOOT_JENKINS_CACHE_DIR)"
197 @echo " COREBOOT_JENKINS_CCACHE_DIR=$(COREBOOT_JENKINS_CCACHE_DIR)"
198 @echo " COREBOOT_JENKINS_CONTAINER=$(COREBOOT_JENKINS_CONTAINER)"
199 @echo " COREBOOT_CONTAINER_VERSION=$(COREBOOT_CONTAINER_VERSION)"
200 @echo " DOCKER_COMMIT=$(DOCKER_COMMIT)"
Martin Rothcbaab7e2016-08-31 21:26:17 -0600201
Martin Roth9ee70ce2016-12-30 16:26:13 -0700202.PHONY: test-docker test-docker-login
203.PHONY: coreboot-jenkins-node upload-coreboot-jenkins-node
204.PHONY: coreboot-sdk upload-coreboot-sdk
205.PHONY: clean-coreboot-containers clean-coreboot-images
206.PHONY: docker-abuild
Martin Roth85782b22016-12-31 14:59:29 -0700207.PHONY: docker-what-jenkins-does docker-shell docker-jenkins-server
Martin Roth9ee70ce2016-12-30 16:26:13 -0700208.PHONY: help