├── Dockerfile ├── LICENSE ├── README.md ├── build.it ├── docker-compose.yml ├── example.nomad └── tmux.conf /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:edge 2 | MAINTAINER wsielski@eaby.com 3 | 4 | ENV CONSUL_VERSION 0.8.0 5 | ENV NOMAD_VERSION 0.5.6 6 | ENV FABIO_VERSION 1.4.2 7 | 8 | ENV GOLANG_VERSION 1.8.1 9 | ENV GOLANG_SRC_URL https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz 10 | ENV GOLANG_SRC_SHA256 33daf4c03f86120fdfdc66bddf6bfff4661c7ca11c5da473e537f4d69b470e57 11 | 12 | # Compile and install nomad, consul and fabio. 13 | RUN set -ex \ 14 | && echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ 15 | && apk update; apk upgrade \ 16 | && apk add --no-cache --virtual .build-deps \ 17 | bash \ 18 | go \ 19 | curl \ 20 | make \ 21 | git \ 22 | gcc \ 23 | musl-dev \ 24 | openssl \ 25 | openssl-dev \ 26 | \ 27 | # Compile go \ 28 | \ 29 | && export GOROOT_BOOTSTRAP="$(go env GOROOT)" \ 30 | && wget -q "$GOLANG_SRC_URL" -O golang.tar.gz \ 31 | && echo "$GOLANG_SRC_SHA256 golang.tar.gz" | sha256sum -c - \ 32 | && tar -C /usr/local -xzf golang.tar.gz \ 33 | && rm golang.tar.gz \ 34 | && cd /usr/local/go/src \ 35 | && ./make.bash \ 36 | \ 37 | && export PATH=$GOPATH/bin:/usr/local/go/bin:$PATH \ 38 | && mkdir /go \ 39 | && cd /go \ 40 | && ln -s . src \ 41 | && export GOPATH=/go \ 42 | && go get github.com/Masterminds/glide \ 43 | && cp /go/bin/* /usr/local/bin \ 44 | \ 45 | # Compile fabio, nomad, consul \ 46 | \ 47 | && glide create --skip-import --non-interactive \ 48 | && glide get github.com/eBay/fabio#v${FABIO_VERSION} \ 49 | && glide get github.com/hashicorp/nomad#v${NOMAD_VERSION} \ 50 | && glide get github.com/hashicorp/consul#v${CONSUL_VERSION} \ 51 | && glide update --all-dependencies \ 52 | && go build vendor/github.com/hashicorp/consul \ 53 | && go build vendor/github.com/eBay/fabio \ 54 | && go build vendor/github.com/hashicorp/nomad \ 55 | && mv consul fabio nomad /usr/local/bin \ 56 | \ 57 | # Cleanup \ 58 | \ 59 | && rm -rf /go \ 60 | && apk del .build-deps \ 61 | && rm -rf /usr/local/go \ 62 | && rm -rf /var/cache/apk/* \ 63 | && rm -rf /root/.glide \ 64 | && rm /usr/local/bin/glide 65 | 66 | # Install tmux and example for demo 67 | # 68 | RUN apk update; apk add tmux \ 69 | && rm -rf /var/cache/apk/* \ 70 | && ln -s /dev/console /0 \ 71 | && ln -s /dev/tty1 /1 72 | ADD tmux.conf /etc/tmux.conf 73 | ADD example.nomad / 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 eBay Classifieds Group 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KomPaaS 2 | 3 | Compact PaaS - PoC - playgroud mode - small based golang app PaaS closed in one container 4 | 5 | [Watch](https://www.youtube.com/watch?v=gf43TcWjBrE&list=PL81sUbsFNc5b-Gd59Lpz7BW0eHJBt0GvE&index=1) Kelsey Hightower demo Consul, Nomad, Vault and fabio at HashiConf EU 2016. 6 | 7 | * Requirements: 8 | * docker 1.9 or higher 9 | * `docker pull python:alpine` #(only for an example) 10 | 11 | * Components: 12 | * Nomad 13 | * Consul 14 | * Fabio 15 | * Nomad-ui jippi version (with docker-compose only) 16 | 17 | * Most important ports: 18 | 19 | service | port 20 | ---------|----- 21 | Consul UI| 8500 22 | Fabio UI| 9998 23 | Nomad UI| 3000 24 | Fabio router | 9999 25 | 26 | 27 | ## Build image or get it 28 | ```bash 29 | $ ./build.it 30 | ``` 31 | or 32 | ```bash 33 | $ docker pull kompaas/kompaas 34 | ``` 35 | 36 | ## Usage: 37 | ### interactive: 38 | (tmux knowledge required) 39 | ```bash 40 | $ docker run \ 41 | --net=host \ 42 | --privileged \ 43 | --volume "/var/run/docker.sock:/var/run/docker.sock" \ 44 | --volume "/tmp:/tmp" \ 45 | -ti kompaas/kompaas tmux attach 46 | ``` 47 | ### docker compose: 48 | ```bash 49 | $ docker-compose up -d 50 | Creating kompaas_consul_1 51 | Creating kompaas_nomad_1 52 | Creating kompaas_fabio_1 53 | Creating kompaas_nui_1 54 | ``` 55 | 56 | ## Start example 57 | if you run tmux: 58 | ```bash 59 | $ nomad run example.nomad 60 | ``` 61 | else: 62 | ```bash 63 | $ docker exec -ti kompaas_nomad_1 nomad run example.nomad 64 | ==> Monitoring evaluation "cbbea755" 65 | Evaluation triggered by job "example" 66 | Allocation "b00798bf" created: node "4522e2f4", group "python" 67 | Allocation "64a73a0f" created: node "4522e2f4", group "python" 68 | Allocation "669afa7b" created: node "4522e2f4", group "python" 69 | Allocation "80de4c42" created: node "4522e2f4", group "python" 70 | Evaluation status changed: "pending" -> "complete" 71 | ==> Evaluation "cbbea755" finished with status "complete" 72 | 73 | $ docker ps 74 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 75 | 5920ecba205e python:alpine "/bin/sh -c 'echo $HO" 7 seconds ago Up 6 seconds 127.0.0.1:31873->8000/tcp, 127.0.0.1:31873->8000/udp server-64a73a0f-5999-fcc2-6aa6-b1cf228d1b74 76 | 91a51e1ced32 python:alpine "/bin/sh -c 'echo $HO" 7 seconds ago Up 6 seconds 127.0.0.1:42008->8000/tcp, 127.0.0.1:42008->8000/udp server-80de4c42-4786-2c09-40c9-69002c7f79b4 77 | f1ea7b8984ef python:alpine "/bin/sh -c 'echo $HO" 7 seconds ago Up 6 seconds 127.0.0.1:28821->8000/tcp, 127.0.0.1:28821->8000/udp server-b00798bf-8b32-c40a-a5fb-6496c7112748 78 | 66df4804ee1e python:alpine "/bin/sh -c 'echo $HO" 7 seconds ago Up 6 seconds 127.0.0.1:55579->8000/tcp, 127.0.0.1:55579->8000/udp server-669afa7b-8f33-9dbd-0f21-c83ccf369485 79 | 557511c14cf5 kompaas/kompaas "fabio" 17 seconds ago Up 16 seconds kompaas_fabio_1 80 | b538488d26ac kompaas/kompaas "consul agent -client" 17 seconds ago Up 16 seconds kompaas_consul_1 81 | 0f643244ef92 kompaas/kompaas "nomad agent -dev" 17 seconds ago Up 16 seconds kompaas_nomad_1 82 | e30d12884ce5 jippi/nomad-ui "apache2-foreground" 17 seconds ago Up 16 seconds kompaas_nui_1 83 | ``` 84 | 85 | ## Test example 86 | ```bash 87 | $ while true; do 88 | curl -H 'Host: python.service.consul' http://localhost:9999 89 | done 90 | ``` 91 | -------------------------------------------------------------------------------- /build.it: -------------------------------------------------------------------------------- 1 | [ ${http_proxy} ] && PROXY="--build-arg http_proxy=${http_proxy}" 2 | [ ${https_proxy} ] && PROXY="${PROXY} --build-arg https_proxy=${https_proxy}" 3 | docker build --rm=true ${PROXY} --tag=kompaas/kompaas . 4 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | consul: 2 | image: kompaas/kompaas 3 | net: host 4 | privileged: true 5 | command: "consul agent -client=0.0.0.0 -data-dir=/opt/consul/ -ui -advertise=127.0.0.1 -dc=dc1 -server -bootstrap-expect 1" 6 | 7 | nomad: 8 | image: kompaas/kompaas 9 | net: host 10 | privileged: true 11 | command: "nomad agent -dev" 12 | ports: 13 | - "4646:4646" 14 | volumes: 15 | - "/var/run/docker.sock:/var/run/docker.sock" 16 | - "/tmp:/tmp" 17 | 18 | fabio: 19 | image: kompaas/kompaas 20 | net: host 21 | privileged: true 22 | command: "fabio" 23 | 24 | nui: 25 | image: jippi/hashi-ui 26 | entrypoint: "sh -c 'sleep 10;exec /hashi-ui'" 27 | net: host 28 | environment: 29 | NOMAD_ENABLE: "true" 30 | CONSUL_ENABLE: "true" 31 | -------------------------------------------------------------------------------- /example.nomad: -------------------------------------------------------------------------------- 1 | job "example" { 2 | datacenters = ["dc1"] 3 | #constraint { 4 | # attribute = "$attr.kernel.name" 5 | # value = "linux" 6 | #} 7 | update { 8 | stagger = "10s" 9 | max_parallel = 2 10 | } 11 | group "python" { 12 | count = 4 13 | restart { 14 | interval = "5m" 15 | attempts = 10 16 | delay = "2s" 17 | mode = "delay" 18 | } 19 | task "server" { 20 | driver = "docker" 21 | config { 22 | image = "python:alpine" 23 | command= "/bin/sh" 24 | args = ["-c", "echo hello from $HOSTNAME >index.html && python3 -m http.server 8000"] 25 | port_map { 26 | myhttp = 8000 27 | } 28 | } 29 | service { 30 | tags = ["global", "urlprefix-python/", "urlprefix-python.service.consul/"] 31 | port = "myhttp" 32 | check { 33 | name = "alive" 34 | type = "tcp" 35 | interval = "10s" 36 | timeout = "2s" 37 | } 38 | } 39 | resources { 40 | cpu = 500 # 500 Mhz 41 | memory = 256 # 256MB 42 | network { 43 | mbits = 10 44 | port "myhttp" { 45 | } 46 | } 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tmux.conf: -------------------------------------------------------------------------------- 1 | # KomPaaS debug standelone session 2 | #new -s KomPaaS -n KomPaaS 'consul agent -client=0.0.0.0 -data-dir=/opt/consul/ -ui -advertise=127.0.0.1 -node=$HOSTNAME -dc=dc1 -server -bootstrap-expect 1 2>&1' 3 | new -s KomPaaS -n KomPaaS 'consul agent -client=0.0.0.0 -data-dir=/opt/consul/ -ui -advertise=127.0.0.1 -node=$HOSTNAME -server -bootstrap-expect 1 2>&1' 4 | splitw -v -p 40 5 | selectp -t 0 6 | splitw -h -p 66 -t 0 'nomad agent -dev 2>&1' 7 | splitw -h -p 50 -t 1 'fabio 2>&1' 8 | selectp -t 3 9 | --------------------------------------------------------------------------------