2 ## This file is part of the coreboot project.
4 ## Copyright (C) 2016 Google, Inc.
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.
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.
15 export top
=$(abspath
$(CURDIR
)/..
/..
)
16 export crossgcc_version
=$(shell $(top
)/util
/crossgcc
/buildgcc
--version | grep
'cross toolchain' | sed
's/^.*\sv//' | sed
's/\s.*$$//')
17 export DOCKER
:=$(shell $(SHELL
) -c
"command -v docker")
19 # Local port to forward to the jenkins image for the test server
20 export COREBOOT_JENKINS_PORT?
=49151
22 # Local cache directory - for storing files shared with the docker image
23 export COREBOOT_JENKINS_CACHE_DIR?
=/srv
/docker
/coreboot-builder
/cache
25 # Name of the jenkins container
26 export COREBOOT_JENKINS_CONTAINER?
=coreboot_jenkins
28 # Version of the jenkins / sdk container
29 export COREBOOT_IMAGE_TAG?
=$(crossgcc_version
)
31 # Commit id to build from
32 export DOCKER_COMMIT?
=$(shell git log
-n
1 --pretty
=%h
)
35 export DOCKER_CCACHE?
=$(HOME
)/.ccache
38 export COREBOOT_CROSSGCC_PARAM?
=all_without_gdb
45 $(warning Docker command not found. Please
install docker
) \
46 $(warning https
://docs.docker.com
/engine
/installation
) \
49 test-docker-login
: test-docker
50 $(if
$(shell if
[ ! -f ~
/.docker
/config.json
]; then \
51 echo
"docker authentication file not found"; fi
), \
52 $(error Docker authentication file not found. Run
'docker login'))
54 coreboot-sdk
: test-docker
55 @echo
"Building coreboot SDK $(crossgcc_version) from commit $(DOCKER_COMMIT)"
56 cat coreboot-sdk
/Dockerfile | \
57 sed
"s/{{DOCKER_COMMIT}}/$(DOCKER_COMMIT)/" | \
58 sed
"s/{{SDK_VERSION}}/$(COREBOOT_IMAGE_TAG)/" | \
59 sed
"s/{{CROSSGCC_PARAM}}/$(COREBOOT_CROSSGCC_PARAM)/" | \
60 $(DOCKER
) build
-t coreboot
/coreboot-sdk
:$(COREBOOT_IMAGE_TAG
) -
62 upload-coreboot-sdk
: test-docker-login
63 $(DOCKER
) push coreboot
/coreboot-sdk
:$(COREBOOT_IMAGE_TAG
)
65 coreboot-jenkins-node
: test-docker
66 cat coreboot-jenkins-node
/Dockerfile | \
67 sed
"s/{{SDK_VERSION}}/$(COREBOOT_IMAGE_TAG)/" | \
68 sed
"s|{{SSH_KEY}}|$$(cat coreboot-jenkins-node/authorized_keys)|" | \
69 $(DOCKER
) build
-t coreboot
/coreboot-jenkins-node
:$(COREBOOT_IMAGE_TAG
) -
71 upload-coreboot-jenkins-node
: test-docker-login
72 $(DOCKER
) push coreboot
/coreboot-jenkins-node
:$(COREBOOT_IMAGE_TAG
)
74 docker-killall
: test-docker
75 @if
[ -n
"$$($(DOCKER) ps | grep 'coreboot')" ]; then \
76 $(DOCKER
) kill
$$($(DOCKER
) ps | grep
'coreboot' | cut
-f1
-d
' '); \
79 clean-coreboot-containers
: docker-killall
80 @if
[ -n
"$$($(DOCKER) ps -a | grep 'coreboot')" ]; then \
81 $(DOCKER
) rm $$($(DOCKER
) ps
-a | grep
'coreboot' | sed
's|\s.*$$||'); \
84 clean-coreboot-images
: docker-killall
85 @if
[ -n
"$$($(DOCKER) images | grep 'coreboot')" ]; then \
86 $(DOCKER
) rmi
$$($(DOCKER
) images | grep coreboot | sed
's|^\S\+\s\+\S\+\s\+||' | sed
's|\s.*$$||'); \
89 docker-clean
: clean-coreboot-containers
90 @
$(MAKE
) clean-coreboot-images
93 @if
[ -n
"$$($(DOCKER) ps -a | grep -v "CONTAINER
")" ]; then \
94 $(DOCKER
) kill
$$($(DOCKER
) ps
-a | grep
-v
"CONTAINER" | sed
's|\s.*$$||'); \
95 $(DOCKER
) rm $$($(DOCKER
) ps
-a | grep
-v
"CONTAINER" | sed
's|\s.*$$||'); \
97 @if
[ -n
"$$($(DOCKER) images | grep -v "REPOSITORY
")" ]; then \
98 $(DOCKER
) rmi
$$($(DOCKER
) images | grep
-v
"REPOSITORY" | tr
-s
' ' | cut
-f3
-d
' '); \
104 docker-run-local
: test-docker
$(DOCKER_CCACHE
)
105 $(DOCKER
) run
-it
--rm \
106 --volume
$(DOCKER_CCACHE
):/home
/coreboot
/.ccache \
107 --volume
$(top
):/home
/coreboot
/coreboot \
108 --env HOME
=/home
/coreboot \
109 --user
$(UID
):$(GID
) \
110 coreboot
/coreboot-sdk
:$(COREBOOT_IMAGE_TAG
) \
111 /bin
/bash
-c
'cd $${HOME}/coreboot && $(DOCKER_RUN_LOCAL)'
113 docker-build-coreboot
: docker-run-local
114 docker-build-coreboot
: override DOCKER_RUN_LOCAL
:= \
115 make
clean && make
$(BUILD_CMD
); rm -f .xcompile
117 docker-abuild
: docker-run-local
118 docker-abuild
: override DOCKER_RUN_LOCAL
:= \
119 make
clean && util
/abuild
/abuild
$(ABUILD_ARGS
); rm -f .xcompile
121 docker-what-jenkins-does
: docker-run-local
122 docker-what-jenkins-does
: override DOCKER_RUN_LOCAL
:= \
123 make
clean && make what-jenkins-does CPUS
=$(CPUS
)
125 docker-jenkins-server
: test-docker
126 @if
[ ! -d
"$(COREBOOT_JENKINS_CACHE_DIR)" ]; then \
127 printf
"\nError: %s does not exist.\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
128 printf
"Please run:\nsudo mkdir -p %s\n\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
131 @if
! touch
"$(COREBOOT_JENKINS_CACHE_DIR)/testfile" 2>/dev
/null
; then \
132 printf
"\nError: Cannot create file in %s." "$(COREBOOT_JENKINS_CACHE_DIR)"; \
133 printf
"Please run:\nsudo chown -R $(whoami):$(whoami) %s\n\n" "$(COREBOOT_JENKINS_CACHE_DIR)"; \
135 rm -f
"$(COREBOOT_JENKINS_CACHE_DIR)/testfile"; \
137 $(DOCKER
) run
-d
--privileged
--restart
=always \
138 -p
$(COREBOOT_JENKINS_PORT
):49151 \
139 -v
$(COREBOOT_JENKINS_CACHE_DIR
):/data
/cache \
140 --name
=$(COREBOOT_JENKINS_CONTAINER
) \
141 coreboot
/coreboot-jenkins-node
:$(COREBOOT_IMAGE_TAG
)
143 docker-jenkins-shell
: test-docker
144 @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
145 $(DOCKER
) run
-u root
-it
--privileged \
146 --entrypoint
="/bin/bash" \
147 -p
$(COREBOOT_JENKINS_PORT
):49151 \
148 -v
$(top
):/home
/coreboot
/coreboot \
149 -v
$(COREBOOT_JENKINS_CACHE_DIR
):/data
/cache \
150 --name
=$(COREBOOT_JENKINS_CONTAINER
) \
151 --rm coreboot
/coreboot-jenkins-node
:$(COREBOOT_IMAGE_TAG
)
153 docker-shell
: USER
=coreboot
154 docker-shell
: test-docker
155 $(DOCKER
) run
-u
$(USER
) -it \
156 -e COLUMNS
=$(shell tput cols
) -e LINES
=$(shell tput lines
) -e TERM
=$(TERM
) \
157 -w
/home
/coreboot
/coreboot \
158 -v
$(top
):/home
/coreboot
/coreboot \
159 --rm coreboot
/coreboot-sdk
:$(COREBOOT_IMAGE_TAG
) \
162 docker-jenkins-attach
: USER
=root
163 docker-jenkins-attach
:
164 docker exec
--user
$(USER
) \
165 -e COLUMNS
=$(shell tput cols
) -e LINES
=$(shell tput lines
) -e TERM
=$(TERM
) \
166 -it
"$$(docker ps | grep coreboot-jenkins-node | cut -f1 -d' ')" \
170 @echo
"Commands for working with docker images:"
171 @echo
" coreboot-sdk - Build coreboot-sdk container"
172 @echo
" upload-coreboot-sdk - Upload coreboot-sdk to hub.docker.com"
173 @echo
" coreboot-jenkins-node - Build coreboot-jenkins-node container"
174 @echo
" upload-coreboot-jenkins-node - Upload coreboot-jenkins-node to hub.docker.com"
175 @echo
" clean-coreboot-containers - Remove all docker coreboot containers"
176 @echo
" clean-coreboot-images - Remove all docker coreboot images"
177 @echo
" clean-docker - Remove docker coreboot containers & images"
179 @echo
"Commands for using docker images"
180 @echo
" docker-build-coreboot - Build coreboot under coreboot-sdk"
181 @echo
" <BUILD_CMD=target> "
182 @echo
" docker-abuild - Run abuild under coreboot-sdk"
183 @echo
" <ABUILD_ARGS='-a -B'>"
184 @echo
" docker-what-jenkins-does - Run 'what-jenkins-does' target"
185 @echo
" docker-shell - Bash prompt in coreboot-jenkins-node"
186 @echo
" <USER=root or USER=coreboot>"
187 @echo
" docker-jenkins-server - Run coreboot-jenkins-node image (for server)"
188 @echo
" docker-jenkins-attach - Open shell in running jenkins server"
191 @echo
" COREBOOT_JENKINS_PORT=$(COREBOOT_JENKINS_PORT)"
192 @echo
" COREBOOT_JENKINS_CACHE_DIR=$(COREBOOT_JENKINS_CACHE_DIR)"
193 @echo
" COREBOOT_JENKINS_CONTAINER=$(COREBOOT_JENKINS_CONTAINER)"
194 @echo
" COREBOOT_IMAGE_TAG=$(COREBOOT_IMAGE_TAG)"
195 @echo
" DOCKER_COMMIT=$(DOCKER_COMMIT)"
197 .PHONY
: test-docker test-docker-login
198 .PHONY
: coreboot-jenkins-node upload-coreboot-jenkins-node
199 .PHONY
: coreboot-sdk upload-coreboot-sdk
200 .PHONY
: clean-coreboot-containers clean-coreboot-images
201 .PHONY
: docker-abuild
202 .PHONY
: docker-what-jenkins-does docker-shell docker-jenkins-server docker-jenkins-attach