buildWarpApi

buildWarpApi

Steps to build Warp api container

CloudOps Standard CI/CD Model of building and promoting an ECS container

A) develop/hotfix branches ONLY 1) Build the container 2) Push the container to ECR (tag with git hash) 3) ECS deploy the container to branch (on success, deploy will tag with branch name) 4) Approval - Promote to next higher env up to master branch B) qa/stage/demo/prod/master branches 1) ECS deploy the container to branch (on success, deploy will tag with branch name) 4) Approval - Promote to next higher env up to master branch

 1#!/usr/bin/env python3
 2"""
 3buildWarpApi
 4
 5Steps to build Warp api container
 6
 7CloudOps Standard CI/CD Model of building and promoting an ECS container
 8
 9A) develop/hotfix branches ONLY
10    1) Build the container
11    2) Push the container to ECR (tag with git hash)
12    3) ECS deploy the container to branch (on success, deploy will tag with branch name)
13    4) Approval - Promote to next higher env up to master branch
14B) qa/stage/demo/prod/master branches
15    1) ECS deploy the container to branch (on success, deploy will tag with branch name)
16    4) Approval - Promote to next higher env up to master branch
17"""
18from utils import release, jdk, aws
19from utils.common import subprocess_long as _run
20import os
21
22if __name__ == "__main__":
23    print("buildWarpApi.__main__(): BEGIN")
24
25    APP_NAME = os.environ.get('APP_NAME', None)
26    BASE_IMAGE = os.environ.get('BASE_IMAGE', None)
27    ENV_NAME = os.environ.get('ENV_NAME', 'dev')
28
29    if APP_NAME is None or BASE_IMAGE is None:
30        print("buildWarpApi.__main__(): Error: APP_NAME and BASE_NAME are not set.")
31        raise Exception("variable issue")
32
33    print(f"buildWarpApi.__main__(): Pulling container ({BASE_IMAGE})")
34    _c, _t = aws.ecr_pull_from_build(container=BASE_IMAGE)
35    if not _c or not _t:
36        raise Exception("Failed to pull from build ECR.")
37
38    my_version = release.get_version()
39    print(f"buildWarpApi.__main__(): Version is {my_version}")
40
41    my_hash = release.get_commit_short_hash()
42    print(f"buildWarpApi.__main__(): commit short hash is {my_hash}")
43
44    print("buildWarpApi.__main__(): Installing jdk 17")
45    jdk.install_jdk_17_with_yum()
46
47    print("buildWarpApi.__main__(): Running gradlew")
48    _run("ls -latr")
49    _run("chmod 755 gradlew")
50
51    # _c, _t = aws.ecr_generate_fqcn(container=BASE_IMAGE)
52    output = _run(f"./gradlew clean build jibDockerBuild -DfromImage=docker://{_c}:{_t} -Denvironment={ENV_NAME} -Dtag={my_hash}", check=False, shell=True)
53    if output.returncode != 0:
54        print(f"buildWarpApi(): {output.stdout}")
55        print(f"buildWarpApi(): {output.stderr}")
56        print(f"buildWarpApi(): {str(output.returncode)}")
57        raise Exception("holy crap")
58        # sys.exit(0)
59
60    print("buildWarpApi.__main__(): Pushing container to build commercial ECR")
61    _c, _t = aws.ecr_generate_build_fqcn(container=APP_NAME)
62    aws.ecr_push_to_build(container=_c, tag=ENV_NAME, tag_list=[my_hash, my_version])