diff --git a/projects/demo/etcd/Dockerfile b/projects/demo/etcd/Dockerfile new file mode 100644 index 000000000..bee96b5dd --- /dev/null +++ b/projects/demo/etcd/Dockerfile @@ -0,0 +1,6 @@ +# A dockerfile to build an etcd container image from the upstream one +# with a script as entry point +FROM quay.io/coreos/etcd:v3.1.5 +COPY ./etcd.sh / + +ENTRYPOINT ["/etcd.sh"] diff --git a/projects/demo/etcd/README.md b/projects/demo/etcd/README.md new file mode 100644 index 000000000..ac80b9246 --- /dev/null +++ b/projects/demo/etcd/README.md @@ -0,0 +1,20 @@ +This directory contains scripts/files to bootstrap a `etcd` cluster. + +In the local, hyperkit based, setup, we use a `etcd` running in a +Docker for Mac container to bootstrap the cluster. For a cloud based demo, we'd use `https://discovery.etcd.io`. The host/DfM side is setup with [dfm-setup.sh](./dfm-setup.sh). + +The moby `etcd` package is build with [build-pkg.sh](./build-pkg.sh). It take the official `etcd` container and adds a [script](./etcd.sh) to start `etcd`. + +To run (for now): + +- Start the etcd bootstrap container in on window: +``` +./dfm-setup.sh +``` + +- In another window build/run the moby image: +``` +./build-pkg.sh +moby build etcd +moby run etcd +``` diff --git a/projects/demo/etcd/build-pkg.sh b/projects/demo/etcd/build-pkg.sh new file mode 100755 index 000000000..1142c2133 --- /dev/null +++ b/projects/demo/etcd/build-pkg.sh @@ -0,0 +1,2 @@ +#! /bin/sh +docker build -t mobylinux/etcd . diff --git a/projects/demo/etcd/dfm-setup.sh b/projects/demo/etcd/dfm-setup.sh new file mode 100755 index 000000000..f7e6fd8a0 --- /dev/null +++ b/projects/demo/etcd/dfm-setup.sh @@ -0,0 +1,46 @@ +#! /bin/sh +## +## This script starts a etcd container which is used to bootstrap a +## local etcd cluster. The etcd container is started on a non-standard +## port to keep the standard port free for the cluster. +## +## If you have a local etcd installed (brew install etcd) you can +## point the cli at it as well: +## +## etcdctl --debug --endpoints http://0.0.0.0:2381 member list +## + +# debug +set -x +set -v + +# Change depending on the cluster size +NUMPEERS=1 + +# Start a local etcd for bootstrapping +NAME=etcd-bootstrap +PORT=2381 + +#UUID=$(uuidgen) +UUID=6c007a14875d53d9bf0ef5a6fc0257c817f0fb83 + +ID=$(docker run -d --rm --name ${NAME} \ + -p ${PORT}:${PORT} \ + quay.io/coreos/etcd:v3.1.5 /usr/local/bin/etcd \ + --debug \ + --name ${NAME} \ + --listen-client-urls http://0.0.0.0:${PORT} \ + --advertise-client-urls http://0.0.0.0:$PORT,http://192.168.65.2:$PORT \ + --initial-cluster-token ${NAME} \ + --initial-cluster-state new \ + --auto-compaction-retention 0) + +trap "docker kill ${ID}" 2 + +# Could poll until returns without error, but sleep for 2s for now +sleep 2 +docker exec -t ${ID} etcdctl --endpoints http://0.0.0.0:${PORT} mk discovery/${UUID}/_config/size ${NUMPEERS} + +echo "KEY: ${UUID}" + +docker logs -f ${ID} diff --git a/projects/demo/etcd/etcd.sh b/projects/demo/etcd/etcd.sh new file mode 100755 index 000000000..8baa9eb4b --- /dev/null +++ b/projects/demo/etcd/etcd.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +# debug +set -x +set -v + +# Needs to come from metadata +UUID=6c007a14875d53d9bf0ef5a6fc0257c817f0fb83 +DISCOVER_URL=http://192.168.65.2:2381/v2/keys/discovery/${UUID} + +IP=$(ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://') +NAME=$(hostname) + +/usr/local/bin/etcd \ + --name ${NAME} \ + --debug \ + --log-package-levels etcdmain=DEBUG,etcdserver=DEBUG \ + --initial-advertise-peer-urls http://${IP}:2380 \ + --listen-peer-urls http://${IP}:2380 \ + --listen-client-urls http://${IP}:2379,http://127.0.0.1:2379 \ + --advertise-client-urls http://${IP}:2379 \ + --discovery ${DISCOVER_URL} diff --git a/projects/demo/etcd/etcd.yml b/projects/demo/etcd/etcd.yml new file mode 100644 index 000000000..07897d3bf --- /dev/null +++ b/projects/demo/etcd/etcd.yml @@ -0,0 +1,31 @@ +kernel: + image: "mobylinux/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: "mobylinux/init:00c3a5bbfd9794f4a3187fcc4a9f0c826c46d474" +system: + - name: sysctl + image: "mobylinux/sysctl:2cf2f9d5b4d314ba1bfc22b2fe931924af666d8c" + net: host + pid: host + ipc: host + capabilities: + - CAP_SYS_ADMIN + readonly: true +daemon: + - name: rngd + image: "mobylinux/rngd:3dad6dd43270fa632ac031e99d1947f20b22eec9@sha256:1c93c1db7196f6f71f8e300bc1d15f0376dd18e8891c8789d77c8ff19f3a9a92" + capabilities: + - CAP_SYS_ADMIN + oomScoreAdj: -800 + readonly: true + - name: etcd + image: "mobylinux/etcd" + capabilities: + - CAP_NET_BIND_SERVICE + - CAP_CHOWN + - CAP_SETUID + - CAP_SETGID + - CAP_DAC_OVERRIDE + net: host +outputs: + - format: kernel+initrd diff --git a/projects/demo/infrakit/infrakit.json b/projects/demo/infrakit/infrakit.json new file mode 100644 index 000000000..39c3e67dd --- /dev/null +++ b/projects/demo/infrakit/infrakit.json @@ -0,0 +1,30 @@ +{ + "ID": "cattle", + "Properties": { + "Allocation": { + "Size": 5 + }, + "Instance": { + "Plugin": "instance-hyperkit", + "Properties": { + "Moby": "nginx-4.10", + "Disk" : 512, + "CPUs" : 2, + "Memory" : 1024 + } + }, + "Flavor": { + "Plugin": "flavor-vanilla", + "Properties": { + "Init": [ + "test1", + "test2" + ], + "Tags": { + "tier": "sample", + "project": "infrakit" + } + } + } + } +} diff --git a/projects/demo/infrakit/nginx-4.10.yml b/projects/demo/infrakit/nginx-4.10.yml new file mode 100644 index 000000000..38e85b7bf --- /dev/null +++ b/projects/demo/infrakit/nginx-4.10.yml @@ -0,0 +1,27 @@ +kernel: + image: "mobylinux/kernel:4.10.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: "mobylinux/init:00c3a5bbfd9794f4a3187fcc4a9f0c826c46d474" +system: + - name: sysctl + image: "mobylinux/sysctl:2cf2f9d5b4d314ba1bfc22b2fe931924af666d8c" + net: host + pid: host + ipc: host + capabilities: + - CAP_SYS_ADMIN + readonly: true +daemon: + - name: nginx + image: "nginx:alpine" + capabilities: + - CAP_NET_BIND_SERVICE + - CAP_CHOWN + - CAP_SETUID + - CAP_SETGID + - CAP_DAC_OVERRIDE + net: host +outputs: + - format: kernel+initrd + - format: iso-bios + - format: iso-efi diff --git a/projects/demo/infrakit/nginx.yml b/projects/demo/infrakit/nginx.yml new file mode 100644 index 000000000..83d756594 --- /dev/null +++ b/projects/demo/infrakit/nginx.yml @@ -0,0 +1,27 @@ +kernel: + image: "mobylinux/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: "mobylinux/init:00c3a5bbfd9794f4a3187fcc4a9f0c826c46d474" +system: + - name: sysctl + image: "mobylinux/sysctl:2cf2f9d5b4d314ba1bfc22b2fe931924af666d8c" + net: host + pid: host + ipc: host + capabilities: + - CAP_SYS_ADMIN + readonly: true +daemon: + - name: nginx + image: "nginx:alpine" + capabilities: + - CAP_NET_BIND_SERVICE + - CAP_CHOWN + - CAP_SETUID + - CAP_SETGID + - CAP_DAC_OVERRIDE + net: host +outputs: + - format: kernel+initrd + - format: iso-bios + - format: iso-efi diff --git a/projects/demo/intro/intro.yml b/projects/demo/intro/intro.yml new file mode 100644 index 000000000..83d756594 --- /dev/null +++ b/projects/demo/intro/intro.yml @@ -0,0 +1,27 @@ +kernel: + image: "mobylinux/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: "mobylinux/init:00c3a5bbfd9794f4a3187fcc4a9f0c826c46d474" +system: + - name: sysctl + image: "mobylinux/sysctl:2cf2f9d5b4d314ba1bfc22b2fe931924af666d8c" + net: host + pid: host + ipc: host + capabilities: + - CAP_SYS_ADMIN + readonly: true +daemon: + - name: nginx + image: "nginx:alpine" + capabilities: + - CAP_NET_BIND_SERVICE + - CAP_CHOWN + - CAP_SETUID + - CAP_SETGID + - CAP_DAC_OVERRIDE + net: host +outputs: + - format: kernel+initrd + - format: iso-bios + - format: iso-efi