|
33 | 33 |
|
34 | 34 | import argparse |
35 | 35 | import itertools |
36 | | -import json |
37 | 36 | import os |
38 | 37 | import subprocess |
39 | 38 |
|
40 | | -from ssl import SSLContext |
41 | | -from typing import BinaryIO, Optional, Sequence, TextIO |
42 | | -from urllib.request import urlopen, Request |
| 39 | +from typing import BinaryIO, Optional, Sequence |
| 40 | +from urllib.request import urlopen |
43 | 41 |
|
44 | 42 |
|
45 | 43 | def calculate_tags(ref: str) -> Sequence[str]: |
@@ -97,47 +95,6 @@ def docker_cli_login(username: str, password: str): |
97 | 95 | ) |
98 | 96 |
|
99 | 97 |
|
100 | | -class DockerHub: |
101 | | - context: SSLContext |
102 | | - token: str |
103 | | - |
104 | | - @staticmethod |
105 | | - def login(username: str, password: str) -> DockerHub: |
106 | | - context = SSLContext() |
107 | | - context.load_default_certs() |
108 | | - |
109 | | - with urlopen( |
110 | | - Request( |
111 | | - "https://hub.docker.com/v2/users/login", |
112 | | - method="POST", |
113 | | - data=json.dumps({"username": username, "password": password}).encode( |
114 | | - "utf-8" |
115 | | - ), |
116 | | - headers={"Content-Type": "application/json; charset=utf-8"}, |
117 | | - ), |
118 | | - context=context, |
119 | | - ) as resp: |
120 | | - hub = DockerHub() |
121 | | - hub.context = context |
122 | | - hub.token = json.load(resp)["token"] |
123 | | - |
124 | | - return hub |
125 | | - |
126 | | - def update_description(self, image: str, file: TextIO) -> None: |
127 | | - urlopen( |
128 | | - Request( |
129 | | - f"https://hub.docker.com/v2/repositories/{image}/", |
130 | | - method="PATCH", |
131 | | - data=json.dumps({"full_description": file.read()}).encode("utf-8"), |
132 | | - headers={ |
133 | | - "Content-Type": "application/json; charset=utf-8", |
134 | | - "Authorization": f"JWT {self.token}", |
135 | | - }, |
136 | | - ), |
137 | | - context=self.context, |
138 | | - ) |
139 | | - |
140 | | - |
141 | 98 | def run(args: Sequence[str], /, **kwargs) -> subprocess.CompletedProcess: |
142 | 99 | print(f"+ {' '.join(args)}") |
143 | 100 | return subprocess.run(args, check=True, **kwargs) |
@@ -180,12 +137,6 @@ def main(): |
180 | 137 | print("building and pushing image") |
181 | 138 | docker_cli_build(open(args.dockerfile, "rb"), args.platform, args.image, tags) |
182 | 139 |
|
183 | | - print("acquiring token to update description") |
184 | | - hub = DockerHub.login(os.environ["DOCKER_USERNAME"], os.environ["DOCKER_PASSWORD"]) |
185 | | - |
186 | | - print("updating description") |
187 | | - hub.update_description(args.image, open(args.readme, "r")) |
188 | | - |
189 | 140 | print("success!") |
190 | 141 |
|
191 | 142 |
|
|
0 commit comments