ecrTagAndPush
ecrTagAndPush
Pull, Tag and Push into ECR
container: String container name (i.e. warp/api)
tag: String tag (i.e. dev) Defaults to release.get_version()
newtag: String newtag (i.e. single tag "qa_rc" or colon separated list of tags "qa_rc:1.2.3:hello")
1#!/usr/bin/env python3 2""" 3ecrTagAndPush 4 5Pull, Tag and Push into ECR 6 7container: String container name (i.e. warp/api) 8tag: String tag (i.e. dev) Defaults to `release.get_version()` 9newtag: String newtag (i.e. single tag "qa_rc" or colon separated list of tags "qa_rc:1.2.3:hello") 10""" 11from utils import aws, release, common, docker 12import argparse 13import sys 14 15if __name__ == "__main__": 16 print("ecrTagAndPush(): BEGIN") 17 18 # 19 # ArgParse 20 # 21 parser = argparse.ArgumentParser(description='Pull, Tag and Push a container into ECR.') 22 parser.add_argument( 23 '-c', 24 '--container', 25 action='store', 26 type=str, 27 required=True, 28 help='container name') 29 30 parser.add_argument( 31 '-t', 32 '--tag', 33 action='store', 34 type=str, 35 required=False, 36 default=release.get_version(), 37 help='container existing tag to pull') 38 39 parser.add_argument( 40 '-n', 41 '--newtag', 42 action='store', 43 type=str, 44 required=True, 45 help='New tag(s) to push to container. separate with a colon (:)') 46 47 args = parser.parse_args() 48 49 _CONTAINER = common.resolve_gocd_pipeline_variable(args.container) 50 _TAG = common.resolve_gocd_pipeline_variable(args.tag) 51 _TAG_LIST = [common.resolve_gocd_pipeline_variable(args.newtag)] if ':' not in args.newtag else args.newtag.split(':') 52 53 print(f"ecrTagAndPush(): Pulling container ({_CONTAINER}:{_TAG})") 54 _c, _t = aws.ecr_pull_from_build(container=f"{_CONTAINER}:{_TAG}") 55 56 print(f"ecrTagAndPush(): Tagging container with {_TAG_LIST[0]}") 57 docker.tag(container=f"{_c}:{_t}", tag=_TAG_LIST[0]) 58 59 print("ecrTagAndPush(): Pushing container to build commercial ECR") 60 # _c, _t = aws.ecr_generate_fqcn(container=APP_NAME) 61 aws.ecr_push_to_build(container=_c, tag=_t, tag_list=_TAG_LIST) 62 63 sys.exit(0)