#!/usr/bin/env python3
import subprocess
import re
namespace = 'my-namespace'
secret_name = 'ecr-credeintial'
aws_region = 'ap-northeast-1'
docker_server = 'https://000000000000.dkr.ecr.ap-northeast-1.amazonaws.com'
def main():
output = subprocess.check_output([
'aws', 'ecr', 'get-login',
'--no-include-email', '--region', aws_region,
]).decode()
words = output.split()
username = words[words.index('-u') + 1]
password = words[words.index('-p') + 1]
subprocess.run([
'kubectl', '-n', namespace, 'delete', 'secret', secret_name])
subprocess.run([
'kubectl', '-n', namespace, 'create', 'secret',
'docker-registry', secret_name,
f'--docker-username={username}',
f'--docker-password={password}',
f'--docker-server={docker_server}'
])
if __name__ == '__main__':
main()
コメント