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: 139475 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1688644lji; Wed, 20 Jun 2018 23:48:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKISA8YUZE7X5MoQVwUBUtPOxdptB8RwP8aXb0rT95mcvVeBDP6EVnvNrIBHtsZykqwNYzQs X-Received: by 2002:a37:6945:: with SMTP id e66-v6mr19937019qkc.305.1529563736922; Wed, 20 Jun 2018 23:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529563736; cv=none; d=google.com; s=arc-20160816; b=qDYPReRZOnu6zK1MoUVS1ENAwlMEm5q4QlMXYSR9Dxsq6pr6WP7gesmNzXxzJkrGVe B/BOaZdM0v0hvGlSrvgUpQj0tJfrJ/Uo0iHbivBbFexEkexPMBmMXnZteNpAZYDCQ8My u319nK30k9bP9go0noYc4CSkJ7HeEZjR3L9QUL7IUHE8nSV5zkbnEiBYOXyKVhJ4t+T1 ealcUsBJsvOZoe/1Vq0pgXE5Vz0f7dJ6z6rV4WIhGc18F+wG/W4Pm0bIA+h/NqrIybxc JRzjT59o8QBjSaWf73GtMF8HZeZw+u1WLZ1GX+gbts2tn8gQ4mZmZHBTb7KDGEvQ/Up+ a/JA== 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=/D1lEdDMUENcePAfJtOpRjbpTAdwBnoDIQPNOds7Bfs=; b=sscZ05Z3rlXI+vO3Ec+6Dz5jIkft6zmhvNroqUzaH4w2jKP8vhCUYnyOMS+23pRVW7 ibNLVqKBU5wDgRRzk20gzaExjEW/7/cK1vG6mMS38gYKXq5DXM+gAmrbgL2fg18Ik8Ym ZneeYthGESJjZw4/NOOjgdfZs3D3D3PZVg7+fR/Fan7ge+Mbe4XN1ViFfVeOqWTd8t5G 1Imneza3pHO6BmlGBKc716acyg7gFCC1bp4CvRPnInQuHzc/CN3mWy4NsD/Vkz2NMDtv 6ZMiOPv5qr4FcbMexq5Exdb1R8pjl5CKFKyc1sa2RhtBVy62Q7zNw3RoUIMGXjOf1QJr uR7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=U9qpsMgK; 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 u42-v6si4176588qtu.18.2018.06.20.23.48.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Jun 2018 23:48:56 -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=U9qpsMgK; 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]:53357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVtOq-00029W-C0 for patch@linaro.org; Thu, 21 Jun 2018 02:48:56 -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-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+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 -- 2.17.1 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]))