1 ##############################################################################
2 # Copyright (c) 2015,2016 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
12 FILES = $(wildcard ubuntu-builder/*) runcontext
13 DOCKER_VER := $(shell [[ "$$(docker version --format '{{.Client.Version}}')" =~ ([0-9]+)\.([0-9]+) ]] && echo $$(( $${BASH_REMATCH[1]} * 100 + $${BASH_REMATCH[2]} )))
15 # Builder tag lifespan, force container rebuild X days after tag creation
17 DOCKER_IMG = opnfv.org/ubuntu-builder
18 DOCKER_TAG = ${DOCKER_IMG}:14.04
19 # Shell contruct for checking our tag object did not expire
20 DOCKER_EXPIRED = D_TAG_BIRTH=`docker inspect --format="{{.Created}}" \
21 ${DOCKER_TAG} 2>/dev/null`; test -z "$$D_TAG_BIRTH" -o `date +%s` -gt \
22 `date -d "$$D_TAG_BIRTH +${DOCKER_KEEP}" +%s`; echo $$?
24 # Don't use -f flag when docker is newer than 1.9
25 # https://docs.docker.com/engine/deprecated/#/f-flag-on-docker-tag
26 ifeq ($(shell echo "$(DOCKER_VER)>109" | bc), 1)
36 cp Dockerfile ubuntu-builder/Dockerfile
37 # Only add proxy ENVs where set in host - needed to pull the base Ubuntu image
38 test -n "${http_proxy}" && sed -i "s;INSERT_HTTP_PROXY;${http_proxy};" ubuntu-builder/Dockerfile || exit 0
39 test -n "${https_proxy}" && sed -i "s;INSERT_HTTPS_PROXY;${https_proxy};" ubuntu-builder/Dockerfile || exit 0
40 test -n "${no_proxy}" && sed -i "s;INSERT_NO_PROXY;${no_proxy};" ubuntu-builder/Dockerfile || exit 0
41 test -n "${HTTP_PROXY}" && sed -i "s;INSERT_HTTP_PROXY;${HTTP_PROXY};" ubuntu-builder/Dockerfile || exit 0
42 test -n "${HTTPS_PROXY}" && sed -i "s;INSERT_HTTPS_PROXY;${HTTPS_PROXY};" ubuntu-builder/Dockerfile || exit 0
43 test -n "${NO_PROXY}" && sed -i "s;INSERT_NO_PROXY;${NO_PROXY};" ubuntu-builder/Dockerfile || exit 0
44 sed -i '/INSERT_/d' ubuntu-builder/Dockerfile
48 @if test "$(shell ${DOCKER_EXPIRED})" -eq "0"; then \
49 /usr/bin/docker build --rm=true --no-cache=true \
50 -t ${DOCKER_TAG} ubuntu-builder && \
51 /usr/bin/docker tag ${tag_flags} ${DOCKER_TAG} ${DOCKER_IMG}; \
53 echo "Docker: Tag '${DOCKER_TAG}' was created less than" \
54 "${DOCKER_KEEP} ago, skipping re-build."; \
57 test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
61 rm -f .docker* ubuntu-builder/Dockerfile
64 deepclean: clean clean-cache
66 ##############################################################################
67 # Cache operations - only used when building through ci/build.sh
68 ##############################################################################
70 # NOTE: For docker, we only get/put cache to fingerprint build scripts and
71 # env vars, its cached data holds only an empty .docker file.
73 # Create a unique hash to be used for getting and putting cache, based on:
74 # - ubuntu-builder Dockerfile (includes eventual proxy env vars), runcontext;
75 # - The contents of this Makefile
77 sha1sum Makefile runcontext $(wildcard ubuntu-builder/*) > .cachedata
78 cat .cachedata | $(CACHETOOL) getid > .cacheid
80 # Clean local data related to caching - called prior to ordinary build
83 rm -f .cachedata .cacheid
85 # Try to download cache - called prior to ordinary build
88 @if $(CACHETOOL) check $(shell cat .cacheid); then \
89 if test "$(shell ${DOCKER_EXPIRED})" -eq "0"; then \
90 echo "Docker: Tag '${DOCKER_TAG}' missing" \
91 "or older than ${DOCKER_KEEP}, not using it."; \
96 echo "No cache item found for $(shell cat .cacheid)" ;\
100 # Store cache if not already stored - called after ordinary build
103 @tar cf - .docker | $(CACHETOOL) put $(shell cat .cacheid)