-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from alliance-genome/API-deployment-KANBAN-558
added API infra and deployment (KANBAN-558)
- Loading branch information
Showing
28 changed files
with
776 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
option_settings: | ||
aws:ec2:instances: | ||
InstanceTypes: t2.micro | ||
aws:autoscaling:asg: | ||
Availability Zones: Any | ||
MinSize: 1 | ||
MaxSize: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
option_settings: | ||
aws:ec2:vpc: | ||
AssociatePublicIpAddress: false | ||
Subnets: | ||
- subnet-0d4703177afb1797d | ||
- subnet-04262fc338f638054 | ||
- subnet-044457c061edf85f2 | ||
- subnet-04019d42d5c9e6fb9 | ||
- subnet-049778993fb504a7c | ||
ELBSubnets: | ||
- subnet-0d4703177afb1797d | ||
- subnet-04262fc338f638054 | ||
- subnet-044457c061edf85f2 | ||
- subnet-04019d42d5c9e6fb9 | ||
- subnet-049778993fb504a7c | ||
VPCId: vpc-55522232 | ||
ELBScheme: internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
files: | ||
"/opt/aws/amazon-cloudwatch-agent/bin/config.json": | ||
mode: "000600" | ||
owner: root | ||
group: root | ||
content: | | ||
{ | ||
"agent": { | ||
"metrics_collection_interval": 60, | ||
"run_as_user": "root" | ||
}, | ||
"metrics": { | ||
"namespace": "PAVI/ApiServer", | ||
"append_dimensions": { | ||
"AutoScalingGroupName": "${aws:AutoScalingGroupName}", | ||
"InstanceId": "${aws:InstanceId}", | ||
"InstanceType": "${aws:InstanceType}" | ||
}, | ||
"metrics_collected": { | ||
"cpu": { | ||
"totalcpu": true, | ||
"measurement": [ | ||
"usage_active", | ||
"usage_idle", | ||
"usage_iowait", | ||
"usage_guest", | ||
"usage_system", | ||
"usage_user" | ||
] | ||
}, | ||
"disk": { | ||
"ignore_file_system_types": [ | ||
"tmpfs", | ||
"devtmpfs" | ||
], | ||
"measurement": [ | ||
"free", | ||
"used", | ||
"used_percent", | ||
"inodes_used", | ||
"inodes_free" | ||
] | ||
}, | ||
"diskio": { | ||
"measurement": [ | ||
"reads", | ||
"writes", | ||
"read_bytes", | ||
"write_bytes", | ||
"iops_in_progress" | ||
] | ||
}, | ||
"mem": { | ||
"measurement": [ | ||
"available", | ||
"available_percent", | ||
"free", | ||
"used", | ||
"used_percent" | ||
] | ||
}, | ||
"swap": { | ||
"measurement": [ | ||
"free", | ||
"used", | ||
"used_percent" | ||
] | ||
}, | ||
"net": { | ||
"resources": ["eth0", "docker0"], | ||
"measurement": [ | ||
"bytes_sent", | ||
"bytes_recv", | ||
"drop_in", | ||
"drop_out", | ||
"err_in", | ||
"err_out" | ||
] | ||
}, | ||
"processes": { | ||
"measurement": [ | ||
"blocked", | ||
"dead", | ||
"paging", | ||
"running", | ||
"sleeping", | ||
"wait", | ||
"zombies", | ||
"total", | ||
"total_threads" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
container_commands: | ||
start_cloudwatch_agent: | ||
command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
option_settings: | ||
aws:elasticbeanstalk:managedactions: | ||
ManagedActionsEnabled: true | ||
PreferredStartTime: "Tue:02:00" | ||
aws:elasticbeanstalk:managedactions:platformupdate: | ||
UpdateLevel: minor | ||
InstanceRefreshEnabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Resources: | ||
AWSEBV2LoadBalancerListener: | ||
Type: 'AWS::ElasticLoadBalancingV2::Listener' | ||
Properties: | ||
DefaultActions: | ||
- Type: redirect | ||
RedirectConfig: | ||
Protocol: HTTPS | ||
Port: '443' | ||
Host: '#{host}' | ||
Path: '/#{path}' | ||
Query: '#{query}' | ||
StatusCode: HTTP_301 | ||
LoadBalancerArn: | ||
Ref: AWSEBV2LoadBalancer | ||
Port: 80 | ||
Protocol: HTTP | ||
option_settings: | ||
# As noted in the AWS docs, the following option cannot be set through the .ebextensions configuration files, | ||
# and thus is defined directly in the CDK definitions (see parent directory). | ||
# | ||
# aws:elasticbeanstalk:environment: | ||
# LoadBalancerType: application | ||
# | ||
# https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-alb.html#environments-cfg-alb-namespaces | ||
|
||
aws:elbv2:listener:443: | ||
SSLCertificateArns: arn:aws:acm:us-east-1:100225593120:certificate/047a56a2-09dd-4857-9f28-32d23650d4da | ||
Protocol: HTTPS | ||
DefaultProcess: api | ||
aws:elasticbeanstalk:environment:process:api: | ||
Port: '8080' | ||
Protocol: HTTP | ||
aws:elbv2:loadbalancer: | ||
IdleTimeout: 600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import click | ||
from os import listdir, path | ||
from zipfile import ZipFile | ||
|
||
from .eb.eb_app_version import eb_app_version_exists, create_eb_app_version | ||
from .s3.eb_assets import upload_application_bundle | ||
|
||
|
||
@click.command(context_settings={'show_default': True}) | ||
@click.option("--eb_app_name", type=click.STRING, required=True, | ||
help="The Elasticbeanstalk application name to deploy a new version for.") | ||
@click.option("--version_label", type=click.STRING, required=True, | ||
help="The version label to assign to the EB application version.") | ||
def main(eb_app_name: str, version_label: str) -> None: | ||
""" | ||
Main method to deploy EB application versions. Receives input args from click. | ||
Checks if an EB application version already exists with the defined version_label, | ||
and deploys the current working directory as a new application version with that label if not. | ||
""" | ||
## Search EB application version by label | ||
## Note: EB application version management is done external to CDK, | ||
## as Cloudformation/CDK does not support custom labels at current (2024/05/17). | ||
if not eb_app_version_exists(eb_app_name=eb_app_name, version_label=version_label): | ||
print(f'Creating new application version with label "{version_label}".') | ||
# Create app zip | ||
dir_path = path.dirname(path.realpath(__file__)) | ||
app_zip_path = 'eb_app.zip' | ||
with ZipFile(app_zip_path, 'w') as zipObj: | ||
## Add docker-compose file | ||
docker_compose_file = f'{dir_path}/../../docker-compose.yml' | ||
zipObj.write(docker_compose_file, path.basename(path.normpath(docker_compose_file))) | ||
|
||
## Add all files in .ebextensions/ | ||
ebextensions_path = f'{dir_path}/../.ebextensions/' | ||
for filename in listdir(ebextensions_path): | ||
full_file_path = path.join(ebextensions_path, filename) | ||
if path.isfile(full_file_path): | ||
zipObj.write(full_file_path, path.join('.ebextensions/', filename)) | ||
|
||
# Upload app zip as s3 source bundle | ||
source_bundle = upload_application_bundle( | ||
eb_app_name=eb_app_name, | ||
version_label=version_label, | ||
bundle_path=app_zip_path) | ||
|
||
# Create new application version with label | ||
create_eb_app_version( | ||
eb_app_name=eb_app_name, version_label=version_label, | ||
source_bundle=source_bundle, | ||
tags=[{'Key': 'Product', 'Value': 'PAVI'}, | ||
{'Key': 'Managed_by', 'Value': 'PAVI'}]) | ||
else: | ||
print(f'Application version with label "{version_label}" already exists.') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
Oops, something went wrong.