11"""
22Script that automates trusted pull/pushes on different docker versions.
3+
4+ Usage: python buildscripts/dockertest.py
5+
6+ - assumes that this is run from the root notary directory
7+ - assumes that bin/client already exists
8+ - assumes you are logged in with docker
9+
10+ - environment variables to provide:
11+ - DEBUG=true - produce debug output
12+ - DOCKER_CONTENT_TRUST_SERVER=<notary server url> test against a non-local
13+ notary server
14+ - NOTARY_SERVER_USERNAME=<username> login creds username to notary server
15+ - NOTARY_SERVER_PASSPHRASE=<passwd> login creds password to notary server
16+ - DOCKER_USERNAME=<username> docker hub login username
317"""
418
519from __future__ import print_function
3347 "1.12" : ("https://get.docker.com" , "docker-1.12.1" ),
3448}
3549
36- NOTARY_VERSION = "0.3.0 " # only version that will work with docker < 1.13
50+ NOTARY_VERSION = "0.4.1 " # only version that will work with docker < 1.13
3751NOTARY_BINARY = "bin/notary"
3852
3953# please replace with private registry if you want to test against a private
@@ -131,7 +145,7 @@ def download_docker(download_dir="/tmp"):
131145
132146def verify_notary ():
133147 """
134- Check that notary is hte right version
148+ Check that notary is the right version
135149 """
136150 if not os .path .isfile (NOTARY_BINARY ):
137151 raise Exception ("notary client does not exist: " + NOTARY_BINARY )
@@ -247,15 +261,23 @@ def clear_keys():
247261 raise
248262
249263
250- def run_cmd (cmd , fileoutput ):
264+ def run_cmd (cmd , fileoutput , input = None ):
251265 """
252266 Takes a string command, runs it, and returns the output even if it fails.
253267 """
254268 print ("$ " + cmd )
255269 fileoutput .write ("$ {cmd}\n " .format (cmd = cmd ))
256270
257- process = subprocess .Popen (cmd .split (), env = _ENV , stderr = subprocess .STDOUT ,
258- stdout = subprocess .PIPE )
271+ if input is not None :
272+ process = subprocess .Popen (
273+ cmd .split (), env = _ENV , stderr = subprocess .STDOUT ,
274+ stdin = subprocess .PIPE , stdout = subprocess .PIPE )
275+
276+ process .stdin .write (input )
277+ process .stdin .close ()
278+ else :
279+ process = subprocess .Popen (cmd .split (), env = _ENV , stderr = subprocess .STDOUT ,
280+ stdout = subprocess .PIPE )
259281 output = ""
260282 while process .poll () is None :
261283 line = process .stdout .readline ()
@@ -343,6 +365,18 @@ def push(fout, docker_version, image, tag):
343365 return sha , size
344366
345367
368+ def get_notary_usernamepass ():
369+ """
370+ Gets the username password for the notary server
371+ """
372+ username = os .getenv ("NOTARY_SERVER_USERNAME" )
373+ passwd = os .getenv ("NOTARY_SERVER_PASSPHRASE" )
374+
375+ if username and passwd :
376+ return username + "\n " + passwd + "\n "
377+ return None
378+
379+
346380def notary_list (fout , repo ):
347381 """
348382 Calls notary list on the repo and returns a list of lists of tags, shas,
@@ -352,7 +386,7 @@ def notary_list(fout, repo):
352386 output = run_cmd (
353387 "{notary}{debug} -d {trustdir} list {gun}" .format (
354388 notary = NOTARY_CLIENT , trustdir = _TRUST_DIR , gun = repo , debug = DEBUG ),
355- fout )
389+ fout , input = get_notary_usernamepass () )
356390 lines = output .strip ().split ("\n " )
357391 assert len (lines ) >= 3 , "not enough targets"
358392 return [line .strip ().split () for line in lines [2 :]]
@@ -552,11 +586,11 @@ def rotate_to_server_snapshot(fout, image):
552586 run_cmd (
553587 "{notary}{debug} -d {trustdir} key rotate {gun} snapshot -r" .format (
554588 notary = NOTARY_CLIENT , trustdir = _TRUST_DIR , gun = image , debug = DEBUG ),
555- fout )
589+ fout , input = get_notary_usernamepass () )
556590 run_cmd (
557591 "{notary}{debug} -d {trustdir} publish {gun}" .format (
558592 notary = NOTARY_CLIENT , trustdir = _TRUST_DIR , gun = image , debug = DEBUG ),
559- fout )
593+ fout , input = get_notary_usernamepass () )
560594
561595
562596def test_all_docker_versions ():
0 commit comments