Skip to content

Commit

Permalink
Merge pull request #2 from DNXLabs/improvement/code_improvements_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
brunodasilvalenga authored Mar 29, 2022
2 parents 33a702f + 7660900 commit 417e412
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 26 deletions.
6 changes: 1 addition & 5 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ENV

AWS_ACCESS_KEY_ID
AWS_SESSION_TOKEN
AWS_SECRET_ACCESS_KEY
Expand All @@ -11,6 +9,4 @@ AWS_ROLE
BLUE_ENV_NAME
GREEN_ENV_NAME
BEANSTALK_APP_NAME
CREATE_CONFIG_TEMPLATE_NAME
BLUE_CNAME_CONFIG_FILE
ARTIFACTS_S3_BUCKET
S3_ARTIFACTS_BUCKET
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
.env.assume
.env.local
.DS_Store
__pycache__
__pycache__
blue_cname.json
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ AWS_SESSION_TOKEN
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION

ENV
BLUE_ENV_NAME
GREEN_ENV_NAME
BEANSTALK_APP_NAME
CREATE_CONFIG_TEMPLATE_NAME
BLUE_CNAME_CONFIG_FILE
ARTIFACTS_S3_BUCKET

S3_ARTIFACTS_BUCKET
S3_ARTIFACTS_OBJECT
```

#### Optional Variables
Expand Down
6 changes: 2 additions & 4 deletions blue_green_assets/clone_blue_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def main():
BLUE_ENV_NAME = os.getenv('BLUE_ENV_NAME')
GREEN_ENV_NAME = os.getenv('GREEN_ENV_NAME')
BEANSTALK_APP_NAME = os.getenv('BEANSTALK_APP_NAME')
CREATE_CONFIG_TEMPLATE_NAME = os.getenv('CREATE_CONFIG_TEMPLATE_NAME')
BLUE_CNAME_CONFIG_FILE = os.getenv('BLUE_CNAME_CONFIG_FILE')
CREATE_CONFIG_TEMPLATE_NAME = "BlueEnvConfig"
BLUE_CNAME_CONFIG_FILE = "blue_cname.json"
beanstalkclient = boto3.client('elasticbeanstalk',region_name='ap-southeast-2')
try:
BlueEnvInfo=GetBlueEnvInfo(beanstalkclient, BLUE_ENV_NAME)
Expand Down Expand Up @@ -61,7 +61,6 @@ def GetBlueEnvInfo(beanstalkclient, EnvName):
EnvironmentNames=[
EnvName
])
print("Described the environment")
return response

def CreateGreenEnvironment(beanstalkclient, EnvName,ConfigTemplate,AppVersion,AppName):
Expand Down Expand Up @@ -93,7 +92,6 @@ def get_green_env_info(beanstalkclient, EnvName):
EnvironmentNames=[
EnvName
])
print("Described the environment")
return response

def timeout(event):
Expand Down
10 changes: 5 additions & 5 deletions blue_green_assets/deploy_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

def main():
VERSION_LABEL = strftime("%Y%m%d%H%M%S")
BUCKET_KEY = os.getenv('ENV') + '/deployment/DeploymentPackage.zip'
ARTIFACTS_S3_BUCKET=os.getenv('ARTIFACTS_S3_BUCKET')
BUCKET_KEY = os.getenv('S3_ARTIFACTS_OBJECT')
S3_ARTIFACTS_BUCKET=os.getenv('S3_ARTIFACTS_BUCKET')
BLUE_ENV_NAME = os.getenv("BLUE_ENV_NAME")
BEANSTALK_APP_NAME = os.getenv("BEANSTALK_APP_NAME")

if not create_new_version(VERSION_LABEL, BUCKET_KEY, ARTIFACTS_S3_BUCKET, BEANSTALK_APP_NAME):
if not create_new_version(VERSION_LABEL, BUCKET_KEY, S3_ARTIFACTS_BUCKET, BEANSTALK_APP_NAME):
raise Exception("Create new version.")
# Wait for the new version to be consistent before deploying
sleep(5)
Expand All @@ -21,7 +21,7 @@ def main():



def create_new_version(VERSION_LABEL, BUCKET_KEY, ARTIFACTS_S3_BUCKET, BEANSTALK_APP_NAME):
def create_new_version(VERSION_LABEL, BUCKET_KEY, S3_ARTIFACTS_BUCKET, BEANSTALK_APP_NAME):
"""
Creates a new application version in AWS Elastic Beanstalk
"""
Expand All @@ -37,7 +37,7 @@ def create_new_version(VERSION_LABEL, BUCKET_KEY, ARTIFACTS_S3_BUCKET, BEANSTALK
VersionLabel=VERSION_LABEL,
Description='New release azure devops',
SourceBundle={
'S3Bucket': ARTIFACTS_S3_BUCKET,
'S3Bucket': S3_ARTIFACTS_BUCKET,
'S3Key': BUCKET_KEY
},
Process=True
Expand Down
5 changes: 1 addition & 4 deletions blue_green_assets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def main():

if __name__ == "__main__":
try:
ENV = os.getenv("ENV")
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SESSION_TOKEN = os.getenv("AWS_SESSION_TOKEN")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
Expand All @@ -92,9 +91,7 @@ def main():
BLUE_ENV_NAME = os.getenv("BLUE_ENV_NAME")
GREEN_ENV_NAME = os.getenv("GREEN_ENV_NAME")
BEANSTALK_APP_NAME = os.getenv("BEANSTALK_APP_NAME")
CREATE_CONFIG_TEMPLATE_NAME = os.getenv("CREATE_CONFIG_TEMPLATE_NAME")
BLUE_CNAME_CONFIG_FILE = os.getenv("BLUE_CNAME_CONFIG_FILE")
ARTIFACTS_S3_BUCKET=os.getenv('ARTIFACTS_S3_BUCKET')
S3_ARTIFACTS_BUCKET=os.getenv('S3_ARTIFACTS_BUCKET')
print(colored("Successfully get envs", "green"))
except Exception as e:
print("Failed to get environment variable")
Expand Down
2 changes: 1 addition & 1 deletion blue_green_assets/swap_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def main():
beanstalkclient = boto3.client("elasticbeanstalk",region_name="ap-southeast-2")

BLUE_CNAME_CONFIG_FILE = os.getenv("BLUE_CNAME_CONFIG_FILE")
BLUE_CNAME_CONFIG_FILE = "blue_cname.json"
BLUE_ENV_NAME = os.getenv("BLUE_ENV_NAME")
GREEN_ENV_NAME = os.getenv("GREEN_ENV_NAME")

Expand Down
2 changes: 1 addition & 1 deletion blue_green_assets/terminate_green_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def main():
BLUE_ENV_NAME = os.getenv("BLUE_ENV_NAME")
GREEN_ENV_NAME = os.getenv("GREEN_ENV_NAME")
BEANSTALK_APP_NAME = os.getenv("BEANSTALK_APP_NAME")
CREATE_CONFIG_TEMPLATE_NAME = os.getenv("CREATE_CONFIG_TEMPLATE_NAME")
CREATE_CONFIG_TEMPLATE_NAME = "BlueEnvConfig"

beanstalkclient = boto3.client('elasticbeanstalk',region_name='ap-southeast-2')
try:
Expand Down

0 comments on commit 417e412

Please sign in to comment.