Browse Source

Issue #20: Keep devstack plugin in-tree

Implements #20
Denis Makogon 2 years ago
parent
commit
b297146ea8

+ 59
- 0
devstack/README.rst View File

@@ -0,0 +1,59 @@
1
+Enabling Picasso (Functions-as-a-Service) in DevStack
2
+=====================================================
3
+
4
+Installing Glide
5
+================
6
+
7
+Note that your machine should have Glide installed.
8
+See more info at https://github.com/Masterminds/glide
9
+
10
+
11
+Download 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
+
19
+Enable the FaaS plugin
20
+======================
21
+
22
+Enable 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
+
53
+Run the DevStack utility
54
+========================
55
+
56
+.. sourcecode:: bash
57
+
58
+     cd $DEVSTACK_DIR
59
+     ./stack.sh

+ 2
- 0
devstack/files/debs/functions View File

@@ -0,0 +1,2 @@
1
+golang
2
+docker

+ 3
- 0
devstack/files/rpms-suse/functions View File

@@ -0,0 +1,3 @@
1
+golang
2
+hg
3
+docker

+ 3
- 0
devstack/files/rpms/functions View File

@@ -0,0 +1,3 @@
1
+golang
2
+hg
3
+docker

+ 250
- 0
devstack/plugin.sh View File

@@ -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
17
+XTRACE=$(set +o | grep xtrace)
18
+set +o xtrace
19
+
20
+# Functions
21
+# ---------
22
+
23
+
24
+function is_functions_enabled {
25
+    [[ ,${ENABLED_SERVICES} =~ ,"picasso" ]] && return 0
26
+    return 1
27
+}
28
+
29
+function 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
+
44
+function 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
+
54
+function 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
+
62
+function 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
+
104
+function 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
+
114
+function 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
+
120
+function 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
+
128
+function 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
+
134
+function configure_systemctl_for_functions_api {
135
+    echo -e "[Unit]
136
+Description=Functions API service
137
+After=network.target
138
+[Service]
139
+Type=notify
140
+Environment=GOPATH=${GOPATH}
141
+Environment=PORT=${FUNCTIONS_PORT}
142
+Environment=API_URL=http://${SERVICE_HOST}:${FUNCTIONS_PORT}
143
+Environment=DOCKER_HOST=tcp://${SERVICE_HOST}:2375
144
+Environment=LOG_LEVEL=${FUNCTIONS_LOG_LEVEL}
145
+Environment=DB_URL=${FUNCTIONS_DB}
146
+Environment=MQ_URL=${FUNCTIONS_MQ}
147
+ExecStart=${FUNCTIONS_DIR}/functions
148
+LimitNOFILE=1048576
149
+LimitNPROC=1048576
150
+LimitCORE=infinity
151
+TimeoutStartSec=0
152
+[Install]
153
+WantedBy=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
+
159
+function configure_systemctl_for_picasso_api {
160
+    rm -fr $PICASSO_DIR/.picasso.docker
161
+    echo -e "PICASSO_HOST=0.0.0.0
162
+PICASSO_PORT=${PICASSO_PORT}
163
+PICASSO_DB=$(get_database_type_mysql)://${DATABASE_USER}:${DATABASE_PASSWORD}@${SERVICE_HOST}/functions
164
+KEYSTONE_ENDPOINT=http://${SERVICE_HOST}:5000/v3
165
+FUNCTIONS_URL=http://${SERVICE_HOST}:${FUNCTIONS_PORT}/v1
166
+PICASSO_LOG_LEVEL=DEBUG
167
+    " | tee -a $PICASSO_DIR/.picasso.docker
168
+
169
+    echo -e "[Unit]
170
+Description=Picasso API service
171
+After=network.target
172
+[Service]
173
+Type=notify
174
+Environment=PICASSO_DIR=${PICASSO_DIR}
175
+Environment=DOCKER_HOST=tcp://${SERVICE_HOST}:2375
176
+ExecStart=/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
177
+ExecStop=/usr/bin/docker -H tcp://${SERVICE_HOST}:2375 stop -t 1 picasso-api
178
+ExecStopPost=/usr/bin/docker -H tcp://${SERVICE_HOST}:2375 rm -f picasso-api
179
+RemainAfterExit=true
180
+LimitNOFILE=1048576
181
+LimitNPROC=1048576
182
+LimitCORE=infinity
183
+TimeoutStartSec=0
184
+[Install]
185
+WantedBy=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
+
192
+function start_picasso_api {
193
+    echo_summary "Starting Picasso API"
194
+    sudo systemctl start picasso-api.service
195
+}
196
+
197
+
198
+function stop_picasso_api {
199
+    echo_summary "Stopping Picasso API"
200
+    sudo systemctl stop picasso-api.service
201
+}
202
+
203
+
204
+function start_functions {
205
+    echo_summary "Starting Functions API"
206
+    sudo systemctl start functions-api.service &
207
+}
208
+
209
+
210
+function stop_functions {
211
+    echo_summary "Stopping Functions API"
212
+    sudo systemctl stop functions-api.service &
213
+}
214
+
215
+function install_python_picassoclient {
216
+    git_clone $PICASSO_CLIENT_REPO $PICASSO_CLIENT_DIR $PICASSO_CLIENT_BRANCH
217
+    setup_develop $PICASSO_CLIENT_DIR
218
+}
219
+
220
+if 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
247
+fi
248
+
249
+# Restore xtrace
250
+$XTRACE

+ 30
- 0
devstack/settings View File

@@ -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
7
+PICASSO_REPO=${PICASSO_REPO:-git@github.com:iron-io/picasso.git}
8
+PICASSO_BRANCH=${PICASSO_BRANCH:-master}
9
+PICASSO_DIR=${PICASSO_DIR:-${DEST}/picasso}
10
+PICASSO_PORT=${PICASSO_PORT:-10001}
11
+PICASSO_LOG_LEVEL=${PICASSO_LOG_LEVEL:-DEBUG}
12
+
13
+# Picasso client configuration
14
+PICASSO_CLIENT_REPO=${PICASSO_CLIENT_REPO:-git@github.com:iron-io/python-picassoclient.git}
15
+PICASSO_CLIENT_DIR=${PICASSO_CLIENT_DIR:-${DEST}/python-picassoclient}
16
+PICASSO_CLIENT_BRANCH=${PICASSO_CLIENT_BRANCH:-master}
17
+
18
+# IronFunctions configuration
19
+GOPATH=${GOPATH:-${DEST}/functions}
20
+FUNCTIONS_DIR=${FUNCTIONS_DIR:-${GOPATH}/src/github.com/iron-io/functions}
21
+FUNCTIONS_REPO=${FUNCTIONS_REPO:-git@github.com:iron-io/functions.git}
22
+FUNCTIONS_BRANCH=${FUNCTIONS_BRANCH:-master}
23
+FUNCTIONS_PORT=${FUNCTIONS_PORT:-10501}
24
+FUNCTIONS_DB=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.storage.db?bucket=funcs}
25
+FUNCTIONS_MQ=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.queue.db}
26
+FUNCTIONS_LOG_LEVEL=${FUNCTIONS_LOG_LEVEL:-DEBUG}
27
+
28
+DOCKERD_OPTS=${DOCKER_OPTS:---dns 8.8.8.8 --dns 8.8.4.4 --storage-driver=overlay2}
29
+
30
+enable_service picasso

Loading…
Cancel
Save