Skip to content

Commit

Permalink
Merge pull request #38 from cancervariants/codebuild
Browse files Browse the repository at this point in the history
Add codebuild files
  • Loading branch information
korikuzma authored Mar 29, 2021
2 parents bb4cee4 + b9a028d commit 06e1526
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
52 changes: 52 additions & 0 deletions codebuild/deploy_eb_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Module for deploying staging EB environment."""
import boto3
import time

elasticbeanstalk = boto3.client('elasticbeanstalk')
servicecatalog = boto3.client('servicecatalog')
terminate_time = 12
eb_app_name = "GeneNormalization"
eb_env_name = "GeneNormalization-staging-env"
sc_product_id = "prod-mmw6ymv2ntzl2"
print(f'Launching new Service Catalog Product for staging environment:'
f' {eb_app_name}')
sc_product_artifacts = \
servicecatalog.list_provisioning_artifacts(ProductId=sc_product_id)
for artifact in sc_product_artifacts['ProvisioningArtifactDetails']:
if artifact['Active']:
provisioning_artifact_id = artifact['Id']
try:
eb_provisioned_product = servicecatalog.provision_product(
ProductId=sc_product_id,
ProvisioningArtifactId=provisioning_artifact_id,
ProvisionedProductName=eb_env_name,
ProvisioningParameters=[
{
'Key': 'Env',
'Value': eb_app_name
},
{
'Key': 'EnvType',
'Value': 'staging'
},
{
'Key': 'TerminateTime',
'Value': str(terminate_time)
}
]
)
eb_provisioned_product_Id = \
eb_provisioned_product['RecordDetail']['ProvisionedProductId']
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
while eb_provisioned_product_status == "UNDER_CHANGE":
time.sleep(10)
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
print(eb_provisioned_product_status)
except: # noqa: E722
print("The EB environment is already running...")
30 changes: 30 additions & 0 deletions codebuild/terminate_eb_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Module for terminating staging EB environment."""
import boto3
import json
import time

client = boto3.client('lambda')
servicecatalog = boto3.client('servicecatalog')
eb_env_name = "GeneNormalization-staging-env"
data = {"sc_provisioned_name": eb_env_name}
client.invoke(FunctionName='igm-inf-terminate-provisioned-product',
Payload=json.dumps(data))
time.sleep(10)
provisioned_product = \
servicecatalog.describe_provisioned_product(Name=eb_env_name)
eb_provisioned_product_Id =\
provisioned_product['ProvisionedProductDetail']['Id']
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status =\
product_status['ProvisionedProductDetail']['Status']
while eb_provisioned_product_status == "UNDER_CHANGE":
time.sleep(10)
try:
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
except: # noqa: E722
eb_provisioned_product_status = "PRODUCT NOT FOUND"
print(eb_provisioned_product_status)

0 comments on commit 06e1526

Please sign in to comment.