forked from google/appengine-phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_time_config.sh
72 lines (63 loc) · 3.01 KB
/
run_time_config.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
#!/bin/bash -e
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
mkdir -p /var/log/app_engine/custom_logs
cd /opt/phabricator
export SQL_DETAILS="$(/google/google-cloud-sdk/bin/gcloud sql instances describe ${SQL_INSTANCE} --format=json)"
if [ -z "${SQL_DETAILS}" ]; then
echo "Failed to lookup details for the '${SQL_INSTANCE}' Cloud SQL instance" >> /var/log/app_engine/custom_logs/setup.log
exit 1
fi
echo "${SQL_DETAILS}" >> /var/log/app_engine/custom_logs/setup.log
export SQL_HOST=$(echo ${SQL_DETAILS} | jq -r '.ipAddresses[0].ipAddress')
if [ -z "${SQL_HOST}" ]; then
echo "Failed to lookup the IP address of the '${SQL_INSTANCE}' Cloud SQL instance" >> /var/log/app_engine/custom_logs/setup.log
exit 1
fi
export SQL_USER=root
echo "Setting up a connection to ${SQL_INSTANCE} at ${SQL_HOST} as ${SQL_USER}" >> /var/log/app_engine/custom_logs/setup.log
export SQL_PASS="$(uuidgen)"
/google/google-cloud-sdk/bin/gcloud sql instances set-root-password \
--password "${SQL_PASS}" "${SQL_INSTANCE}"
# Configure Phabricator's connection to the SQL server.
./bin/config set mysql.host ${SQL_HOST}
./bin/config set mysql.port 3306
./bin/config set mysql.user ${SQL_USER}
./bin/config set mysql.pass ${SQL_PASS}
# And setup the .my.cnf file so that mysql commands are authenticated.
cat > ~/.my.cnf <<EOF
[client]
host=${SQL_HOST}
user=${SQL_USER}
password=${SQL_PASS}
EOF
# Configure Phabricator's reference to itself.
./bin/config set phabricator.base-uri ${PHABRICATOR_BASE_URI}
./bin/config set security.alternate-file-domain ${ALTERNATE_FILE_DOMAIN}
./bin/config set phd.taskmasters 4
# Restore the /var/repo directory from the GCS backup (if one exists)
PROJECT=$(curl http://metadata.google.internal/computeMetadata/v1/project/project-id -H 'Metadata-Flavor: Google')
BACKUP_FILE=$(/google/google-cloud-sdk/bin/gsutil cat gs://${PROJECT}.appspot.com/backups/phabricator.backup)
if [ -n "$BACKUP_FILE" ]; then
echo "Restoring from backup ${BACKUP_FILE}" >> /var/log/app_engine/custom_logs/setup.log
/google/google-cloud-sdk/bin/gsutil cp ${BACKUP_FILE} /tmp/phabricator.backup.tgz
tar -xvzf /tmp/phabricator.backup.tgz -C /
fi
# Configure git
echo "Configuring git" >> /var/log/app_engine/custom_logs/setup.log
cd ~/
git config --global --add user.name "git-mirror"
git config --global --add user.email "git-mirror@phabricator-dot-${PROJECT}.appspot.com"
git config --global --list 2>&1 >> /var/log/app_engine/custom_logs/setup.log
echo "Finished configuring git" >> /var/log/app_engine/custom_logs/setup.log