Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 1 | ## |
| 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 | ## |
| 15 | export top=$(abspath $(CURDIR)/../..) |
| 16 | export crossgcc_version=$(shell $(top)/util/crossgcc/buildgcc --version | grep 'cross toolchain' | sed 's/^.*\sv//' | sed 's/\s.*$$//') |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 17 | export DOCKER:=$(shell $(SHELL) -c "command -v docker") |
| 18 | |
Martin Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 19 | # Local port to forward to the jenkins image for the test server |
| 20 | export COREBOOT_JENKINS_PORT?=49151 |
| 21 | |
| 22 | # Local cache directory - for storing files shared with the docker image |
| 23 | export COREBOOT_JENKINS_CACHE_DIR?=/srv/docker/coreboot-builder/cache |
| 24 | |
| 25 | # Local ccache directory |
| 26 | export COREBOOT_JENKINS_CCACHE_DIR?=/srv/docker/coreboot-builder/ccache |
| 27 | |
| 28 | # Name of the jenkins container |
| 29 | export COREBOOT_JENKINS_CONTAINER?=coreboot_jenkins |
| 30 | |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 31 | # Version of the jenkins / sdk container |
| 32 | export COREBOOT_CONTAINER_VERSION?=$(crossgcc_version) |
| 33 | |
| 34 | # Commit id to build from |
| 35 | export DOCKER_COMMIT?=$(shell git log -n 1 --pretty=%h) |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 36 | |
Piotr Król | 64f87f3 | 2017-10-20 12:17:34 +0200 | [diff] [blame] | 37 | # SDK architecture |
| 38 | export COREBOOT_CROSSGCC_PARAM?=all_without_gdb |
| 39 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 40 | test-docker: |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 41 | $(if $(DOCKER),,\ |
| 42 | $(warning Docker command not found. Please install docker) \ |
| 43 | $(warning https://docs.docker.com/engine/installation ) \ |
| 44 | $(error halting)) |
| 45 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 46 | test-docker-login: test-docker |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 47 | $(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 Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 51 | coreboot-sdk: test-docker |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 52 | @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ól | 64f87f3 | 2017-10-20 12:17:34 +0200 | [diff] [blame] | 56 | sed "s/{{CROSSGCC_PARAM}}/$(COREBOOT_CROSSGCC_PARAM)/" | \ |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 57 | $(DOCKER) build -t coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) - |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 58 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 59 | upload-coreboot-sdk: test-docker-login |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 60 | $(DOCKER) push coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 61 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 62 | coreboot-jenkins-node: test-docker |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 63 | 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 Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 67 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 68 | upload-coreboot-jenkins-node: test-docker-login |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 69 | $(DOCKER) push coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION) |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 70 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 71 | docker-killall: test-docker |
Martin Roth | af25fd7 | 2016-12-30 16:12:30 -0700 | [diff] [blame] | 72 | @if [ -n "$$($(DOCKER) ps | grep 'coreboot')" ]; then \ |
| 73 | $(DOCKER) kill $$($(DOCKER) ps | grep 'coreboot' | cut -f1 -d ' '); \ |
| 74 | fi |
| 75 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 76 | clean-coreboot-containers: docker-killall |
Martin Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 77 | @if [ -n "$$($(DOCKER) ps -a | grep 'coreboot')" ]; then \ |
| 78 | $(DOCKER) rm $$($(DOCKER) ps -a | grep 'coreboot' | sed 's|\s.*$$||'); \ |
| 79 | fi |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 80 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 81 | clean-coreboot-images: docker-killall |
Martin Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 82 | @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 | |
| 86 | docker-clean: clean-coreboot-containers |
| 87 | @$(MAKE) clean-coreboot-images |
| 88 | |
| 89 | docker-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 Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 97 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 98 | docker-build-coreboot: test-docker |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 99 | $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \ |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 100 | --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \ |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 101 | /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 Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 108 | docker-abuild: test-docker |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 109 | $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \ |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 110 | --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \ |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 111 | /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 Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 118 | docker-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 | |
| 124 | docker-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 | |
| 154 | docker-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 | |
| 166 | docker-shell: USER=coreboot |
| 167 | docker-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 Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 174 | help: |
| 175 | @echo "Commands for working with docker images:" |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 176 | @echo " coreboot-sdk - Build coreboot-sdk container" |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 177 | @echo " upload-coreboot-sdk - Upload coreboot-sdk to hub.docker.com" |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 178 | @echo " coreboot-jenkins-node - Build coreboot-jenkins-node container" |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 179 | @echo " upload-coreboot-jenkins-node - Upload coreboot-jenkins-node to hub.docker.com" |
Martin Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 180 | @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 Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 183 | @echo |
| 184 | @echo "Commands for using docker images" |
Martin Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 185 | @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 Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 193 | @echo |
| 194 | @echo "Variables:" |
Martin Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 195 | @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 Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 201 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 202 | .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 Roth | 85782b2 | 2016-12-31 14:59:29 -0700 | [diff] [blame] | 207 | .PHONY: docker-what-jenkins-does docker-shell docker-jenkins-server |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 208 | .PHONY: help |