Skip to content

Commit 3d079b9

Browse files
author
Matthew Fisher
committed
import deis/server
1 parent f9f60b3 commit 3d079b9

12 files changed

Lines changed: 261 additions & 0 deletions

File tree

controller/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM deis/base:latest
2+
MAINTAINER Gabriel A. Monroy <gabriel@opdemand.com>
3+
4+
# install required system packages
5+
RUN apt-get update
6+
RUN apt-get install -yq python-pip python-dev libpq-dev
7+
8+
# install chef
9+
RUN apt-get install -yq ruby1.9.1 rubygems
10+
RUN gem install --no-ri --no-rdoc chef
11+
12+
# install requirements before ADD to cache layer and speed build
13+
RUN pip install boto==2.23.0 celery==3.1.8 Django==1.6.2 django-allauth==0.15.0 django-guardian==1.1.1 django-json-field==0.5.5 django-yamlfield==0.5 djangorestframework==2.3.12 dop==0.1.4 gevent==1.0 gunicorn==18.0 paramiko==1.12.1 psycopg2==2.5.2 pycrypto==2.6.1 python-etcd==0.3.0 pyrax==1.6.2 PyYAML==3.10 redis==2.8.0 static==1.0.2 South==0.8.4
14+
15+
# clone the project into /app
16+
ADD . /app
17+
18+
# install python requirements
19+
RUN pip install -r /app/requirements.txt
20+
21+
# Create static resources
22+
RUN /app/manage.py collectstatic --settings=deis.settings --noinput
23+
24+
# add a deis user that has passwordless sudo (for now)
25+
RUN useradd deis --groups sudo --home-dir /app --shell /bin/bash
26+
RUN sed -i -e 's/%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=(ALL:ALL) NOPASSWD:ALL/' /etc/sudoers
27+
RUN chown -R deis:deis /app
28+
29+
# create directory for logs
30+
RUN mkdir -p /app/logs && chown -R deis:deis /app/logs
31+
32+
# define the execution environment
33+
CMD ["/app/bin/boot"]
34+
EXPOSE 8000

controller/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
runserver:
2+
python manage.py runserver
3+
4+
db:
5+
python manage.py syncdb --migrate --noinput
6+
7+
test:
8+
python manage.py test --noinput api cm provider web
9+
10+
coverage:
11+
coverage run manage.py test --noinput api cm provider web
12+
coverage html
13+
14+
build:
15+
docker build -t deis/server .
16+
17+
run:
18+
docker run -rm -p $${PORT:-8000}:$${PORT:-8000} -e ETCD=$${ETCD:-127.0.0.1:4001} -name deis-server deis/server ; exit 0
19+
20+
shell:
21+
docker run -t -i -rm -e ETCD=$${ETCD:-127.0.0.1:4001} deis/server /bin/bash
22+
23+
clean:
24+
-docker rmi deis/server
25+
26+
flake8:
27+
flake8

