summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Schultz <schultz.derek@gmail.com>2016-12-13 10:06:09 -0700
committerGitHub <noreply@github.com>2016-12-13 10:06:09 -0700
commit4efc71a2ade1a255359bafb25de4a386c838b501 (patch)
treec6799fdbacb2c4911483326a56162d81448a185f
parent2981828da52a4cac953fba275b716d80a5dce0d3 (diff)
parentb297146ea8423f9a513e1365c134d6d6611ced5a (diff)
Merge pull request #29 from denismakogon/issue/20
Issue #20: Keep devstack plugin in-tree
-rw-r--r--devstack/README.rst59
-rw-r--r--devstack/files/debs/functions2
-rw-r--r--devstack/files/rpms-suse/functions3
-rw-r--r--devstack/files/rpms/functions3
-rw-r--r--devstack/plugin.sh250
-rw-r--r--devstack/settings30
6 files changed, 347 insertions, 0 deletions
diff --git a/devstack/README.rst b/devstack/README.rst
new file mode 100644
index 0000000..b0e7372
--- /dev/null
+++ b/devstack/README.rst
@@ -0,0 +1,59 @@
1Enabling Picasso (Functions-as-a-Service) in DevStack
2=====================================================
3
4Installing Glide
5================
6
7Note that your machine should have Glide installed.
8See more info at https://github.com/Masterminds/glide
9
10
11Download DevStack
12=================
13
14.. sourcecode:: bash
15
16 export DEVSTACK_DIR=~/devstack
17 git clone git://git.openstack.org/openstack-dev/devstack.git $DEVSTACK_DIR
18
19Enable the FaaS plugin
20======================
21
22Enable the plugin by adding the following section to ``$DEVSTACK_DIR/local.conf``
23
24.. sourcecode:: bash
25
26 [[local|localrc]]
27
28 enable_plugin picasso git@github.com:iron-io/picasso.git
29
30 # Picasso configuration
31 PICASSO_REPO=${PICASSO_REPO:-git@github.com:iron-io/picasso.git}
32 PICASSO_BRANCH=${PICASSO_BRANCH:-master}
33 PICASSO_DIR=${PICASSO_DIR:-${DEST}/picasso}
34 PICASSO_PORT=${PICASSO_PORT:-10001}
35 PICASSO_LOG_LEVEL=${PICASSO_LOG_LEVEL:-DEBUG}
36 PICASSO_LOG_FILE=${PICASSO_LOG_FILE:-/var/log/picasso-api.log}
37
38 # Picasso client configuration
39 PICASSO_CLIENT_REPO=${PICASSO_CLIENT_REPO:-git@github.com:iron-io/python-picassoclient.git}
40 PICASSO_CLIENT_DIR=${PICASSO_CLIENT_DIR:-${DEST}/python-picassoclient}
41 PICASSO_CLIENT_BRANCH=${PICASSO_CLIENT_BRANCH:-master}
42
43 # IronFunctions parameters
44 FUNCTIONS_REPO=${FUNCTIONS_REPO:-git@github.com:iron-io/functions.git}
45 FUNCTIONS_BRANCH=${FUNCTIONS_BRANCH:-master}
46 FUNCTIONS_PORT=${FUNCTIONS_PORT:-10501}
47 FUNCTIONS_DB=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.storage.db?bucket=funcs}
48 FUNCTIONS_MQ=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.queue.db}
49 FUNCTIONS_LOG_LEVEL=${FUNCTIONS_LOG_LEVEL:-DEBUG}
50
51 DOCKERD_OPTS=${DOCKERD_OPTS:---dns 8.8.8.8 --dns 8.8.4.4 --storage-driver=overlay2 -H fd://}
52
53Run the DevStack utility
54========================
55
56.. sourcecode:: bash
57
58 cd $DEVSTACK_DIR
59 ./stack.sh
diff --git a/devstack/files/debs/functions b/devstack/files/debs/functions
new file mode 100644
index 0000000..30ba113
--- /dev/null
+++ b/devstack/files/debs/functions
@@ -0,0 +1,2 @@
1golang
2docker \ No newline at end of file
diff --git a/devstack/files/rpms-suse/functions b/devstack/files/rpms-suse/functions
new file mode 100644
index 0000000..dbd341c
--- /dev/null
+++ b/devstack/files/rpms-suse/functions
@@ -0,0 +1,3 @@
1golang
2hg
3docker \ No newline at end of file
diff --git a/devstack/files/rpms/functions b/devstack/files/rpms/functions
new file mode 100644
index 0000000..dbd341c
--- /dev/null
+++ b/devstack/files/rpms/functions
@@ -0,0 +1,3 @@
1golang
2hg
3docker \ No newline at end of file
diff --git a/devstack/plugin.sh b/devstack/plugin.sh
new file mode 100644
index 0000000..b7592e7
--- /dev/null
+++ b/devstack/plugin.sh
@@ -0,0 +1,250 @@
1#!/bin/bash
2#
3
4# lib/functions
5# Functions to control the configuration and operation of the **Functions-as-a-Service** service
6
7# Dependencies:
8# ``functions`` file
9# ``DEST``, ``STACK_USER`` must be defined
10# ``SERVICE_{HOST|PROTOCOL|TOKEN}`` must be defined
11
12# ``stack.sh`` calls the entry points in this order:
13#
14
15
16# Save trace setting
17XTRACE=$(set +o | grep xtrace)
18set +o xtrace
19
20# Functions
21# ---------
22
23
24function is_functions_enabled {
25 [[ ,${ENABLED_SERVICES} =~ ,"picasso" ]] && return 0
26 return 1
27}
28
29function create_functions_accounts {
30 if [[ "$ENABLED_SERVICES" =~ "functions" ]]; then
31
32 create_service_user "picasso" "admin"
33
34 local functions_service=$(get_or_create_service "picasso" \
35 "functions" "Functions-as-a-Service")
36 get_or_create_endpoint $functions_service \
37 "$REGION_NAME" \
38 "http://$SERVICE_HOST:$PICASSO_PORT" \
39 "http://$SERVICE_HOST:$PICASSO_PORT" \
40 "http://$SERVICE_HOST:$PICASSO_PORT"
41 fi
42}
43
44function install_go_1.7.1 {
45 wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz -O /tmp/go1.7.linux-amd64.tar.gz
46 sudo tar -xvf /tmp/go1.7.linux-amd64.tar.gz -C /usr/local/
47 sudo rm -fr /usr/bin/go
48 sudo rm -fr /usr/bin/gofmt
49 sudo ln -s /usr/local/go/bin/go /usr/bin/go
50 sudo ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
51 `which go` env
52}
53
54function check_docker {
55 if is_ubuntu; then
56 dpkg -s docker-engine > /dev/null 2>&1
57 else
58 rpm -q docker-engine > /dev/null 2>&1
59 fi
60}
61
62function install_docker {
63 check_docker || curl -fsSL https://get.docker.com/ | sudo sh
64
65 echo "Adding ${STACK_USER} to ${docker_group}..."
66 add_user_to_group $STACK_USER $DOCKER_GROUP
67 echo "Adding $(whoami) to ${DOCKER_GROUP}..."
68 add_user_to_group $(whoami) $DOCKER_GROUP
69
70 if is_fedora; then
71 install_package socat dnsmasq
72 fi
73
74 if is_ubuntu && [ $UBUNTU_RELEASE_BASE_NUM -le 14 ]; then
75 sudo service docker start || true
76 else
77 echo -e "[Unit]
78 Description=Docker Application Container Engine
79 Documentation=https://docs.docker.com
80 After=network.target docker.socket
81 Requires=docker.socket
82 [Service]
83 Type=notify
84 Environment=SERVICE_HOST=${SERVICE_HOST}
85 ExecStart=/usr/bin/dockerd -H tcp://${SERVICE_HOST}:2375 ${DOCKERD_OPTS}
86 MountFlags=slave
87 LimitNOFILE=1048576
88 LimitNPROC=1048576
89 LimitCORE=infinity
90 TimeoutStartSec=0
91 Delegate=yes
92 [Install]
93 WantedBy=multi-user.target" | sudo tee -a /lib/systemd/system/docker.service.new
94
95 sudo mv /lib/systemd/system/docker.service.new /lib/systemd/system/docker.service
96
97 sudo systemctl daemon-reload
98 sudo systemctl enable docker.service
99 sudo systemctl restart docker || true
100 fi
101}
102
103
104function is_glide_installed {
105 echo_summary "Attempting to find Glide binary"
106 local glbin=`which glide`
107 if [[ -z "${glbin}" ]]; then
108 echo_summary "Glide is not installed, aborting."
109 exit 1
110 fi
111}
112
113
114function install_picasso {
115 echo_summary "Installing Picasso"
116 git_clone $PICASSO_REPO $PICASSO_DIR $FUNCTIONS_BRANCH
117 pushd $PICASSO_DIR && docker -H tcp://${SERVICE_HOST}:2375 build -t picasso-api -f $PICASSO_DIR/Dockerfile .; popd
118}
119
120function apply_picasso_migrations {
121 echo_summary "Applying Picasso migrations"
122 recreate_database_mysql functions
123 local picasso_db=$(get_database_type_mysql)://${DATABASE_USER}:${DATABASE_PASSWORD}@${MYSQL_HOST}/functions
124 pushd $PICASSO_DIR && PICASSO_MIGRATIONS_DB=${picasso_db} alembic upgrade head; popd
125
126}
127
128function install_functions {
129 echo_summary "Pulling Functions sources"
130 git_clone $FUNCTIONS_REPO $GOPATH/src/github.com/iron-io/functions $FUNCTIONS_BRANCH
131 pushd $FUNCTIONS_DIR && GOPATH=${GOPATH} make all; popd
132}
133
134function configure_systemctl_for_functions_api {
135 echo -e "[Unit]
136Description=Functions API service
137After=network.target
138[Service]
139Type=notify
140Environment=GOPATH=${GOPATH}
141Environment=PORT=${FUNCTIONS_PORT}
142Environment=API_URL=http://${SERVICE_HOST}:${FUNCTIONS_PORT}
143Environment=DOCKER_HOST=tcp://${SERVICE_HOST}:2375
144Environment=LOG_LEVEL=${FUNCTIONS_LOG_LEVEL}
145Environment=DB_URL=${FUNCTIONS_DB}
146Environment=MQ_URL=${FUNCTIONS_MQ}
147ExecStart=${FUNCTIONS_DIR}/functions
148LimitNOFILE=1048576
149LimitNPROC=1048576
150LimitCORE=infinity
151TimeoutStartSec=0
152[Install]
153WantedBy=multi-user.target" | sudo tee - a /lib/systemd/system/functions-api.service.new
154
155 sudo mv /lib/systemd/system/functions-api.service.new /lib/systemd/system/functions-api.service
156 sudo systemctl daemon-reload
157}
158
159function configure_systemctl_for_picasso_api {
160 rm -fr $PICASSO_DIR/.picasso.docker
161 echo -e "PICASSO_HOST=0.0.0.0
162PICASSO_PORT=${PICASSO_PORT}
163PICASSO_DB=$(get_database_type_mysql)://${DATABASE_USER}:${DATABASE_PASSWORD}@${SERVICE_HOST}/functions
164KEYSTONE_ENDPOINT=http://${SERVICE_HOST}:5000/v3
165FUNCTIONS_URL=http://${SERVICE_HOST}:${FUNCTIONS_PORT}/v1
166PICASSO_LOG_LEVEL=DEBUG
167 " | tee -a $PICASSO_DIR/.picasso.docker
168
169 echo -e "[Unit]
170Description=Picasso API service
171After=network.target
172[Service]
173Type=notify
174Environment=PICASSO_DIR=${PICASSO_DIR}
175Environment=DOCKER_HOST=tcp://${SERVICE_HOST}:2375
176ExecStart=/usr/bin/docker -H tcp://${SERVICE_HOST}:2375 run --name picasso-api -d -p ${SERVICE_HOST}:10001:10001 --env-file ${PICASSO_DIR}/.picasso.docker picasso-api
177ExecStop=/usr/bin/docker -H tcp://${SERVICE_HOST}:2375 stop -t 1 picasso-api
178ExecStopPost=/usr/bin/docker -H tcp://${SERVICE_HOST}:2375 rm -f picasso-api
179RemainAfterExit=true
180LimitNOFILE=1048576
181LimitNPROC=1048576
182LimitCORE=infinity
183TimeoutStartSec=0
184[Install]
185WantedBy=multi-user.target" | sudo tee - a /lib/systemd/system/picasso-api.service.new
186
187 sudo mv /lib/systemd/system/picasso-api.service.new /lib/systemd/system/picasso-api.service
188 sudo systemctl daemon-reload
189}
190
191
192function start_picasso_api {
193 echo_summary "Starting Picasso API"
194 sudo systemctl start picasso-api.service
195}
196
197
198function stop_picasso_api {
199 echo_summary "Stopping Picasso API"
200 sudo systemctl stop picasso-api.service
201}
202
203
204function start_functions {
205 echo_summary "Starting Functions API"
206 sudo systemctl start functions-api.service &
207}
208
209
210function stop_functions {
211 echo_summary "Stopping Functions API"
212 sudo systemctl stop functions-api.service &
213}
214
215function install_python_picassoclient {
216 git_clone $PICASSO_CLIENT_REPO $PICASSO_CLIENT_DIR $PICASSO_CLIENT_BRANCH
217 setup_develop $PICASSO_CLIENT_DIR
218}
219
220if is_service_enabled functions; then
221
222 if [[ "$1" == "stack" && "$2" == "install" ]]; then
223 echo_summary "Installing Functions"
224 install_docker
225 install_go_1.7.1
226 is_glide_installed
227 install_functions
228 install_picasso
229 install_python_picassoclient
230 elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
231 echo_summary "Configuring Picasso and IronFunctions"
232 configure_systemctl_for_functions_api
233 configure_systemctl_for_picasso_api
234 if is_service_enabled key; then
235 create_functions_accounts
236 fi
237 elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
238 apply_picasso_migrations
239 start_functions
240 start_picasso_api
241 fi
242
243 if [[ "$1" == "unstack" ]]; then
244 stop_functions
245 stop_picasso_api
246 fi
247fi
248
249# Restore xtrace
250$XTRACE
diff --git a/devstack/settings b/devstack/settings
new file mode 100644
index 0000000..2f63571
--- /dev/null
+++ b/devstack/settings
@@ -0,0 +1,30 @@
1# Settings needed for Picasso (Functions-as-a-Service) plugin
2# -----------------------------------------------------------
3
4# Set up default directories
5
6# Picasso service configuration
7PICASSO_REPO=${PICASSO_REPO:-git@github.com:iron-io/picasso.git}
8PICASSO_BRANCH=${PICASSO_BRANCH:-master}
9PICASSO_DIR=${PICASSO_DIR:-${DEST}/picasso}
10PICASSO_PORT=${PICASSO_PORT:-10001}
11PICASSO_LOG_LEVEL=${PICASSO_LOG_LEVEL:-DEBUG}
12
13# Picasso client configuration
14PICASSO_CLIENT_REPO=${PICASSO_CLIENT_REPO:-git@github.com:iron-io/python-picassoclient.git}
15PICASSO_CLIENT_DIR=${PICASSO_CLIENT_DIR:-${DEST}/python-picassoclient}
16PICASSO_CLIENT_BRANCH=${PICASSO_CLIENT_BRANCH:-master}
17
18# IronFunctions configuration
19GOPATH=${GOPATH:-${DEST}/functions}
20FUNCTIONS_DIR=${FUNCTIONS_DIR:-${GOPATH}/src/github.com/iron-io/functions}
21FUNCTIONS_REPO=${FUNCTIONS_REPO:-git@github.com:iron-io/functions.git}
22FUNCTIONS_BRANCH=${FUNCTIONS_BRANCH:-master}
23FUNCTIONS_PORT=${FUNCTIONS_PORT:-10501}
24FUNCTIONS_DB=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.storage.db?bucket=funcs}
25FUNCTIONS_MQ=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.queue.db}
26FUNCTIONS_LOG_LEVEL=${FUNCTIONS_LOG_LEVEL:-DEBUG}
27
28DOCKERD_OPTS=${DOCKER_OPTS:---dns 8.8.8.8 --dns 8.8.4.4 --storage-driver=overlay2}
29
30enable_service picasso