|
a |
|
b/source/setup.sh |
|
|
1 |
#!/bin/bash -e |
|
|
2 |
|
|
|
3 |
export AWS_DEFAULT_OUTPUT=text |
|
|
4 |
|
|
|
5 |
create_stack() { |
|
|
6 |
local stack_name=${1} |
|
|
7 |
local template_name=${2} |
|
|
8 |
local ResourcePrefix=${3} |
|
|
9 |
|
|
|
10 |
local ResourcePrefix_lowercase=$(echo ${ResourcePrefix} | tr '[:upper:]' '[:lower:]') |
|
|
11 |
|
|
|
12 |
aws cloudformation create-stack --stack-name ${stack_name} --template-body file://${template_name} --parameters ParameterKey=ResourcePrefix,ParameterValue=${ResourcePrefix} ParameterKey=ResourcePrefixLowercase,ParameterValue=${ResourcePrefix_lowercase} --capabilities CAPABILITY_NAMED_IAM --no-enable-termination-protection; aws cloudformation wait stack-create-complete --stack-name ${stack_name} |
|
|
13 |
} |
|
|
14 |
|
|
|
15 |
clone_and_commit() { |
|
|
16 |
local stack_name=${1} |
|
|
17 |
|
|
|
18 |
local repo_http_url=$(aws cloudformation describe-stacks --stack-name ${stack_name} --query 'Stacks[].Outputs[?OutputKey==`RepoHttpUrl`].OutputValue') |
|
|
19 |
|
|
|
20 |
git init .; git remote add origin ${repo_http_url} |
|
|
21 |
|
|
|
22 |
git add *; git commit -m "first commit"; git push --set-upstream origin master |
|
|
23 |
|
|
|
24 |
} |
|
|
25 |
|
|
|
26 |
wait_for_pipeline() { |
|
|
27 |
local pipeline_name=${1} |
|
|
28 |
local commit_id=${2} |
|
|
29 |
|
|
|
30 |
local message="Max attempts reached. Pipeline execution failed for commit: ${commit_id}" |
|
|
31 |
for i in {1..60}; do |
|
|
32 |
|
|
|
33 |
stage_status=$(aws codepipeline list-pipeline-executions --pipeline-name ${pipeline_name} --query 'pipelineExecutionSummaries[?sourceRevisions[0].revisionId==`'${commit_id}'`].status') |
|
|
34 |
|
|
|
35 |
if [ "${stage_status}" == "InProgress" ] || [ -z "${stage_status}" ]; then |
|
|
36 |
printf '.' |
|
|
37 |
sleep 30 |
|
|
38 |
elif [ "${stage_status}" == "Succeeded" ]; then |
|
|
39 |
message="CodePipeline execution succeeded for commit: ${commit_id}" |
|
|
40 |
break |
|
|
41 |
elif [ "${stage_status}" == "Failed" ]; then |
|
|
42 |
message="CodePipeline execution Failed for commit: ${commit_id}" |
|
|
43 |
break |
|
|
44 |
fi |
|
|
45 |
|
|
|
46 |
done |
|
|
47 |
printf "\n${message}\n" |
|
|
48 |
if [ "${stage_status}" == "Failed" ]; then exit 1; fi |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
copy_unpack_zip() { |
|
|
52 |
local source_artifact=${1} |
|
|
53 |
local dest_prefix=${2} |
|
|
54 |
|
|
|
55 |
echo "Unpacking ${source_artifact} to ${dest_prefix}" |
|
|
56 |
aws s3 cp ${source_artifact} ./temporary.zip |
|
|
57 |
mkdir stage |
|
|
58 |
pushd stage; unzip ../temporary.zip; popd |
|
|
59 |
aws s3 sync stage/ ${dest_prefix} |
|
|
60 |
rm -rf stage temporary.zip |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
copy_and_upload() { |
|
|
64 |
local source_artifact=${1} |
|
|
65 |
local dest_artifact=${2} |
|
|
66 |
local filename=${3} |
|
|
67 |
|
|
|
68 |
aws s3 cp ${source_artifact} ${filename} |
|
|
69 |
aws s3 cp ${filename} ${dest_artifact} |
|
|
70 |
rm ${filename} |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
copy_test_data() { |
|
|
74 |
local artifact_bucket=${1} |
|
|
75 |
local artifact_key_prefix=${2} |
|
|
76 |
local pipe_stackname=${3} |
|
|
77 |
|
|
|
78 |
local data_lake_bucket=$(aws cloudformation describe-stacks --stack-name ${pipe_stackname} --query 'Stacks[].Outputs[?OutputKey==`DataLakeBucket`].OutputValue' --output text) |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
copy_unpack_zip s3://${artifact_bucket}/${artifact_key_prefix}/tcga/tcga-clinical.zip s3://${data_lake_bucket}/ |
|
|
82 |
copy_unpack_zip s3://${artifact_bucket}/${artifact_key_prefix}/tcga/tcga-cnv.zip s3://${data_lake_bucket}/ |
|
|
83 |
copy_unpack_zip s3://${artifact_bucket}/${artifact_key_prefix}/tcga/tcga-expression.zip s3://${data_lake_bucket}/ |
|
|
84 |
copy_unpack_zip s3://${artifact_bucket}/${artifact_key_prefix}/tcga/tcga-mutation.zip s3://${data_lake_bucket}/ |
|
|
85 |
copy_unpack_zip s3://${artifact_bucket}/${artifact_key_prefix}/tcga/tcia-metadata.zip s3://${data_lake_bucket}/ |
|
|
86 |
copy_unpack_zip s3://${artifact_bucket}/${artifact_key_prefix}/tcga/tcga-summary.zip s3://${data_lake_bucket}/ |
|
|
87 |
|
|
|
88 |
copy_and_upload s3://${artifact_bucket}/${artifact_key_prefix}/annotation/clinvar/clinvar.vcf.gz s3://${data_lake_bucket}/annotation/vcf/clinvar/clinvar.vcf.gz clinvar.vcf.gz |
|
|
89 |
copy_and_upload s3://${artifact_bucket}/${artifact_key_prefix}/variants/vcf/variants.vcf.gz s3://${data_lake_bucket}/variants/vcf/variants.vcf.gz variants.vcf.gz |
|
|
90 |
copy_and_upload s3://${artifact_bucket}/${artifact_key_prefix}/variants/1kg/ALL.chr22.shapeit2_integrated_snvindels_v2a_27022019.GRCh38.phased.filtNA.vcf.gz s3://${data_lake_bucket}/variants/1kg/ALL.chr22.shapeit2_integrated_snvindels_v2a_27022019.GRCh38.phased.filtNA.vcf.gz ALL.chr22.shapeit2_integrated_snvindels_v2a_27022019.GRCh38.phased.filtNA.vcf.gz |
|
|
91 |
copy_and_upload s3://${artifact_bucket}/${artifact_key_prefix}/references/hg38/Homo_sapiens_assembly38.fasta s3://${data_lake_bucket}/references/hg38/Homo_sapiens_assembly38.fasta Homo_sapiens_assembly38.fasta |
|
|
92 |
} |
|
|
93 |
|
|
|
94 |
setup() { |
|
|
95 |
|
|
|
96 |
local resource_prefix=$1 |
|
|
97 |
local artifact_bucket=$2 |
|
|
98 |
local artifact_key_prefix=$3 |
|
|
99 |
|
|
|
100 |
local dir_prefix="GenomicsAnalysis" |
|
|
101 |
|
|
|
102 |
local zone_dir="${dir_prefix}Zone" |
|
|
103 |
local pipe_dir="${dir_prefix}Pipe" |
|
|
104 |
local code_dir="${dir_prefix}Code" |
|
|
105 |
|
|
|
106 |
local zone_stackname=${resource_prefix}-LandingZone |
|
|
107 |
local pipe_stackname=${resource_prefix}-Pipeline |
|
|
108 |
|
|
|
109 |
# Create stacks |
|
|
110 |
create_stack "${zone_stackname}" "${zone_dir}/zone_cfn.yml" "${resource_prefix}" |
|
|
111 |
create_stack "${pipe_stackname}" "${pipe_dir}/pipe_cfn.yml" "${resource_prefix}" |
|
|
112 |
|
|
|
113 |
# Clone and commit resources |
|
|
114 |
cd "${pipe_dir}"; clone_and_commit "${zone_stackname}"; cd .. |
|
|
115 |
cd "${code_dir}"; clone_and_commit "${pipe_stackname}"; |
|
|
116 |
|
|
|
117 |
# Get the last commit id |
|
|
118 |
commit_id=$(git log -1 --pretty=format:%H) |
|
|
119 |
cd .. |
|
|
120 |
|
|
|
121 |
# Get pipeline name |
|
|
122 |
pipeline_name=$(aws cloudformation describe-stack-resource --stack-name ${pipe_stackname} --logical-resource-id CodePipeline --query 'StackResourceDetail.PhysicalResourceId') |
|
|
123 |
|
|
|
124 |
# Copy Test Data |
|
|
125 |
copy_test_data "${artifact_bucket}" "${artifact_key_prefix}" "${pipe_stackname}" |
|
|
126 |
|
|
|
127 |
# Wait for pipeline execution using commit id |
|
|
128 |
wait_for_pipeline "${pipeline_name}" "${commit_id}" |
|
|
129 |
|
|
|
130 |
# Run Crawlers for TCGA data |
|
|
131 |
"${code_dir}/run_crawlers.sh" "${resource_prefix}" |
|
|
132 |
} |
|
|
133 |
|
|
|
134 |
project_name=${PROJECT_NAME:-GenomicsAnalysis} |
|
|
135 |
|
|
|
136 |
setup "$project_name" "${ARTIFACT_BUCKET}" "${ARTIFACT_KEY_PREFIX}" |