Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: tools/android/loading/gce/startup-script.sh

Issue 1895033002: tools/android/loading Switch the GCE worker to pull queues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@appengine
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/android/loading/gce/pip_requirements.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # Script executed at instance startup. It installs the required dependencies,
6 # downloads the source code, and starts a web server.
7
8 set -v
9
10 get_instance_metadata() {
11 curl -fs http://metadata/computeMetadata/v1/instance/attributes/$1 \
12 -H "Metadata-Flavor: Google"
13 }
14
15 # Talk to the metadata server to get the project id
16 PROJECTID=$(curl -s \
17 "http://metadata.google.internal/computeMetadata/v1/project/project-id" \
18 -H "Metadata-Flavor: Google")
19
20 # Install dependencies from apt
21 apt-get update
22 # Basic dependencies
23 apt-get install -yq git supervisor python-pip python-dev unzip
24 # Web server dependencies
25 apt-get install -yq libffi-dev libssl-dev
26 # Chrome dependencies
27 apt-get install -yq libpangocairo-1.0-0 libXcomposite1 libXcursor1 libXdamage1 \
28 libXi6 libXtst6 libnss3 libcups2 libgconf2-4 libXss1 libXrandr2 \
29 libatk1.0-0 libasound2 libgtk2.0-0
30 # Trace collection dependencies
31 apt-get install -yq xvfb
32
33 # Create a pythonapp user. The application will run as this user.
34 useradd -m -d /home/pythonapp pythonapp
35
36 # pip from apt is out of date, so make it update itself and install virtualenv.
37 pip install --upgrade pip virtualenv
38
39 # Download the Clovis deployment from Google Cloud Storage and unzip it.
40 # It is expected that the contents of the deployment have been generated using
41 # the tools/android/loading/gce/deploy.sh script.
42 CLOUD_STORAGE_PATH=`get_instance_metadata cloud-storage-path`
43 DEPLOYMENT_PATH=$CLOUD_STORAGE_PATH/deployment
44
45 mkdir -p /opt/app/clovis
46 gsutil cp gs://$DEPLOYMENT_PATH/source/source.tgz /opt/app/clovis/source.tgz
47 tar xvf /opt/app/clovis/source.tgz -C /opt/app/clovis
48 rm /opt/app/clovis/source.tgz
49
50 # Install app dependencies
51 virtualenv /opt/app/clovis/env
52 /opt/app/clovis/env/bin/pip install \
53 -r /opt/app/clovis/src/tools/android/loading/gce/pip_requirements.txt
54
55 mkdir /opt/app/clovis/binaries
56 gsutil cp gs://$DEPLOYMENT_PATH/binaries/* /opt/app/clovis/binaries/
57 unzip /opt/app/clovis/binaries/linux.zip -d /opt/app/clovis/binaries/
58
59 # Install the Chrome sandbox
60 cp /opt/app/clovis/binaries/chrome_sandbox /usr/local/sbin/chrome-devel-sandbox
61 chown root:root /usr/local/sbin/chrome-devel-sandbox
62 chmod 4755 /usr/local/sbin/chrome-devel-sandbox
63
64 # Make sure the pythonapp user owns the application code
65 chown -R pythonapp:pythonapp /opt/app
66
67 # Create the configuration file for this deployment.
68 DEPLOYMENT_CONFIG_PATH=/opt/app/clovis/deployment_config.json
69 cat >$DEPLOYMENT_CONFIG_PATH << EOF
70 {
71 "project_name" : "$PROJECTID",
72 "cloud_storage_path" : "$CLOUD_STORAGE_PATH",
73 "chrome_path" : "/opt/app/clovis/binaries/chrome",
74 "src_path" : "/opt/app/clovis/src"
75 }
76 EOF
77
78 # Check if auto-start is enabled
79 AUTO_START=`get_instance_metadata auto-start`
80
81 # Exit early if auto start is not enabled.
82 if [ "$AUTO_START" != "true" ]; then
83 exit 1
84 fi
85
86 # Configure supervisor to start gunicorn inside of our virtualenv and run the
87 # applicaiton.
88 cat >/etc/supervisor/conf.d/python-app.conf << EOF
89 [program:pythonapp]
90 directory=/opt/app/clovis/src/tools/android/loading/gce
91 command=/opt/app/clovis/env/bin/gunicorn --workers=1 --bind 0.0.0.0:8080 \
92 'main:StartApp('\"$DEPLOYMENT_CONFIG_PATH\"')'
93 autostart=true
94 autorestart=true
95 user=pythonapp
96 # Environment variables ensure that the application runs inside of the
97 # configured virtualenv.
98 environment=VIRTUAL_ENV="/opt/app/clovis/env", \
99 PATH="/opt/app/clovis/env/bin:/usr/bin", \
100 HOME="/home/pythonapp",USER="pythonapp", \
101 CHROME_DEVEL_SANDBOX="/usr/local/sbin/chrome-devel-sandbox"
102 stdout_logfile=syslog
103 stderr_logfile=syslog
104 EOF
105
106 supervisorctl reread
107 supervisorctl update
108
OLDNEW
« no previous file with comments | « tools/android/loading/gce/pip_requirements.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698