-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·156 lines (130 loc) · 4.65 KB
/
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
set -euo pipefail
cd -Pe $(dirname $0)
BASE_DIR=$(pwd)
export PATH=$BASE_DIR:$PATH
trap onExit EXIT
onExit() {
local status=$?
if [ "${ENVIRONMENT}" == "local" -a -d "$JENKINS_DIR" ]; then rm -r $JENKINS_DIR; fi
return $status
}
#
# Set up a mechanism to communicate job descriptions, etc. so that Jenkins provides more meaningful pages
#
JENKINS_DIR=$BASE_DIR/.jenkins
JENKINS_DESCRIPTION=$JENKINS_DIR/description
JENKINS_BUILD_NAME=$JENKINS_DIR/build-name
if [ -d "$JENKINS_DIR" ]; then rm -rf "$JENKINS_DIR"; fi
mkdir "$JENKINS_DIR"
#
# To support Jenkins use of the flyway container and because
# the flyway script provided in the flyway docker image isn't executable,
# we'll need to launch flyway via bash.
#
FLYWAY=flyway
if [ -f /flyway/flyway ]; then FLYWAY="bash /flyway/flyway"; fi
#
# To support local testing, add a local install to the front of the path
#
LOCAL_INSTALL=$(find . -maxdepth 1 -name "flyway-[678]*" | sort -V | head -1)
if [ -n "$LOCAL_INSTALL" ]
then
if [[ "$LOCAL_INSTALL" == *flyway-6* ]]; then echo "WARNING: Upgrade Flyway To Version 7"; fi;
export PATH="$LOCAL_INSTALL:$PATH"
fi
#
# Load environment specific configuration. See local.conf as an example
# of variables that need to be set.
#
echo "Loading configuration for ${ENVIRONMENT}"
case "${ENVIRONMENT}" in
lab) . environments/lab.conf;;
staging-lab) . environments/staging-lab.conf;;
qa) . environments/qa.conf;;
local) . environments/local.conf;;
*) echo "Unknown environment: $ENVIRONMENT"; exit 1;;
esac
echo "$ENVIRONMENT synthetic database updated" >> $JENKINS_DESCRIPTION
echo "$ENVIRONMENT" >> $JENKINS_BUILD_NAME
#
# These options are true through out the migration.
#
export FLYWAY_EDITION=community
export FLYWAY_DRIVER=com.microsoft.sqlserver.jdbc.SQLServerDriver
export FLYWAY_VALIDATE_ON_MIGRATE=true
export FLYWAY_BASELINE_ON_MIGRATE=true
export FLYWAY_BASELINE_VERSION=0.1
export FLYWAY_PLACEHOLDERS_DB_NAME=dq
export BOOTSTRAP_DB=jenkins
announce() {
echo "============================================================"
echo "$1"
echo "============================================================"
}
#
# When AWS creates the SQL Server instance, this is likely to be the very
# first interaction with it. We won't have a database within the instance yet
# that is required to bootstrap the rest of databases. This hack creates one
# that we will use to track the creation of the other databases.
#
BOOTSTRAP_DB_HACK="IF DB_ID (N'$BOOTSTRAP_DB') IS NULL CREATE DATABASE $BOOTSTRAP_DB"
$FLYWAY info -q -url="${FLYWAY_BASE_URL}" -initSql="$BOOTSTRAP_DB_HACK"
runDataQueryTests() {
if [[ "${ENVIRONMENT}" != "qa" && "${ENVIRONMENT}" != "staging-lab" && "${ENVIRONMENT}" != "lab" ]]
then
echo "Not running Data Query tests for: $ENVIRONMENT" && return 1
fi
if [ "$RUN_DATA_QUERY_TESTS" == "true" ]
then
local job="job/department-of-veterans-affairs/job/health-apis-agent-j/job/master%252Frun-application-tests"
local url="$HUDSON_URL/$job/buildWithParameters?ENVIRONMENT=$ENVIRONMENT&PRODUCT=data-query"
announce "Launching Data Query application tests: $url"
local status=$(curl \
-s \
-X POST \
"$url" \
-w "%{http_code}" \
-o /dev/null \
--user "$PROMOTATRON_USERNAME_PASSWORD")
if [ "$status" != 201 ]
then
echo "Data Query test not started: $status"
return 1
fi
fi
return 0
}
announce "Bootstrapping database"
$FLYWAY migrate \
-url="${FLYWAY_BASE_URL};databaseName=$BOOTSTRAP_DB" \
-table=flyway_schema_history \
-locations='filesystem:db/bootstrap'
announce "Migrating Database"
$FLYWAY migrate \
-url="${FLYWAY_BASE_URL};databaseName=$FLYWAY_PLACEHOLDERS_DB_NAME" \
-table=flyway_schema_history \
-locations='filesystem:db/migration' \
-schemas=app
DATAMART_DIR=$BASE_DIR/datamart
cd minimart-manager
CONFIG_FILE=sqlserver.properties
cat <<EOF > $CONFIG_FILE
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=$FLYWAY_BASE_URL;databaseName=$FLYWAY_PLACEHOLDERS_DB_NAME
spring.datasource.username=$FLYWAY_USER
spring.datasource.password=$FLYWAY_PASSWORD
EOF
cat $CONFIG_FILE
announce "Populating Database Tables"
MVN_ARGS=
LIGHTHOUSE_SETTINGS=/lighthouse-mvn-settings.xml
if [ -f $LIGHTHOUSE_SETTINGS ]
then
MVN_ARGS+=" --settings $LIGHTHOUSE_SETTINGS"
MVN_ARGS+=" -Dhealth-apis-releases.nexus.user=$NEXUS_USERNAME"
MVN_ARGS+=" -Dhealth-apis-releases.nexus.password=$NEXUS_PASSWORD"
fi
if [ -n "${RESOURCES:-}" ]; then MVN_ARGS+=" -Dresources=$RESOURCES"; fi
mvn ${MVN_ARGS:-} -Dimport.directory=$DATAMART_DIR -Dconfig.file=$CONFIG_FILE -Dtest=PopulateDb test
if ! runDataQueryTests; then echo "aborting"; exit 1; fi