From patchwork Thu Jun 21 06:26:01 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: 932573 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="U9qpsMgK"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41BC0f1kg1z9s0W for ; Thu, 21 Jun 2018 16:46:42 +1000 (AEST) Received: from localhost ([::1]:53345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVtMd-0008Lh-RL for incoming@patchwork.ozlabs.org; Thu, 21 Jun 2018 02:46:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVt31-00013q-2G for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:26:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVt30-0000iQ-1b for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:26:23 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:37071) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVt2z-0000hr-RA for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:26:21 -0400 Received: by mail-wm0-x234.google.com with SMTP id r125-v6so3615564wmg.2 for ; Wed, 20 Jun 2018 23:26:21 -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=/D1lEdDMUENcePAfJtOpRjbpTAdwBnoDIQPNOds7Bfs=; b=U9qpsMgKCoMJZgUhXF6RohRCnBatgjPYsSIGrttC/gVZt/vYqfrEC/9fvZHPmNQjEv lXWHKChnvQmEWuEAb8z2244kP4aXuxP12/tBniPvnISPGV9ma0K51jh242WRNmTegRQf cx72Auv5ShqISJXZdNDOeYo6xkOEdRl4W0D2E= 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=/D1lEdDMUENcePAfJtOpRjbpTAdwBnoDIQPNOds7Bfs=; b=mOX2bREEKftNeg6nyqaxwCCPuGlSchNLAmT73L0IEz0Qc/aORjSav7bSsZZVPCabRA 8wr12PSUAcFoYDJRjxONbdaa6nRiJCbtbr0/xrkieIPdMPSq9mc9svzDZfQ+ge1UYO+p SWDNGc+sy/KDLzFCUmsHHzkw7/KtYRWhRd6uvvSsU85ZlNZw2TQLyEzGawhbCL4YYuR/ t7lgh+hYduKltSI1DUKS9jfn/OIohKJhZjUjfI2NWNqVvyHg9V5l6ygPu8JGtSs4lUIB k9f88EvjLMNGta9wmdBdHT98i4LtNPs1/rDkHGeunETDvkaNWxL+AI6mkul7KPS/2PON JVGg== X-Gm-Message-State: APt69E3dyunuHuY597aSnn6fdBdDUtuuUFxV+XgMuyBsYhkWx25/WmXa aTKycUOnfnsM1R3uGU4nNvlYWQ== X-Google-Smtp-Source: ADUXVKJr5ZlL/rlTuoGGcXgrik2X0VaWu7WMpDTY2yv5CqLLve+rUANcAKUU+hHRfu5U2yluEbuIgg== X-Received: by 2002:a1c:454f:: with SMTP id s76-v6mr3767140wma.16.1529562380862; Wed, 20 Jun 2018 23:26:20 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 11-v6sm4799994wmd.35.2018.06.20.23.26.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 23:26:17 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id D036E3E150F; Thu, 21 Jun 2018 07:26:09 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 21 Jun 2018 07:26:01 +0100 Message-Id: <20180621062605.941-54-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180621062605.941-1-alex.bennee@linaro.org> References: <20180621062605.941-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:c09::234 Subject: [Qemu-devel] [PULL v2 53/57] 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+incoming=patchwork.ozlabs.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 diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 6a9f2f224b..e4f37820e0 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -184,8 +184,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", "") @@ -447,6 +453,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]))