From patchwork Tue Jun 19 15:44:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 139190 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5391207lji; Tue, 19 Jun 2018 09:08:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK8qVVY/jHZBS2i6mmEVjBVdrQv1Rjo1DZXWt8hnGvx63QfsrTvjNeZOzhC4xBg/U3hnMlY X-Received: by 2002:ac8:f2a:: with SMTP id e39-v6mr15545947qtk.88.1529424484558; Tue, 19 Jun 2018 09:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529424484; cv=none; d=google.com; s=arc-20160816; b=LxES2CGXwLfFNHpV9ekdNFVeyauVp9y0aZHl9uovZxWkj6oaBr23rhfZQkT9R4Aj8q IJe3pc5hPsXS0W3VFBOaFMmEOpND5QSJcEN/A+g7IvQS2qIMppacbI3vt/ULstytZGCv 9J4RGkSW4J8HQ1I5EwkJewEnZP2UtkoEtT/UB/8eBRtPrX77cRj5DE8tq+B8r0PIwtJv bBCNjTTmGqgxo/XUruYOFnxYsznAbxv8bNinlCJXw69TyTs2oeV/f+bRbuBXX7iO1QEe v/bBhdtoDP8gkQ6O82uNWJSXzSARO6lxHFgYvZOHtI6J6tPVr0p8I+VZmyEdVDqulaBI WCdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=gmUYP4NWio58be30lOOjMYE5Li37ls87Zycph2WvLvQ=; b=Y97iX+YFrAe9dZdVymoIyjubZy6n8czb5V4C6ybczEt4Foge6nSdxxcOkf7MdbM/h7 18O6IeHl7Bppg1WqF+xjH1WcNLDMy7+Yh0Na5zC4iHL1OgasheGg0R0UStdbpc+Vt0jf wlPEpkvKq/W/SY8bmo3olnjTI1MbAt3UboxmSC6qEkG4IJfN2CLD7ZiNb4HtKJsNRM5W 3Q+YVuMNJ1SOJ8Rv6kXXVLyZeL2jML9T0KZVH/YXsdHfTsyTOH3kKzD/O9hXxOJCg5wv 6tjLyGyDk4IAnHEfX2ULR+PC32F9QoEnPNc7NOGQpgIBMpMmbc5h4WRGBK/akfgUo2F1 Vwzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jAh1TqVN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d30-v6si51812qtd.302.2018.06.19.09.08.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 19 Jun 2018 09:08:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jAh1TqVN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVJAp-0008EQ-W7 for patch@linaro.org; Tue, 19 Jun 2018 12:08:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVIvO-0004CK-1f for qemu-devel@nongnu.org; Tue, 19 Jun 2018 11:52:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVIvE-0001nN-S8 for qemu-devel@nongnu.org; Tue, 19 Jun 2018 11:52:05 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:39235) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVIvE-0001ly-9E for qemu-devel@nongnu.org; Tue, 19 Jun 2018 11:51:56 -0400 Received: by mail-wr0-x230.google.com with SMTP id w7-v6so170761wrn.6 for ; Tue, 19 Jun 2018 08:51:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gmUYP4NWio58be30lOOjMYE5Li37ls87Zycph2WvLvQ=; b=jAh1TqVN22h1cTpyonEpS5Jj+Ui093Fv/CQTcUuduJKX0s5QZ7XeJR+SbjAqZERFhG al/aa5ZkbeLXgBZLImRoLJ1GwnjG0GCskV+BfPOu3+92890bNhCnXYVn9lEaZDFDubGN 69/UL7TVN8U+j8pyuh+jjqnrZLxKZ5xiCGpfc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gmUYP4NWio58be30lOOjMYE5Li37ls87Zycph2WvLvQ=; b=DjrmF+FBLa2Y3Iqxjmnpj7VA8MS9CP16YevoriVITXo2oiRIM71frI59GLRIRXfX54 asuEijuHwF2Evg8wfIjnBfeJwQhg6RAtnN+ZoMDm9vrSd4nGGDoEMddfRN1b2ZHUk1+m RHFVy5eievrM5/xy5oVaJtnJnAEPn38jOsqVA+3I/M30muu8aRxYE1R8brqMQ3oGMSyk Kdt5d1ulRuuL06g1MZwHwItLacA8PJxXOix8oM6MBjVC1zf+HRhwAa8Y6cVGSskIxq+C JfckHlVr9qneue9/OZblogrVyk6TAreHD1RaewqYBT3SIUWrqhq2RKAzMy77vmqY6agn Lqdg== X-Gm-Message-State: APt69E2qt/2XltQu5iP8TvUKvDJFLx75XYzkbrkut7bsw3YOIDgsWavu Pww6Zm4lb222R0H9eNokFHg0Dg== X-Received: by 2002:adf:f112:: with SMTP id r18-v6mr14160765wro.134.1529423515150; Tue, 19 Jun 2018 08:51:55 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id b14-v6sm11425wrn.57.2018.06.19.08.51.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jun 2018 08:51:50 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1EA873E1139; Tue, 19 Jun 2018 16:44:40 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Tue, 19 Jun 2018 16:44:31 +0100 Message-Id: <20180619154435.18898-53-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180619154435.18898-1-alex.bennee@linaro.org> References: <20180619154435.18898-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::230 Subject: [Qemu-devel] [PULL 52/56] docker: docker.py add check sub-command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: agraf@suse.de, =?utf-8?q?Alex_Benn=C3=A9e?= , richard.henderson@linaro.org, qemu-devel@nongnu.org, f4bug@amsat.org, cota@braap.org, famz@redhat.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This command allows you to check if we need to re-build a docker image. If the image isn't in the repository or the checksums don't match then we return false and some text (for processing in makefiles). Signed-off-by: Alex Bennée --- - fix prints to be "modern" - PEP8 fixes - split inspect into function -- 2.17.1 diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 0a0155c941..770b22424b 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -181,8 +181,14 @@ class Docker(object): stderr=subprocess.STDOUT, **kwargs) + def inspect_tag(self, tag): + try: + return self._output(["inspect", tag]) + except subprocess.CalledProcessError: + return None + def get_image_dockerfile_checksum(self, tag): - resp = self._output(["inspect", tag]) + resp = self.inspect_tag(tag) labels = json.loads(resp)[0]["Config"].get("Labels", {}) return labels.get("com.qemu.dockerfile-checksum", "") @@ -444,6 +450,36 @@ class CcCommand(SubCommand): return Docker().command("run", cmd, args.quiet) +class CheckCommand(SubCommand): + """Check if we need to re-build a docker image out of a dockerfile. + Arguments: """ + name = "check" + + def args(self, parser): + parser.add_argument("tag", + help="Image Tag") + parser.add_argument("dockerfile", + help="Dockerfile name") + + def run(self, args, argv): + dockerfile = open(args.dockerfile, "rb").read() + tag = args.tag + + dkr = Docker() + info = dkr.inspect_tag(tag) + if info is None: + print("Image does not exist") + return 1 + + if dkr.image_matches_dockerfile(tag, dockerfile): + if not args.quiet: + print("Image is up to date") + return 0 + else: + print("Image needs updating") + return 1 + + def main(): parser = argparse.ArgumentParser(description="A Docker helper", usage="%s ..." % os.path.basename(sys.argv[0]))