-
Notifications
You must be signed in to change notification settings - Fork 53
/
docker_build.sh
executable file
·121 lines (102 loc) · 6.12 KB
/
docker_build.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# The required environment variables are:
# user - e.g. 'pjmhill'
# m2_cache_parent_folder - the folder within which .m2 is to be found
# src_folder - the folder within which the source code is found
# org_sagebionetworks_stack_iam_id - the id of the developer's AWS secret key
# org_sagebionetworks_stack_iam_key - the developer's AWS secret key
# org_sagebionetworks_stackEncryptionKey - the stack encryption key, common to all dev builds
# org_sagebionetworks_search_enabled - when set to "true", will enable search feature and its tests
# rds_password - the password for the build database, common to all dev builds
# JOB_NAME - a unique string differentiating concurrent builds. if omitted is the stack + user
# build_deploy - when set to any value, deploy artifacts (omit this if you do not wish to deploy)
# artifactory_username - username to deploy artifacts
# artifactory_password - password to deploy artifacts
# org_sagebionetworks_repository_database_connection_url - endpoint to mysql database for repo data
# org_sagebionetworks_table_cluster_endpoint_0 - endpoint to mysql database for user tables data
# org.sagebionetworks.doi.datacite.enabled - when set to true, enable DOI minting/editing features
# org.sagebionetworks.doi.prefix - the prefix to use when minting DOIs (e.g. 10.12345)
# org.sagebionetworks.doi.datacite.enabled - when set to true, enable DOI minting/editing features
# org.sagebionetworks.doi.datacite.username - the username used to connect to DataCite for minting DOIs
# org.sagebionetworks.doi.datacite.password - the password used to connect to DataCite for minting DOIs
# org.sagebionetworks.doi.datacite.api.endpoint - the endpoint used to connect to DataCite for minting DOIs (e.g. mds.test.datacite.org)
# org.sagebionetworks.google.cloud.enabled - when set to true, enable Google Cloud features
# org.sagebionetworks.google.cloud.key - the private key used to log into the Google Cloud service account
# org.sagebionetworks.cloudfront.keypair - the public key ID used for creating signed URLs for CloudFront distribution in front of the S3 data bucket
# org.sagebionetworks.cloudfront.domainname - the domain name for the CloudFront distribution in front of the S3 data bucket
# org.sagebionetworks.cloudfront.private.key.secret - the private key for the CloudFront distribution in front of the S3 data bucket
# if anything fails, stop
set -e
set -v
db_name=${stack}${user}
#used to log in to the db for setup
rds_user_name=${db_name}user
if [ ! ${JOB_NAME} ]; then
JOB_NAME=${stack}${user}
fi
AWS_CREDS=""
if [ -n "${org_sagebionetworks_stack_iam_id}" ] && [ -n "${org_sagebionetworks_stack_iam_key}" ]; then
AWS_CREDS="-Dorg.sagebionetworks.stack.iam.id=${org_sagebionetworks_stack_iam_id} -Dorg.sagebionetworks.stack.iam.key=${org_sagebionetworks_stack_iam_key} "
fi
MVN_GOAL=install
if [ ${build_deploy} ]; then
MVN_GOAL=deploy
SETTINGS_XML="<settings><servers><server><id>sagebionetworks</id><username>${artifactory_username}</username><password>${artifactory_password}</password></server></servers></settings>"
fi
# the containers are ${JOB_NAME}-rds and ${JOB_NAME}-build
clean_up_container() {
if [ $(docker ps --format {{.Names}} -af name=$1) ]; then
docker stop $1
docker rm $1
fi
}
clean_up_volumes() {
docker volume prune -f
}
# remove build container, if any
build_container_name=${JOB_NAME}-build
clean_up_container ${build_container_name}
clean_up_volumes
mkdir -p ${m2_cache_parent_folder}/.m2/
if [ ${SETTINGS_XML} ]; then
echo ${SETTINGS_XML} > ${m2_cache_parent_folder}/.m2/settings.xml
fi
mysql -u${rds_user_name} -p${rds_password} -h ${org_sagebionetworks_repository_database_connection_url} -sN -e "DROP DATABASE ${db_name};CREATE DATABASE ${db_name};"
mysql -u${rds_user_name} -p${rds_password} -h ${org_sagebionetworks_table_cluster_endpoint_0} -sN -e "DROP DATABASE ${db_name};CREATE DATABASE ${db_name};"
# create build container and run build
docker run --user "$(id -u):$(id -g)" -i --rm --name ${build_container_name} \
-m 5500M \
-v ${m2_cache_parent_folder}/.m2:/tmp/.m2 \
-v ${src_folder}:/repo \
-v /etc/localtime:/etc/localtime:ro \
-e MAVEN_OPTS="-Xms256m -Xmx2048m -XX:MaxPermSize=512m" \
-w /repo \
maven:3-amazoncorretto-11 \
bash -c "mvn clean ${MVN_GOAL} ${EXTRA_ARGS} -U \
-Dorg.sagebionetworks.repository.database.connection.url=jdbc:mysql://${org_sagebionetworks_repository_database_connection_url}/${db_name} \
-Dorg.sagebionetworks.id.generator.database.connection.url=jdbc:mysql://${org_sagebionetworks_repository_database_connection_url}/${db_name} \
-Dorg.sagebionetworks.repository.database.username=${rds_user_name} \
-Dorg.sagebionetworks.id.generator.database.username=${rds_user_name} \
-Dorg.sagebionetworks.stackEncryptionKey=${org_sagebionetworks_stackEncryptionKey} \
${AWS_CREDS} \
-Dorg.sagebionetworks.stack.instance=${user} \
-Dorg.sagebionetworks.developer=${user} \
-Dorg.sagebionetworks.stack=${stack} \
-Dorg.sagebionetworks.table.enabled=true \
-Dorg.sagebionetworks.table.cluster.endpoint.0=${org_sagebionetworks_table_cluster_endpoint_0} \
-Dorg.sagebionetworks.table.cluster.schema.0=${db_name} \
-Dorg.sagebionetworks.search.enabled=${org_sagebionetworks_search_enabled} \
-Dorg.sagebionetworks.doi.datacite.enabled=${org_sagebionetworks_datacite_enabled} \
-Dorg.sagebionetworks.doi.prefix=${org_sagebionetworks_doi_prefix} \
-Dorg.sagebionetworks.doi.datacite.username=${org_sagebionetworks_datacite_username} \
-Dorg.sagebionetworks.doi.datacite.password=${org_sagebionetworks_datacite_password} \
-Dorg.sagebionetworks.doi.datacite.api.endpoint=${org_sagebionetworks_doi_datacite_api_endpoint} \
-Dorg.sagebionetworks.google.cloud.enabled=${org_sagebionetworks_google_cloud_enabled} \
-Dorg.sagebionetworks.sts.iam.arn=${org_sagebionetworks_sts_iam_arn} \
-Dorg.sagebionetworks.google.cloud.key="${org_sagebionetworks_google_cloud_key}" \
-Dorg.sagebionetworks.cloudfront.keypair="${org_sagebionetworks_cloudfront_keypair}" \
-Dorg.sagebionetworks.cloudfront.domainname="${org_sagebionetworks_cloudfront_domainname}" \
-Dorg.sagebionetworks.cloudfront.private.key.secret="${org_sagebionetworks_cloudfront_private_key_secret}" \
-Duser.home=/tmp"
clean_up_container ${build_container_name}
clean_up_volumes