77import sys
88
99
10+ def save_to_s3 (project , data ):
11+ table_content = ""
12+ client = boto3 .client ("s3" )
13+ for repo , tag , window , age , pushed in data :
14+ table_content += f"<tr><td>{ repo } </td><td>{ tag } </td><td>{ window } </td><td>{ age } </td><td>{ pushed } </td></tr>"
15+ html_body = f"""
16+ <html>
17+ <head>
18+ <link rel="stylesheet"
19+ href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
20+ integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
21+ crossorigin="anonymous">
22+ <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
23+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
24+ <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>
25+ <title>{ project } nightly and permanent docker image info</title>
26+ </head>
27+ <body>
28+ <table class="table table-striped table-hover" id="docker">
29+ <thead class="thead-dark">
30+ <tr>
31+ <th scope="col">repo</th>
32+ <th scope="col">tag</th>
33+ <th scope="col">keep window</th>
34+ <th scope="col">age</th>
35+ <th scope="col">pushed at</th>
36+ </tr>
37+ </thead>
38+ <tbody>
39+ { table_content }
40+ </tbody>
41+ </table>
42+ </body>
43+ <script>
44+ $(document).ready( function () {{
45+ $('#docker').DataTable({{paging: false}});
46+ }} );
47+ </script>
48+ </html>
49+ """
50+
51+ # for pytorch, file can be found at
52+ # http://ossci-docker.s3-website.us-east-1.amazonaws.com/pytorch.html
53+ # and later one we can config docker.pytorch.org to point to the location
54+
55+ client .put_object (
56+ Bucket = "ossci-docker" ,
57+ ACL = "public-read" ,
58+ Key = f"{ project } .html" ,
59+ Body = html_body ,
60+ ContentType = "text/html" ,
61+ )
62+
63+
1064def repos (client ):
1165 paginator = client .get_paginator ("describe_repositories" )
1266 pages = paginator .paginate (registryId = "308535385114" )
@@ -89,29 +143,38 @@ def chunks(chunkable, n):
89143 yield chunkable [i : i + n ]
90144
91145
146+ stable_window_tags = []
92147for repo in repos (client ):
93148 repositoryName = repo ["repositoryName" ]
94149 if not repositoryName .startswith (args .filter_prefix ):
95150 continue
96151
97152 # Keep list of image digests to delete for this repository
98153 digest_to_delete = []
99-
100154 print (repositoryName )
155+
101156 for image in images (client , repo ):
102157 tags = image .get ("imageTags" )
103158 if not isinstance (tags , (list ,)) or len (tags ) == 0 :
104159 continue
105160
106161 tag = tags [0 ]
162+ created = image ["imagePushedAt" ]
163+ age = now - created
107164 # new images build on circle ci use workflow ID as tag, which has 4 "-"
108- if tag .isdigit () or tag .count ("-" ) == 4 :
165+ if tag .isdigit () or tag .count ("-" ) == 4 or tag in ignore_tags :
109166 window = stable_window
167+ if tag in ignore_tags :
168+ stable_window_tags .append ((repositoryName , tag , "" , age , created ))
169+ elif age < window :
170+ stable_window_tags .append ((repositoryName , tag , window , age , created ))
110171 else :
111172 window = unstable_window
112173
113- created = image ["imagePushedAt" ].replace (tzinfo = pytz .UTC )
114- age = now - created
174+ print (
175+ f"Debug: for tag: { tag } , keep window is { window } , age is { age } , pushed at { image ['imagePushedAt' ]} "
176+ )
177+
115178 if tag in ignore_tags :
116179 print ("Ignoring tag {} (age: {})" .format (tag , age ))
117180 continue
@@ -135,3 +198,5 @@ def chunks(chunkable, n):
135198 repositoryName = repositoryName ,
136199 imageIds = [{"imageDigest" : digest } for digest in c ],
137200 )
201+
202+ save_to_s3 (args .filter_prefix , stable_window_tags )
0 commit comments