summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Levand <geoff@infradead.org>2018-05-21 19:59:39 +0000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-05-23 11:11:36 +1000
commit1c45cf6e9393e8c27acfa7c86ea305bcc26ff258 (patch)
tree4930300e91bacccd1657de6ab3ca643c32d51c85
parent1214247667d138e2fa1748f4f270e5fc80010377 (diff)
downloadtalos-petitboot-1c45cf6e9393e8c27acfa7c86ea305bcc26ff258.zip
talos-petitboot-1c45cf6e9393e8c27acfa7c86ea305bcc26ff258.tar.gz
docker: Add DOCKER_FROM arg
The dockerfile for each architecture is the same except for the 'FROM' image. Add a new Dockerfile argument DOCKER_FROM that allows for a commom dockerfile. If the docker version is older than 17.05 generate a docker file from the common one. Signed-off-by: Geoff Levand <geoff@infradead.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
-rw-r--r--docker/Dockerfile.builder (renamed from docker/Dockerfile.builder.amd64)4
-rw-r--r--docker/Dockerfile.builder.arm6424
-rwxr-xr-xdocker/build-builder26
-rw-r--r--docker/builder-include13
4 files changed, 40 insertions, 27 deletions
diff --git a/docker/Dockerfile.builder.amd64 b/docker/Dockerfile.builder
index dc0cce4..b4e3827 100644
--- a/docker/Dockerfile.builder.amd64
+++ b/docker/Dockerfile.builder
@@ -1,6 +1,8 @@
# Image for compiling petitboot.
-FROM ubuntu:17.10
+ARG DOCKER_FROM
+
+FROM ${DOCKER_FROM}
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
diff --git a/docker/Dockerfile.builder.arm64 b/docker/Dockerfile.builder.arm64
deleted file mode 100644
index d46581f..0000000
--- a/docker/Dockerfile.builder.arm64
+++ /dev/null
@@ -1,24 +0,0 @@
-# Image for compiling petitboot.
-
-FROM arm64v8/ubuntu:17.10
-
-ENV LANG C.UTF-8
-ENV LC_ALL C.UTF-8
-
-RUN apt-get update && apt-get install -y \
- apt-utils \
- autoconf \
- autopoint \
- bison \
- flex \
- gettext \
- gcc \
- git \
- libtool \
- libuv-dev \
- libdevmapper-dev \
- libncurses-dev \
- pkg-config \
- && rm -rf /var/lib/apt/lists/*
-
-CMD /bin/bash
diff --git a/docker/build-builder b/docker/build-builder
index 8a5015c..04603ad 100755
--- a/docker/build-builder
+++ b/docker/build-builder
@@ -8,7 +8,8 @@ name="$(basename $0)"
source ${TOP_DIR}/docker/builder-include
-: ${DOCKER_FILE:="${TOP_DIR}/docker/Dockerfile.builder.$(arch)"}
+: ${DOCKER_FILE:="${TOP_DIR}/docker/Dockerfile.builder"}
+: ${DOCKER_FROM:="$(docker_from)"}
usage () {
echo "${name} - Builds a docker image that contains tools for building petitboot." >&2
@@ -22,6 +23,7 @@ usage () {
echo " -v --verbose - Verbose execution." >&2
echo "Environment:" >&2
echo " DOCKER_FILE - Default: '${DOCKER_FILE}'" >&2
+ echo " DOCKER_FROM - Default: '${DOCKER_FROM}'" >&2
echo " DOCKER_TAG - Default: '${DOCKER_TAG}'" >&2
echo "Examples:" >&2
echo " ${name} -v"
@@ -87,6 +89,22 @@ if [[ -n "${tag}" ]]; then
exit 0
fi
+version () {
+ echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
+}
+
+# Support for docker versions older than 17.05.
+# See https://github.com/moby/moby/issues/32457
+if [[ $(version "$(docker version --format '{{.Server.Version}}')") < $(version "17.05") ]]; then
+ tmp_file="${DOCKER_FILE}.tmp"
+ trap "rm -f ${tmp_file}" EXIT
+
+ cp -f ${DOCKER_FILE} ${tmp_file}
+ DOCKER_FILE=${tmp_file}
+ sed --in-place "s|ARG DOCKER_FROM||" ${tmp_file}
+ sed --in-place "s|\${DOCKER_FROM}|${DOCKER_FROM}|" ${tmp_file}
+fi
+
if [[ -n "${purge}" ]] && docker inspect --type image ${DOCKER_TAG} >/dev/null 2>/dev/null; then
echo "Removing docker image: ${DOCKER_TAG}" >&2
run_cmd "docker rmi --force ${DOCKER_TAG}"
@@ -99,6 +117,10 @@ fi
echo "Building docker image: ${DOCKER_TAG}" >&2
cd ${TOP_DIR}
-run_cmd "docker build --file ${DOCKER_FILE} --tag ${DOCKER_TAG} ."
+run_cmd "docker build \
+ --file "${DOCKER_FILE}" \
+ --build-arg DOCKER_FROM=${DOCKER_FROM} \
+ --tag ${DOCKER_TAG} \
+ ."
show_tag
diff --git a/docker/builder-include b/docker/builder-include
index 40e0120..87405b8 100644
--- a/docker/builder-include
+++ b/docker/builder-include
@@ -19,6 +19,19 @@ arch_tag() {
esac
}
+docker_from() {
+ local a="$(arch)"
+
+ case "${a}" in
+ amd64) echo "ubuntu:17.10" ;;
+ arm64) echo "arm64v8/ubuntu:17.10" ;;
+ *)
+ echo "${name}: ERROR: Unknown arch ${a}" >&2
+ exit 1
+ ;;
+ esac
+}
+
run_cmd () {
local cmd="${*}"
OpenPOWER on IntegriCloud