From 0699037e09e716a17a77dbfc38c3ca553a583775 Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Tue, 20 Jun 2017 17:19:25 +0200 Subject: [PATCH] Add script to start AGL worker XDS docker container. Signed-off-by: Sebastien Douheret --- scripts/xds-docker-create-container.sh | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 scripts/xds-docker-create-container.sh diff --git a/scripts/xds-docker-create-container.sh b/scripts/xds-docker-create-container.sh new file mode 100755 index 0000000..c4bbdee --- /dev/null +++ b/scripts/xds-docker-create-container.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +########################################## +# WARNING WARNING WARNING WARNING +# +# This script is an example to start a new AGL XDS container +# +# You should customize it to fit your environment and in particular +# adjust the paths and permissions where needed. +# +# Note that sharing volumes with host system is not mandatory: it +# was just added for performances reasons: building from a SSD is +# just faster than using the container filesystem: that's why /xdt is +# mounted from there. Same applies to ~/mirror and ~/share, which are +# just 2 convenient folders to store reference build caches (used in prepare_meta script) +# +########################################## + +CURDIR=$(cd $(dirname $0) && pwd -P) + +REGISTRY=docker.automotivelinux.org +REPO=agl +NAME=worker +FLAVOUR=xds +VERSION=3.99.1 + +# --------------------------------------------------- +# --- computed - don't touch ! +# --------------------------------------------------- +DOCKER_USER=devel + +DEFIMAGE=$REGISTRY/$REPO/$NAME-$FLAVOUR:$VERSION + +function usage() { + echo "Usage: $(basename $0) [image name]" >&2 + echo "Instance ID must be 0 or a positive integer (1,2,...)" >&2 + echo "Image name is optional: 'make show-image' is used by default to get image" >&2 + echo "Default image: $DEFIMAGE" >&2 + exit 1 +} + +ID="" +IMAGE=$DEFIMAGE +FORCE=false +while [ $# -ne 0 ]; do + case $1 in + -h|--help|"") + usage + ;; + -fr|-force-restart) + FORCE=true + ;; + *[0-9]*) + ID=$1 + ;; + *) + IMAGE=$1 + ;; + esac + shift +done + +[ "$ID" = "" ] && usage + +USER=$(id -un) +echo "Using instance ID #$ID (user $(id -un))" + +NAME=agl-xds-$(hostname|cut -f1 -d'.')-$ID-$USER + +MIRRORDIR=$HOME/ssd/localmirror_$ID +XDTDIR=$HOME/ssd/xdt_$ID +SHAREDDIR=$HOME/$DOCKER_USER/docker/share + +SSH_PORT=$((2222 + ID)) +WWW_PORT=$((8000 + ID)) +BOOT_PORT=$((69 + ID)) +NBD_PORT=$((10809 + ID)) + +mkdir -p $MIRRORDIR $XDTDIR $SHAREDDIR +docker run \ + --publish=${SSH_PORT}:22 \ + --publish=${WWW_PORT}:8000 \ + --publish=${BOOT_PORT}:69/udp \ + --publish=${NBD_PORT}:10809 \ + --detach=true \ + --hostname=$NAME --name=$NAME \ + --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ + -v $MIRRORDIR:/home/$DOCKER_USER/mirror \ + -v $SHAREDDIR:/home/$DOCKER_USER/share \ + -v $XDTDIR:/xdt \ + -it $IMAGE + +if ($FORCE); then + echo "Stoping xds-server..." + docker exec --user $DOCKER_USER ${NAME} bash -c "/usr/local/bin/xds-server-stop.sh" + sleep 1 + echo "Starting xds-server..." + docker exec --user $DOCKER_USER ${NAME} bash -c "nohup /usr/local/bin/xds-server-start.sh" +fi + +echo "You can now login using:" +echo " ssh -p $SSH_PORT $DOCKER_USER@$(hostname)" -- 2.16.6