-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
95 lines (75 loc) · 3.33 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
AWS_REGION=us-east-1
export AWS_REGION
####
# IAM Role
# Create a new IAM role for ECS tasks and attach the
# AmazonECSTaskExecutionRolePolicy policy to it.
####
aws iam create-role \
--role-name ecsTaskExecutionRole \
--assume-role-policy-document file://ecs-tasks-trust-policy.json
aws iam attach-role-policy \
--role-name ecsTaskExecutionRole \
--policy-arn arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
####
# ONLY NEEDED IF YOU ARE USING SPOT INSTANCES
#
# # Create another role for AWS Batch to create the Spot Fleet
# aws iam create-service-linked-role --aws-service-name spotfleet.amazonaws.com
####
# Setup the AWS Batch Job Queue and Compute Environment
####
VPC_ID=$(aws ec2 describe-vpcs --output text --query 'Vpcs[*].VpcId' \
--filters Name=isDefault,Values=true --region ${AWS_REGION})
SUBNET_IDS=$(aws ec2 describe-subnets --query "Subnets[*].SubnetId" \
--filters Name=vpc-id,Values="${VPC_ID}" --region ${AWS_REGION} \
--output text | sed 's/\s\+/,/g')
EC2_SPOT_ROLE=$(aws iam get-role --role-name AWSServiceRoleForEC2SpotFleet | jq -r '.Role.Arn')
BATCH_BASE_NAME="nf-main-head"
echo "VPC_ID: ${VPC_ID}"
echo "SUBNET_IDS: ${SUBNET_IDS}"
echo "EC2_SPOT_ROLE: ${EC2_SPOT_ROLE}"
SSH_KEY_NAME="${BATCH_BASE_NAME}-key"
aws ec2 create-key-pair --key-name "${SSH_KEY_NAME}" --region ${AWS_REGION} \
--query 'KeyMaterial' --output text > "${BATCH_BASE_NAME}.pem"
aws cloudformation deploy --stack-name "nf-${BATCH_BASE_NAME}-ce-jq" \
--template-file nextflow-batch-ce-jq.template.yaml \
--capabilities CAPABILITY_IAM --region ${AWS_REGION} \
--parameter-overrides VpcId="${VPC_ID}" SubnetIds="${SUBNET_IDS}" \
BaseName="${BATCH_BASE_NAME}" SshKeyName="${SSH_KEY_NAME}"
####
# Setup the AWS Batch Job Definition for the Nextflow Head Node
####
# Create a Docker image for the HEAD node - that would run Nextflow
REPOSITORY_NAME="nextflow_head"
# Create a new ECR repository as a placeholder to push the Docker image
aws ecr create-repository --repository-name ${REPOSITORY_NAME}
IMAGE_ID=$(aws ecr describe-repositories --repository-names ${REPOSITORY_NAME} \
--output text --query 'repositories[0].[repositoryUri]' --region $AWS_REGION)
echo "IMAGE_ID: ${IMAGE_ID}"
docker build -t "${IMAGE_ID}:latest" nf_head_docker
# Push command to ECR
aws ecr get-login-password --region $AWS_REGION | \
docker login --username AWS --password-stdin "${IMAGE_ID}"
docker push "${IMAGE_ID}:latest"
ECS_ROLE_ARN=$(aws iam get-role --role-name ecsTaskExecutionRole \
--query 'Role.[Arn]' --output text)
echo "ECS_ROLE_ARN: ${ECS_ROLE_ARN}"
# NF Job Queue to submit Nextflow jobs to.
NF_JOB_QUEUE=${BATCH_BASE_NAME}-job-queue
aws cloudformation deploy --stack-name nf-${BATCH_BASE_NAME}-jd \
--template-file nextflow-batch-jd.template.yaml \
--capabilities CAPABILITY_IAM --region ${AWS_REGION} \
--parameter-overrides NFJobQueue=${NF_JOB_QUEUE} ImageId="${IMAGE_ID}" \
ECSRoleArn="${ECS_ROLE_ARN}" AWSRegion=${AWS_REGION} BaseName="${BATCH_BASE_NAME}"
####
#
####
# Submit a job
SUBMITTED_JOB=$(aws batch submit-job --job-name nextflow-job \
--job-queue "${BATCH_BASE_NAME}-job-queue" \
--job-definition "${BATCH_BASE_NAME}-job-definition" \
--region $AWS_REGION --cli-input-json file://sentieon.json)
JOB_ID=$(echo "${SUBMITTED_JOB}" | jq -r '.jobId')
aws batch describe-jobs --jobs "${JOB_ID}" --region $AWS_REGION