From d9458e3f7378b5ab2a952512edb19854c406b450 Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Tue, 5 Sep 2017 16:35:34 +0200 Subject: Bug 1396772 - Copy image_builder v0.1.5 to nssdev/* r=franziskus Bug #: 1396772 Differential Revision: https://phabricator.services.mozilla.com/D33 --- automation/taskcluster/graph/src/context_hash.js | 16 ++++++++++++--- automation/taskcluster/graph/src/image_builder.js | 10 ++++----- automation/taskcluster/image_builder/Dockerfile | 23 +++++++++++++++++++++ automation/taskcluster/image_builder/VERSION | 1 + .../taskcluster/image_builder/bin/checkout.sh | 15 ++++++++++++++ automation/taskcluster/scripts/build_image.sh | 24 ++++++++++++++++++++++ 6 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 automation/taskcluster/image_builder/Dockerfile create mode 100644 automation/taskcluster/image_builder/VERSION create mode 100644 automation/taskcluster/image_builder/bin/checkout.sh create mode 100755 automation/taskcluster/scripts/build_image.sh (limited to 'automation/taskcluster') diff --git a/automation/taskcluster/graph/src/context_hash.js b/automation/taskcluster/graph/src/context_hash.js index f0a2e9a88..0699a0590 100644 --- a/automation/taskcluster/graph/src/context_hash.js +++ b/automation/taskcluster/graph/src/context_hash.js @@ -27,14 +27,24 @@ function collectFilesInDirectory(dir) { }); } -// Compute a context hash for the given context path. -export default function (context_path) { +// A list of hashes for each file in the given path. +function collectFileHashes(context_path) { let root = path.join(__dirname, "../../../.."); let dir = path.join(root, context_path); let files = collectFilesInDirectory(dir).sort(); - let hashes = files.map(file => { + + return files.map(file => { return sha256(file + "|" + fs.readFileSync(file, "utf-8")); }); +} + +// Compute a context hash for the given context path. +export default function (context_path) { + // Regenerate all images when the image_builder changes. + let hashes = collectFileHashes("automation/taskcluster/image_builder"); + + // Regenerate images when the image itself changes. + hashes = hashes.concat(collectFileHashes(context_path)); // Generate a new prefix every month to ensure the image stays buildable. let now = new Date(); diff --git a/automation/taskcluster/graph/src/image_builder.js b/automation/taskcluster/graph/src/image_builder.js index bc90e0242..1346f43b2 100644 --- a/automation/taskcluster/graph/src/image_builder.js +++ b/automation/taskcluster/graph/src/image_builder.js @@ -31,13 +31,11 @@ export async function buildTask({name, path}) { return { name: "Image Builder", - image: "taskcluster/image_builder:0.1.5", + image: "nssdev/image_builder:0.1.5", routes: ["index." + ns], env: { - HEAD_REPOSITORY: process.env.NSS_HEAD_REPOSITORY, - BASE_REPOSITORY: process.env.NSS_HEAD_REPOSITORY, - HEAD_REV: process.env.NSS_HEAD_REVISION, - HEAD_REF: process.env.NSS_HEAD_REVISION, + NSS_HEAD_REPOSITORY: process.env.NSS_HEAD_REPOSITORY, + NSS_HEAD_REVISION: process.env.NSS_HEAD_REVISION, PROJECT: process.env.TC_PROJECT, CONTEXT_PATH: path, HASH: hash @@ -52,7 +50,7 @@ export async function buildTask({name, path}) { command: [ "/bin/bash", "-c", - "/home/worker/bin/build_image.sh" + "bin/checkout.sh && nss/automation/taskcluster/scripts/build_image.sh" ], platform: "nss-decision", features: ["dind"], diff --git a/automation/taskcluster/image_builder/Dockerfile b/automation/taskcluster/image_builder/Dockerfile new file mode 100644 index 000000000..f8b4edcc5 --- /dev/null +++ b/automation/taskcluster/image_builder/Dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu:16.04 +MAINTAINER Tim Taubert + +WORKDIR /home/worker + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get install -y apt-transport-https apt-utils +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 && \ + sh -c "echo deb https://get.docker.io/ubuntu docker main \ + > /etc/apt/sources.list.d/docker.list" +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 41BD8711B1F0EC2B0D85B91CF59CE3A8323293EE && \ + sh -c "echo deb http://ppa.launchpad.net/mercurial-ppa/releases/ubuntu xenial main \ + > /etc/apt/sources.list.d/mercurial.list" +RUN apt-get update && apt-get install -y \ + lxc-docker-1.6.1 \ + mercurial + +ADD bin /home/worker/bin +RUN chmod +x /home/worker/bin/* + +# Set a default command useful for debugging +CMD ["/bin/bash", "--login"] diff --git a/automation/taskcluster/image_builder/VERSION b/automation/taskcluster/image_builder/VERSION new file mode 100644 index 000000000..9faa1b7a7 --- /dev/null +++ b/automation/taskcluster/image_builder/VERSION @@ -0,0 +1 @@ +0.1.5 diff --git a/automation/taskcluster/image_builder/bin/checkout.sh b/automation/taskcluster/image_builder/bin/checkout.sh new file mode 100644 index 000000000..0cdd2ac40 --- /dev/null +++ b/automation/taskcluster/image_builder/bin/checkout.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -v -e -x + +# Default values for testing. +REVISION=${NSS_HEAD_REVISION:-default} +REPOSITORY=${NSS_HEAD_REPOSITORY:-https://hg.mozilla.org/projects/nss} + +# Clone NSS. +for i in 0 2 5; do + sleep $i + hg clone -r $REVISION $REPOSITORY nss && exit 0 + rm -rf nss +done +exit 1 diff --git a/automation/taskcluster/scripts/build_image.sh b/automation/taskcluster/scripts/build_image.sh new file mode 100755 index 000000000..b422214e7 --- /dev/null +++ b/automation/taskcluster/scripts/build_image.sh @@ -0,0 +1,24 @@ +#!/bin/bash -vex + +set -x -e -v + +# Prefix errors with taskcluster error prefix so that they are parsed by Treeherder +raise_error() { + echo + echo "[taskcluster-image-build:error] $1" + exit 1 +} + +# Ensure that the PROJECT is specified so the image can be indexed +test -n "$PROJECT" || raise_error "Project must be provided." +test -n "$HASH" || raise_error "Context Hash must be provided." + +CONTEXT_PATH=/home/worker/nss/$CONTEXT_PATH + +test -d $CONTEXT_PATH || raise_error "Context Path $CONTEXT_PATH does not exist." +test -f "$CONTEXT_PATH/Dockerfile" || raise_error "Dockerfile must be present in $CONTEXT_PATH." + +docker build -t $PROJECT:$HASH $CONTEXT_PATH + +mkdir /artifacts +docker save $PROJECT:$HASH > /artifacts/image.tar -- cgit v1.2.1