-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathsetup_gitlab_docker.py
39 lines (32 loc) · 1.21 KB
/
setup_gitlab_docker.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
import json
import os
import subprocess
import sys
stderr = 'Login was not attempted'
env_var = 'GITLAB_SECRET_FILE_QUAY_CREDENTIALS'
try:
if env_var not in os.environ:
print('Error: could not find environment variable ' + env_var)
sys.exit(1)
filename = os.environ[env_var]
if not os.path.exists(filename):
print('Error: could not find file referenced by ' + env_var)
sys.exit(1)
print('Opening key file...')
with open(filename, 'r') as cred_json_file:
print('Reading keys...')
keys = json.loads(cred_json_file.read())
print('Read and decoded keys')
print('Starting login process...')
process = subprocess.Popen('docker login quay.io -u "{user}" --password-stdin'.format(user=keys['user']),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE,
shell=True)
print('Logging in...')
stdout, stderr = process.communicate(input=keys['password'])
if 'Login Succeeded' in stdout:
print('Login Succeeded')
else:
raise RuntimeError
except:
print('Error while attempting to log into quay.io:\n' + str(stderr))
sys.exit(1)