From 4a99539ca43b7b845298260723ee7389bd29f7fa Mon Sep 17 00:00:00 2001 From: "Munoz, Obed N" Date: Fri, 21 Oct 2016 09:42:59 -0500 Subject: [PATCH] Add ciao launcher container Signed-off-by: Munoz, Obed N --- launcher/Dockerfile | 9 +++ launcher/README.md | 66 +++++++++++++++ launcher/dnsmasq.conf.macvlan0 | 25 ++++++ launcher/generate_cnci_cloud_image.sh | 111 ++++++++++++++++++++++++++ launcher/launcher.sh | 21 +++++ 5 files changed, 232 insertions(+) create mode 100644 launcher/Dockerfile create mode 100644 launcher/README.md create mode 100644 launcher/dnsmasq.conf.macvlan0 create mode 100755 launcher/generate_cnci_cloud_image.sh create mode 100755 launcher/launcher.sh diff --git a/launcher/Dockerfile b/launcher/Dockerfile new file mode 100644 index 0000000..f8357b1 --- /dev/null +++ b/launcher/Dockerfile @@ -0,0 +1,9 @@ +FROM clearlinux/ciao-common +MAINTAINER obed.n.munoz@intel.com + +ARG swupd_args + +COPY *.sh /root/ +COPY dnsmasq.conf.macvlan0 /etc/dnsmasq.conf + +CMD '/root/launcher.sh' diff --git a/launcher/README.md b/launcher/README.md new file mode 100644 index 0000000..3c64f47 --- /dev/null +++ b/launcher/README.md @@ -0,0 +1,66 @@ +CIAO Launcher +============= +[![](https://images.microbadger.com/badges/image/clearlinux/ciao-launcher.svg)](http://microbadger.com/images/clearlinux/ciao-launcher "Get your own image badge on microbadger.com") +[![](https://images.microbadger.com/badges/version/clearlinux/ciao-launcher.svg)](http://microbadger.com/images/clearlinux/launcher "Get your own version badge on microbadger.com") + +This provides a CIAO Launcher container + +Features +-------- +- From source building solution +- Daemon and Manual service start mode +- You mess it, just destroy it and start it again +- Develop on you local development machine and deploy it on container + +Build +----- +``` +docker build -t clearlinux/ciao-launcher . +``` + +Or just pull it from Dockerhub +------------------------------ +``` +docker pull clearlinux/ciao-launcher +``` + +Start CIAO Launcher container +----------------------------- +### Run in daemon mode +``` +docker run -it -d --name launcher --net=host --privileged -v /dev/kvm:/dev/kvm \ + -v /dev:/dev -v /var/run/docker.sock:/var/run/docker.sock \ + --cap-add=NET_ADMIN --device /dev/net/tun:/dev/net/tun \ + -v `pwd`/certs/CAcert-localhost.pem:/etc/pki/ciao/CAcert-ciao-dev.pem \ + -v `pwd`/certs/cert-CNAgent-NetworkingAgent-localhost.pem:/etc/pki/ciao/cert-CNAgent-NetworkingAgent-ciao-dev.pem \ + -v $GOPATH/src/github.com/01org/ciao:/root/go/src/github.com/01org/ciao \ + ciao/launcher +``` + +### Run on manual mode +``` +docker run -it --name launcher --net=host --privileged -v /dev/kvm:/dev/kvm \ + -v /dev:/dev -v /var/run/docker.sock:/var/run/docker.sock \ + --cap-add=NET_ADMIN --device /dev/net/tun:/dev/net/tun \ + -v `pwd`/certs/CAcert-localhost.pem:/etc/pki/ciao/CAcert-ciao-dev.pem \ + -v `pwd`/certs/cert-CNAgent-NetworkingAgent-localhost.pem:/etc/pki/ciao/cert-CNAgent-NetworkingAgent-ciao-dev.pem \ + -v $GOPATH/src/github.com/01org/ciao:/root/go/src/github.com/01org/ciao \ + ciao/launcher bash + +# Inside container +root@example.com # ls +ciaorc go launcher.sh share + +# Manual Start of Ciao Launcher +root@example.com # ./launcher.sh +``` + +Environment Variables +--------------------- + + +Extra Build ARGs +---------------- +- ``swupd_args`` Specifies [SWUPD](https://clearlinux.org/documentation/swupdate_how_to_run_the_updater.html) flags + +Default build args in Docker are on: https://docs.docker.com/engine/reference/builder/#/arg diff --git a/launcher/dnsmasq.conf.macvlan0 b/launcher/dnsmasq.conf.macvlan0 new file mode 100644 index 0000000..4b75e67 --- /dev/null +++ b/launcher/dnsmasq.conf.macvlan0 @@ -0,0 +1,25 @@ +# Only listen to routers' LAN NIC. Doing so opens up tcp/udp port 53 to +# localhost and udp port 67 to world: +interface=macvlan0 + +listen-address=192.168.0.1 + +# dnsmasq will open tcp/udp port 53 and udp port 67 to world to help with +# dynamic interfaces (assigning dynamic ips). Dnsmasq will discard world +# requests to them, but the paranoid might like to close them and let the +# kernel handle them: +bind-interfaces + +# Dynamic range of IPs to make available to LAN pc +dhcp-range=192.168.0.50,192.168.0.100,12h + +# If you’d like to have dnsmasq assign static IPs, bind the LAN computer's +# NIC MAC address: + +except-interface=lo + +log-queries + +log-dhcp + +#dhcp-host=aa:bb:cc:dd:ee:ff,192.168.111.50 diff --git a/launcher/generate_cnci_cloud_image.sh b/launcher/generate_cnci_cloud_image.sh new file mode 100755 index 0000000..faf3d71 --- /dev/null +++ b/launcher/generate_cnci_cloud_image.sh @@ -0,0 +1,111 @@ +#!/bin/bash +#Defaults + +set -x +image="clear-8260-ciao-networking.img" +certs_dir=$GOPATH/src/github.com/01org/ciao/networking/ciao-cnci-agent/scripts/certs +cnci_agent=$GOPATH/bin/ciao-cnci-agent +cnci_sysd=$GOPATH/src/github.com/01org/ciao/networking/ciao-cnci-agent/scripts/ciao-cnci-agent.service +partition="2" +download=0 + +usage="$(basename "$0") [--image clear_cnci_image_name] [-certs certificate_directory] [-agent cnci_agent_binary] [-script cnci_systemd_script] \n\n A simple script to create a CNCI Image from a clear cloud image. \n Defaults for any unspecified option are as follows \n\n --agent $cnci_agent \n --certs $certs_dir \n --image $image \n --script $cnci_sysd\n\n" + + +while : +do + case "$1" in + -a | --agent) + cnci_agent="$2" + shift 2 + ;; + -c | --certs) + certs_dir="$2" + shift 2 + ;; + -d | --download) + download=1 + shift 1 + ;; + -h | --help) + echo -e "$usage" >&2 + exit 0 + ;; + -i | --image) + image="$2" + shift 2 + ;; + -s | --script) + cnci_sysd="$2" + shift 2 + ;; + *) + break + ;; + esac +done + +set -o nounset + +if [ $download -eq 1 ] +then + rm -f "$image" + curl -O https://download.clearlinux.org/demos/ciao/"$image".xz + unxz "$image".xz +fi + +echo -e "\nMounting image: $image" +tmpdir=$(mktemp -d) +#sudo modprobe nbd max_part=63 +#sudo qemu-nbd --format=raw -c /dev/nbd0 "$image" + +#it can take some time for the device to get created +retry=0 +loop='' +until [ $retry -ge 3 ] +do + if [ "$loop" == "" ]; then + loop=`sudo losetup -f --show -P $image` + fi + sudo mount ${loop}p$partition "$tmpdir" && break + let retry=retry+1 + echo "Mount failed, retrying $retry" + sleep 10 +done + +if [ $retry -ge 3 ] +then + echo "Unable to mount CNCI Image" + return 1 +fi + +echo -e "Cleaning up any artifacts" +sudo rm -rf "$tmpdir"/var/lib/ciao + +echo -e "Copying agent image" +sudo cp "$cnci_agent" "$tmpdir"/usr/sbin/ + +echo -e "Copying agent systemd service script" +sudo cp "$cnci_sysd" "$tmpdir"/usr/lib/systemd/system/ + +echo -e "Installing the service" +sudo mkdir -p "$tmpdir"/etc/systemd/system/default.target.wants +sudo rm -f "$tmpdir"/etc/systemd/system/default.target.wants/ciao-cnci-agent.service +sudo chroot "$tmpdir" /bin/bash -c "sudo ln -s /usr/lib/systemd/system/ciao-cnci-agent.service /etc/systemd/system/default.target.wants/" + +echo -e "Copying CA certificates" +sudo mkdir -p "$tmpdir"/var/lib/ciao/ +sudo cp "$certs_dir"/CAcert-* "$tmpdir"/var/lib/ciao/CAcert-server-localhost.pem + +echo -e "Copying CNCI Agent certificate" +sudo cp "$certs_dir"/cert-CNCIAgent-* "$tmpdir"/var/lib/ciao/cert-client-localhost.pem + +echo -e "Removing cloud-init traces" +sudo rm -rf "$tmpdir"/var/lib/cloud + +#Umount +echo -e "Done! unmounting\n" +sudo umount "$tmpdir" +sudo losetup -d $loop +sudo rm -rf "$tmpdir" +exit 0 diff --git a/launcher/launcher.sh b/launcher/launcher.sh new file mode 100755 index 0000000..bef10c3 --- /dev/null +++ b/launcher/launcher.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -x + +# Copy images +mkdir -p /var/lib/ciao/images +if [ ! "$(ls -A /var/lib/ciao/images)" ]; then + cp -r /share/images/* /var/lib/ciao/images/ +fi + +# compile the code before running it +go install github.com/01org/ciao/... +cp -f $GOBIN/* /usr/bin + +# Starting Compute Service +mkdir -p /var/lib/misc +mkdir -p /var/run + +killall -9 dnsmasq +dnsmasq -C /etc/dnsmasq.conf + +$GOBIN/ciao-launcher -logtostderr -v=3