controller/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Deis Server
2+
3+
A Docker image containing a REST API and web server, for use in the [Deis](http://deis.io) open source PaaS.
4+
5+
[![image](https://d207aa93qlcgug.cloudfront.net/img/icons/framed-icon-checked-repository.svg)](https://index.docker.io/u/deis/server/)
6+
7+
[**Trusted Build**](https://index.docker.io/u/deis/server/)
8+
9+
This Docker image is based on the trusted build [deis/base](https://index.docker.io/u/deis/base/), which itself is based on the official [ubuntu:12.04](https://index.docker.io/_/ubuntu/) base image.
10+
11+
Please add any issues you find with this software to the parent [Deis project](https://github.com/opdemand/deis/issues).
12+
13+
## Usage
14+
15+
Coming Soon!
16+
17+
## License
18+
19+
Copyright 2014 OpDemand LLC
20+
21+
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>
22+
23+
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.

controller/bin/boot

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
#
3+
# This script is designed to be run inside the container
4+
#
5+
6+
# configure etcd
7+
export ETCD=${ETCD:-127.0.0.1:4001}
8+
export ETCD_PATH=${ETCD_PATH:-/deis/controller}
9+
export ETCD_TTL=${ETCD_TTL:-10}
10+
11+
# configure service discovery
12+
export HOST=${HOST:-localhost}
13+
export PORT=${PORT:-8000}
14+
export PROTO=${PROTO:-tcp}
15+
16+
# wait for etcd to be available
17+
until etcdctl -C $ETCD ls >/dev/null; do
18+
echo "waiting for etcd at $ETCD..."
19+
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
20+
done
21+
22+
# wait until etcd has discarded potentially stale values
23+
sleep $(($ETCD_TTL+1))
24+
25+
# seed initial service configuration if necessary
26+
$(dirname ${BASH_SOURCE[0]})/seed >/dev/null 2>&1
27+
28+
# wait for confd to run once and install initial templates
29+
until confd -onetime -node $ETCD -config-file /app/confd.toml 2>/dev/null; do
30+
echo "waiting for confd to write initial templates..."
31+
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
32+
done
33+
34+
# wait for confd to populate all values
35+
while grep -q '<no value>' /app/confd_settings.py; do
36+
echo "waiting for confd to write all values..."
37+
confd -onetime -node $ETCD -config-file /app/confd.toml 2>/dev/null
38+
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
39+
done
40+
41+
# perform a one-time reload to install check config
42+
/usr/local/bin/reload
43+
44+
# spawn the service in the background
45+
$(dirname ${BASH_SOURCE[0]})/start &
46+
SERVICE_PID=$!
47+
48+
# smart shutdown on SIGINT and SIGTERM
49+
function on_exit() {
50+
kill -TERM $SERVICE_PID
51+
wait $SERVICE_PID 2>/dev/null
52+
}
53+
trap on_exit INT TERM
54+
55+
# spawn confd in the background to update services based on etcd changes
56+
confd -node $ETCD -config-file /app/confd.toml &
57+
CONFD_PID=$!
58+
59+
# wait for the service to become available
60+
sleep 1 && while [[ -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PORT\" && \$1 ~ \"$PROTO.?\"") ]] ; do sleep 1; done
61+
62+
# as long as the service remains up, keep publishing to etcd with a TTL
63+
$(dirname ${BASH_SOURCE[0]})/publish &
64+
65+
wait

controller/bin/publish

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# configure etcd
4+
ETCD=${ETCD:-127.0.0.1:4001}
5+
ETCD_PATH=${ETCD_PATH:-/deis/controller}
6+
ETCD_TTL=${ETCD_TTL:-10}
7+
8+
# while the port is listening, publish to etcd
9+
while [[ ! -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PORT\" && \$1 ~ \"$PROTO.?\"") ]] ; do
10+
etcdctl -C $ETCD set $ETCD_PATH/host $HOST --ttl $ETCD_TTL >/dev/null
11+
etcdctl -C $ETCD set $ETCD_PATH/port $PORT --ttl $ETCD_TTL >/dev/null
12+
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
13+
done
14+
15+
# if the loop quits, something went wrong
16+
exit 1

controller/bin/seed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# if the keyspace already exists, exit early
5+
etcdctl -C $ETCD ls $ETCD_PATH >/dev/null && exit 0
6+
7+
# otherwise seed initial values
8+
etcdctl -C $ETCD set $ETCD_PATH/protocol ${DEIS_PROTOCOL:-http}
9+
etcdctl -C $ETCD set $ETCD_PATH/secretKey ${DEIS_SECRET_KEY:-`openssl rand -base64 64 | tr -d '\n'`}
10+
etcdctl -C $ETCD set $ETCD_PATH/builderKey ${DEIS_BUILDER_KEY:-`openssl rand -base64 64 | tr -d '\n'`}
11+
etcdctl -C $ETCD set $ETCD_PATH/cmModule ${DEIS_CM_MODULE:-cm.chef}
12+
13+
exit 0

controller/bin/start

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
#
3+
# This script is designed to be run inside the container
4+
#
5+
cd /app
6+
7+
# run an idempotent database migration
8+
sudo -E -u deis ./manage.py syncdb --migrate --noinput
9+
10+
# spawn a gunicorn server in the foreground
11+
sudo -E -u deis ./manage.py run_gunicorn -b 0.0.0.0 -w 8 -t 600 -n deis --log-level debug # -k gevent
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[template]
2+
src = "confd_settings.py"
3+
dest = "/app/confd_settings.py"
4+
uid = 1000
5+
gid = 1000
6+
mode = "0640"
7+
keys = [
8+
"/deis",
9+
]

controller/conf.d/reload.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[template]
2+
src = "reload"
3+
dest = "/usr/local/bin/reload"
4+
owner = "root"
5+
group = "root"
6+
mode = "0755"
7+
keys = [
8+
"/deis/controller",
9+
"/deis/chef",
10+
]
11+
check_cmd = "test -e {{ .src }}"
12+
reload_cmd = "/usr/local/bin/reload"

controller/confd.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[confd]
2+
confdir = "/app"
3+
interval = 5
4+
prefix = "/"
5+
quiet = true

0 commit comments

Comments
 (0)