github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/Makefile (about) 1 SOURCEDIR=. 2 SOURCES := $(shell find $(SOURCEDIR) -name '*.go') 3 4 define pull_container 5 docker pull projectunik/$(1):$(shell jq '.["$(1)"]' containers/versions.json) 6 endef 7 8 define update_container_dependency 9 cat containers/versions.json | jq .['"$(2)"'] -r 10 $(eval BASE_VERSION=$(shell cat containers/versions.json | jq .['"$(2)"'] -r)) 11 echo $(BASE_VERSION) 12 cd containers/$(1) && perl -pi -e 's/FROM projectunik\/(.*):.*/FROM projectunik\/$$1:$(BASE_VERSION)/g' Dockerfile$(3) 13 endef 14 15 define update_version_bindata 16 go-bindata -pkg versiondata -o containers/container-versions.go containers/versions.json 17 endef 18 19 define update_container_version 20 echo $(2) > tmpfile 21 cat containers/versions.json | jq .['"$(1)"']=\"`cat tmpfile`\" > containers/versions.json 22 rm tmpfile 23 $(call update_version_bindata) 24 endef 25 26 define build_container 27 $(eval BASE_CONTAINER=$(shell cd containers/$(1) && cat Dockerfile$(3) | grep FROM | perl -p -e 's/FROM projectunik\/(.*):.*/$$1/g')) 28 echo $(BASE_CONTAINER) 29 $(if $(findstring FROM,$(BASE_CONTAINER)),,$(call update_container_dependency,$(1),$(BASE_CONTAINER),$(3))) 30 cd containers/$(1) && docker build -t projectunik/$(2):build -f Dockerfile$(3) . 31 $(eval CONTAINER_TAG=$(shell echo 'docker inspect projectunik/$(2):build')) 32 $(eval CONTAINER_TAG=$(shell echo '$(CONTAINER_TAG) | jq .[].Id' -r )) 33 $(eval CONTAINER_TAG=$(shell echo '$(CONTAINER_TAG) | sed 's/sha256://g'' )) 34 $(eval CONTAINER_TAG=$(shell echo '$(CONTAINER_TAG) | head -c 16' )) 35 $(eval CONTAINER_TAG=$(shell echo '$$$$($(CONTAINER_TAG))' )) 36 docker tag projectunik/$(2):build projectunik/$(2):$(CONTAINER_TAG) 37 $(call update_container_version,$(2),$(CONTAINER_TAG)) 38 @echo Built projectunik/$(2):$(CONTAINER_TAG) 39 docker rmi projectunik/$(2):build 40 endef 41 42 define remove_container 43 docker rmi -f projectunik/$(1):$(shell cat containers/versions.json | jq '.["$(1)"]') 44 endef 45 46 all: ${SOURCES} binary 47 48 .PHONY: pull 49 .PHONY: containers 50 .PHONY: rump-debugger-qemu 51 .PHONY: compilers-includeos-cpp-common 52 .PHONY: compilers-includeos-cpp-hw 53 .PHONY: compilers-rump-base-common 54 .PHONY: compilers-rump-base-hw 55 .PHONY: compilers-rump-base-xen 56 .PHONY: compilers-rump-java-hw 57 .PHONY: compilers-rump-go-hw 58 .PHONY: compilers-rump-go-xen 59 .PHONY: compilers-rump-nodejs-hw 60 .PHONY: compilers-rump-nodejs-hw-no-stub 61 .PHONY: compilers-rump-nodejs-xen 62 .PHONY: compilers-rump-c-hw 63 .PHONY: compilers-rump-c-xen 64 .PHONY: compilers-rump-python3-hw 65 .PHONY: compilers-rump-python3-hw-no-stub 66 .PHONY: compilers-rump-python3-xen 67 .PHONY: compilers-osv-java 68 .PHONY: compilers-osv-dynamic 69 .PHONY: compilers-mirage-ocaml-xen 70 .PHONY: compilers-mirage-ocaml-ukvm 71 72 .PHONY: compilers 73 .PHONY: boot-creator 74 .PHONY: image-creator 75 .PHONY: vsphere-client 76 .PHONY: qemu-util 77 .PHONY: utils 78 79 #pull containers 80 pull: 81 @echo "Pullling containers from docker hub" 82 $(call pull_container,vsphere-client) 83 $(call pull_container,boot-creator) 84 $(call pull_container,qemu-util) 85 $(call pull_container,compilers-includeos-cpp-hw) 86 $(call pull_container,compilers-osv-java) 87 $(call pull_container,compilers-osv-dynamic) 88 $(call pull_container,compilers-rump-java-hw) 89 $(call pull_container,compilers-rump-java-xen) 90 $(call pull_container,compilers-rump-go-hw) 91 $(call pull_container,compilers-rump-go-xen) 92 $(call pull_container,compilers-rump-nodejs-hw) 93 $(call pull_container,compilers-rump-nodejs-hw-no-stub) 94 $(call pull_container,compilers-rump-nodejs-xen) 95 $(call pull_container,compilers-rump-c-hw) 96 $(call pull_container,compilers-rump-c-xen) 97 $(call pull_container,compilers-rump-python3-hw) 98 $(call pull_container,compilers-rump-python3-hw-no-stub) 99 $(call pull_container,compilers-rump-python3-xen) 100 $(call pull_container,compilers-rump-base-xen) 101 $(call pull_container,compilers-rump-base-hw) 102 $(call pull_container,rump-debugger-qemu) 103 $(call pull_container,compilers-rump-base-common) 104 docker pull euranova/ubuntu-vbox 105 #------ 106 107 #build containers from source 108 containers: compilers utils 109 echo "Built containers from source" 110 111 #compilers 112 compilers: compilers-includeos-cpp-hw \ 113 compilers-rump-java-hw \ 114 compilers-rump-java-xen \ 115 compilers-rump-go-hw \ 116 compilers-rump-go-xen \ 117 compilers-rump-nodejs-hw \ 118 compilers-rump-nodejs-hw-no-stub \ 119 compilers-rump-nodejs-xen \ 120 compilers-rump-c-hw \ 121 compilers-rump-c-xen \ 122 compilers-rump-python3-hw \ 123 compilers-rump-python3-hw-no-stub \ 124 compilers-rump-python3-xen \ 125 compilers-osv-java \ 126 compilers-osv-dynamic 127 128 compilers-includeos-cpp-common: 129 $(call build_container,compilers/includeos/cpp,$@,.common) 130 131 compilers-includeos-cpp-hw: compilers-includeos-cpp-common 132 $(call build_container,compilers/includeos/cpp,$@,.hw) 133 134 compilers-rump-base-common: 135 $(call build_container,compilers/rump/base,$@,.common) 136 137 compilers-rump-base-hw: compilers-rump-base-common 138 $(call build_container,compilers/rump/base,$@,.hw) 139 140 compilers-rump-base-xen: compilers-rump-base-common 141 $(call build_container,compilers/rump/base,$@,.xen) 142 143 compilers-rump-java-hw: compilers-rump-base-hw 144 cd containers/compilers/rump/java/java-wrapper && mvn package 145 $(call build_container,compilers/rump/java,$@,.hw) 146 147 compilers-rump-java-xen: compilers-rump-base-xen 148 cd containers/compilers/rump/java/java-wrapper && mvn package 149 $(call build_container,compilers/rump/java,$@,.xen) 150 151 rump-debugger-qemu: compilers-rump-base-hw 152 $(call build_container,debuggers/rump/base,$@,.hw) 153 154 rump-debugger-xen: compilers-rump-base-xen 155 $(call build_container,debuggers/rump/base,$@,.xen) 156 157 compilers-rump-go-hw: compilers-rump-base-hw 158 $(call build_container,compilers/rump/go,$@,.hw) 159 160 compilers-rump-go-xen: compilers-rump-base-xen 161 $(call build_container,compilers/rump/go,$@,.xen) 162 163 compilers-rump-nodejs-hw: compilers-rump-base-hw 164 $(call build_container,compilers/rump/nodejs,$@,.hw) 165 166 compilers-rump-nodejs-hw-no-stub: compilers-rump-base-hw 167 $(call build_container,compilers/rump/nodejs,$@,.hw.no-stub) 168 169 compilers-rump-nodejs-xen: compilers-rump-base-xen 170 $(call build_container,compilers/rump/nodejs,$@,.xen) 171 172 compilers-rump-c-hw: compilers-rump-go-hw 173 $(call build_container,compilers/rump/c,$@,.hw) 174 175 compilers-rump-c-xen: compilers-rump-go-xen 176 $(call build_container,compilers/rump/c,$@,.xen) 177 178 compilers-rump-python3-hw: compilers-rump-go-hw 179 $(call build_container,compilers/rump/python3,$@,.hw) 180 181 compilers-rump-python3-hw-no-stub: compilers-rump-base-hw 182 $(call build_container,compilers/rump/python3,$@,.hw.no-stub) 183 184 compilers-rump-python3-xen: compilers-rump-go-xen 185 $(call build_container,compilers/rump/python3,$@,.xen) 186 187 compilers-osv-java: 188 cd containers/compilers/osv/java-compiler/java-main-caller && mvn package 189 cd containers/compilers/osv/java-compiler && GOOS=linux go build 190 $(call build_container,compilers/osv/java-compiler,$@,) 191 cd containers/compilers/osv/java-compiler && rm java-compiler 192 cd containers/compilers/osv/java-compiler/java-main-caller && rm -rf target 193 194 compilers-osv-dynamic: 195 $(call build_container,compilers/osv/dynamic,$@,) 196 197 compilers-mirage-ocaml-xen: 198 $(call build_container,compilers/mirage/ocaml,$@,.xen) 199 200 compilers-mirage-ocaml-ukvm: 201 $(call build_container,compilers/mirage/ocaml,$@,.ukvm) 202 203 compilers-firecracker: 204 $(call build_container,compilers/firecracker,$@,) 205 206 #utils 207 utils: boot-creator image-creator vsphere-client qemu-util 208 209 boot-creator: 210 cd containers/utils/boot-creator && GO15VENDOREXPERIMENT=1 GOOS=linux go build 211 $(call build_container,utils/boot-creator,$@,) 212 cd containers/utils/boot-creator && rm boot-creator 213 214 image-creator: 215 cd containers/utils/image-creator && GO15VENDOREXPERIMENT=1 GOOS=linux go build 216 $(call build_container,utils/image-creator,$@,) 217 cd containers/utils/image-creator && rm image-creator 218 219 vsphere-client: containers/utils/vsphere-client/vsphere-client.empty 220 221 VSPHERE_CLIENT_SOURCES := containers/utils/vsphere-client/Dockerfile containers/utils/vsphere-client/pom.xml $(shell find containers/utils/vsphere-client/src/) 222 containers/utils/vsphere-client/vsphere-client.empty: $(VSPHERE_CLIENT_SOURCES) 223 cd containers/utils/vsphere-client && mvn package 224 $(call build_container,utils/vsphere-client,vsphere-client,) 225 cd containers/utils/vsphere-client && rm -rf target 226 touch containers/utils/vsphere-client/vsphere-client.empty 227 228 qemu-util: 229 $(call build_container,utils/qemu-util,$@,) 230 231 #------ 232 233 #binary 234 235 BINARY=unik 236 237 # don't override if provided already 238 ifeq (,$(TARGET_OS)) 239 UNAME:=$(shell uname) 240 ifeq ($(UNAME),Linux) 241 TARGET_OS:=linux 242 else ifeq ($(UNAME),Darwin) 243 TARGET_OS:=darwin 244 endif 245 endif 246 247 binary: ${SOURCES} 248 ifeq (,$(TARGET_OS)) 249 echo "Unknown platform $(UNAME)" 250 echo "Unknown platform $(TARGET_OS)" 251 exit 1 252 endif 253 @echo Building for platform $(UNAME) 254 docker build -t projectunik/$@ -f Dockerfile . 255 mkdir -p ./_build 256 docker run --rm -v $(shell pwd)/_build:/opt/build:z -e TARGET_OS=$(TARGET_OS) projectunik/$@ 257 #docker rmi -f projectunik/$@ 258 @echo "Install finished! UniK binary can be found at $(shell pwd)/_build/unik" 259 #---- 260 261 # local build - useful if you have development env setup. if not - use binary! (this can't depend on binary as binary depends on it via the Dockerfile) 262 localbuild: instance-listener/bindata/instance_listener_data.go containers/version-data.go ${SOURCES} 263 GOOS=${TARGET_OS} go build -v . 264 265 # local install - useful if you have development env setup. if not - use binary! (this can't depend on binary as binary depends on it via the Dockerfile) 266 localinstall: instance-listener/bindata/instance_listener_data.go containers/version-data.go ${SOURCES} 267 GOOS=${TARGET_OS} go install -v . 268 269 containers/version-data.go: containers/versions.json 270 $(call update_version_bindata) 271 272 instance-listener/bindata/instance_listener_data.go: instance-listener/main.go 273 go-bindata -pkg bindata -o instance-listener/bindata/instance_listener_data.go --ignore=instance-listener/bindata/ instance-listener/... 274 275 #clean up 276 .PHONY: uninstall remove-containers clean 277 278 uninstall: 279 rm $(which ${BINARY}) 280 281 remove-containers: 282 -docker rmi -f projectunik/binary 283 -$(call remove_container,vsphere-client) 284 -rm -rf containers/utils/vsphere-client/vsphere-client.empty 285 -$(call remove_container,image-creator) 286 -$(call remove_container,boot-creator) 287 -$(call remove_container,compilers-osv-java) 288 -$(call remove_container,compilers-osv-dynamic) 289 -$(call remove_container,compilers-rump-go-xen) 290 -$(call remove_container,compilers-rump-go-hw) 291 -$(call remove_container,compilers-rump-nodejs-hw) 292 -$(call remove_container,compilers-rump-nodejs-hw-no-stub) 293 -$(call remove_container,compilers-rump-nodejs-xen) 294 -$(call remove_container,compilers-rump-c-hw) 295 -$(call remove_container,compilers-rump-c-xen) 296 -$(call remove_container,compilers-rump-python3-hw) 297 -$(call remove_container,compilers-rump-python3-hw-no-stub) 298 -$(call remove_container,compilers-rump-python3-xen) 299 -$(call remove_container,compilers-rump-base-xen) 300 -$(call remove_container,compilers-rump-base-hw) 301 -$(call remove_container,rump-debugger-qemu) 302 -$(call remove_container,compilers-rump-base-common) 303 -$(call remove_container,compilers-firecracker) 304 305 clean: 306 rm -rf ./_build 307 #---