forked from Razikus/dockerregistrypusher
-
Notifications
You must be signed in to change notification settings - Fork 14
/
dockerregistrypusher.py
134 lines (108 loc) · 3.14 KB
/
dockerregistrypusher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import argparse
import sys
import core
import clients.logging
def run(args):
retval = 1
# plug in verbosity shorthands
if args.v:
args.log_severity = 'debug'
logger = clients.logging.Client(
'pusher',
initial_severity=args.log_severity,
initial_console_severity=args.log_console_severity,
initial_file_severity=args.log_file_severity,
output_stdout=not args.log_disable_stdout,
output_dir=args.log_output_dir,
max_log_size_mb=args.log_file_rotate_max_file_size,
max_num_log_files=args.log_file_rotate_num_files,
log_file_name=args.log_file_name,
log_colors=args.log_colors,
).logger
# initialize and start processing
processor = core.Processor(
logger=logger,
parallel=args.parallel,
registry_url=args.registry_url,
archive_path=args.archive_path,
stream=args.stream,
login=args.login,
password=args.password,
ssl_verify=args.ssl_verify,
replace_tags_match=args.replace_tags_match,
replace_tags_target=args.replace_tags_target,
)
processor.process()
if logger.first_error is None:
retval = 0
return retval
def register_arguments(parser):
# logger options
clients.logging.Client.register_arguments(parser)
# verbosity shorthands
parser.add_argument(
'-v',
'-verbose',
help='Set log level to debug (same as --log-severity=debug)',
action='store_true',
default=False,
)
parser.add_argument(
'-p',
'--parallel',
help='Control parallelism (threads)',
type=int,
default=1,
)
parser.add_argument(
'archive_path',
metavar='ARCHIVE_PATH',
type=str,
help='The url of the target registry to push to',
)
parser.add_argument(
'registry_url',
metavar='REGISTRY_URL',
type=str,
help='The url of the target registry to push to',
)
parser.add_argument(
'--login',
help='Basic-auth login name for registry',
required=False,
)
parser.add_argument(
'--password',
help='Basic-auth login password for registry',
required=False,
)
parser.add_argument(
'--ssl-verify',
help='Skip SSL verification of the registry',
type=bool,
default=True,
)
parser.add_argument(
'--stream',
help='Add some streaming logging during push',
type=bool,
default=True,
)
parser.add_argument(
'--replace-tags-match',
help='A regex string to match on tags. If matches will be replaces with --replace-tags-target',
type=str,
required=False,
)
parser.add_argument(
'--replace-tags-target',
help='If an image tag matches value of --replace-tags-match value, replace it with this tag',
type=str,
required=False,
)
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser()
register_arguments(arg_parser)
parsed_args = arg_parser.parse_args()
ret_val = run(parsed_args)
sys.exit(ret_val)