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 | |
| 19 | # Version of the jenkins / sdk container |
| 20 | export COREBOOT_CONTAINER_VERSION?=$(crossgcc_version) |
| 21 | |
| 22 | # Commit id to build from |
| 23 | export DOCKER_COMMIT?=$(shell git log -n 1 --pretty=%h) |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 24 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 25 | test-docker: |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 26 | $(if $(DOCKER),,\ |
| 27 | $(warning Docker command not found. Please install docker) \ |
| 28 | $(warning https://docs.docker.com/engine/installation ) \ |
| 29 | $(error halting)) |
| 30 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 31 | test-docker-login: test-docker |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 32 | $(if $(shell if [ ! -f ~/.docker/config.json ]; then \ |
| 33 | echo "docker authentication file not found"; fi), \ |
| 34 | $(error Docker authentication file not found. Run 'docker login')) |
| 35 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 36 | coreboot-sdk: test-docker |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 37 | @echo "Building coreboot SDK $(crossgcc_version) from commit $(DOCKER_COMMIT)" |
| 38 | cat coreboot-sdk/Dockerfile | \ |
| 39 | sed "s/{{DOCKER_COMMIT}}/$(DOCKER_COMMIT)/" | \ |
| 40 | sed "s/{{SDK_VERSION}}/$(COREBOOT_CONTAINER_VERSION)/" | \ |
| 41 | $(DOCKER) build -t coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) - |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 42 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 43 | upload-coreboot-sdk: test-docker-login |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 44 | $(DOCKER) push coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 45 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 46 | coreboot-jenkins-node: test-docker |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 47 | cat coreboot-jenkins-node/Dockerfile | \ |
| 48 | sed "s/{{SDK_VERSION}}/$(COREBOOT_CONTAINER_VERSION)/" | \ |
| 49 | sed "s|{{SSH_KEY}}|$$(cat coreboot-jenkins-node/authorized_keys)|" | \ |
| 50 | $(DOCKER) build -t coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION) - |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 51 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 52 | upload-coreboot-jenkins-node: test-docker-login |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 53 | $(DOCKER) push coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION) |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 54 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 55 | docker-killall: test-docker |
Martin Roth | af25fd7 | 2016-12-30 16:12:30 -0700 | [diff] [blame] | 56 | @if [ -n "$$($(DOCKER) ps | grep 'coreboot')" ]; then \ |
| 57 | $(DOCKER) kill $$($(DOCKER) ps | grep 'coreboot' | cut -f1 -d ' '); \ |
| 58 | fi |
| 59 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 60 | clean-coreboot-containers: docker-killall |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 61 | $(DOCKER) rm $(docker ps -a | grep 'coreboot' | sed 's|\s.*$||') |
| 62 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 63 | clean-coreboot-images: docker-killall |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 64 | $(DOCKER) rmi $(docker images | grep coreboot | sed 's|^\S\+\s\+\S\+\s\+||' | sed 's|\s.*$||') |
| 65 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 66 | docker-build-coreboot: test-docker |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 67 | $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \ |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 68 | --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \ |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 69 | /bin/bash -c "cd /home/coreboot/coreboot && \ |
| 70 | make clean && \ |
| 71 | make $(BUILD_CMD)" |
| 72 | @echo "Enter root password to chown files to $$(whoami):$$(id -gn $$(whoami))" |
| 73 | @echo "Exiting now will leave built files owned by root" |
| 74 | sudo chown -R $$(whoami):$$(id -gn $$(whoami)) $(top) |
| 75 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 76 | docker-abuild: test-docker |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 77 | $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \ |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 78 | --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \ |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 79 | /bin/bash -c "cd /home/coreboot/coreboot && \ |
| 80 | make clean && \ |
| 81 | util/abuild/abuild $(ABUILD_ARGS)" |
| 82 | @echo "Enter root password to chown files to $$(whoami):$$(id -gn $$(whoami))" |
| 83 | @echo "Exiting now will leave built files owned by root" |
| 84 | sudo chown -R $$(whoami):$$(id -gn $$(whoami)) $(top) |
| 85 | |
| 86 | help: |
| 87 | @echo "Commands for working with docker images:" |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 88 | @echo " coreboot-sdk - Build coreboot-sdk container" |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 89 | @echo " upload-coreboot-sdk - Upload coreboot-sdk to hub.docker.com" |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 90 | @echo " coreboot-jenkins-node - Build coreboot-jenkins-node container" |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 91 | @echo " upload-coreboot-jenkins-node - Upload coreboot-jenkins-node to hub.docker.com" |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 92 | @echo " clean-coreboot-containers - remove all docker coreboot containers" |
| 93 | @echo " clean-coreboot-images - remove all docker coreboot images" |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 94 | @echo |
| 95 | @echo "Commands for using docker images" |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 96 | @echo " docker-build-coreboot <BUILD_CMD=target> - Build coreboot under coreboot-sdk" |
| 97 | @echo " docker-abuild <ABUILD_ARGS='-a -B'> - Run abuild under coreboot-sdk" |
Martin Roth | 561f368 | 2016-12-30 17:00:19 -0700 | [diff] [blame] | 98 | @echo |
| 99 | @echo "Variables:" |
| 100 | @echo " COREBOOT_CONTAINER_VERSION = $(COREBOOT_CONTAINER_VERSION)" |
| 101 | @echo " DOCKER_COMMIT = $(DOCKER_COMMIT)" |
Martin Roth | cbaab7e | 2016-08-31 21:26:17 -0600 | [diff] [blame] | 102 | |
Martin Roth | 9ee70ce | 2016-12-30 16:26:13 -0700 | [diff] [blame] | 103 | .PHONY: test-docker test-docker-login |
| 104 | .PHONY: coreboot-jenkins-node upload-coreboot-jenkins-node |
| 105 | .PHONY: coreboot-sdk upload-coreboot-sdk |
| 106 | .PHONY: clean-coreboot-containers clean-coreboot-images |
| 107 | .PHONY: docker-abuild |
| 108 | .PHONY: help |