X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Ffull_install_osm.sh;h=f96bfae092f7916243f0d232b789218025655b05;hb=13d76c8224da1ff6ad5181a03af9f4085dae95d4;hp=0573759cf4e6ce438c17caf6c067300d583005ff;hpb=70502ad95df25efa50b3e086d700bfd48106f10d;p=osm%2Fdevops.git diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 0573759c..f96bfae0 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -26,12 +26,23 @@ function usage(){ echo -e " -b v2.0 (v2.0 branch)" echo -e " -b tags/v1.1.0 (a specific tag)" echo -e " ..." + echo -e " -s user defined stack name, default is osm" + echo -e " -H use specific juju host controller IP" + echo -e " -S use VCA/juju secret key" echo -e " --vimemu: additionally deploy the VIM emulator as a docker container" echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging" echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)" - echo -e " -o : do not install OSM, but ONLY one of the addons (vimemu, elk_stack, pm_stack) (assumes OSM is already installed)" + echo -e " -m : install OSM but only rebuild the specified docker images (RO, LCM, NBI, LW-UI, MON, KAFKA, MONGO, NONE)" + echo -e " -o : ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)" echo -e " -D use local devops installation path" + echo -e " -w Location to store runtime installation" + echo -e " -t specify osm docker tag (default is latest)" echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)" + echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)" + echo -e " --nojuju: do not juju, assumes already installed" + echo -e " --nodockerbuild:do not build docker images (use existing locally cached images)" + echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)" + echo -e " --nohostclient: do not install the osmclient" echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" echo -e " --source: install OSM from source code using the latest stable tag" echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch" @@ -70,9 +81,45 @@ function uninstall(){ return 0 } +# takes a juju/accounts.yaml file and returns the password specific +# for a controller. I wrote this using only bash tools to minimize +# additions of other packages +function parse_juju_password { + password_file="${HOME}/.local/share/juju/accounts.yaml" + local controller_name=$1 + local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034') + sed -ne "s|^\($s\):|\1|" \ + -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file | + awk -F$fs -v controller=$controller_name '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i /dev/null"; then + # Not found created, create the controller + sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost $OSM_STACK_NAME" + fi + [ $(sg lxd -c "juju controllers" | awk "/^${OSM_STACK_NAME}[\*| ]/{print $1}"|wc -l) -eq 1 ] || FATAL "Juju installation failed" } function generate_docker_images() { echo "Pulling and generating docker images" - newgrp docker << EONG - docker pull wurstmeister/kafka - docker pull wurstmeister/zookeeper - docker pull mongo - docker pull mysql:5 -EONG - git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON - git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID} - git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI - git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID} - git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO - git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID} - git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM - git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID} - git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI - git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID} - sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image" - sg docker -c "docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm --no-cache" || FATAL "cannot build PM docker image" - sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image" - sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image" - sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image" - sg docker -c "docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile --no-cache" || FATAL "cannot build LW-UI docker image" + _build_from=$COMMIT_ID + [ -z "$_build_from" ] && _build_from="master" + + echo "OSM Docker images generated from $_build_from" + + BUILD_ARGS+=(--build-arg REPOSITORY="$REPOSITORY") + BUILD_ARGS+=(--build-arg RELEASE="$RELEASE") + BUILD_ARGS+=(--build-arg REPOSITORY_KEY="$REPOSITORY_KEY") + BUILD_ARGS+=(--build-arg REPOSITORY_BASE="$REPOSITORY_BASE") + + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then + sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image" + sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then + sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then + git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON + git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID} + sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image" + sg docker -c "docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm --no-cache" || FATAL "cannot build PM docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then + git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI + git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID} + sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then + sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image" + git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO + git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID} + sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then + git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM + git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID} + sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then + git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI + git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID} + sg docker -c "docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile --no-cache" || FATAL "cannot build LW-UI docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-osmclient; then + sg docker -c "docker build -t osm/osmclient ${BUILD_ARGS[@]} -f $OSM_DEVOPS/docker/osmclient ." + fi echo "Finished generation of docker images" } @@ -595,65 +690,103 @@ function cmp_overwrite() { file2="$2" if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then if [ -f "${file2}" ]; then - ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && sudo cp -b ${file1} ${file2} + ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && cp -b ${file1} ${file2} else - sudo cp -b ${file1} ${file2} + cp -b ${file1} ${file2} fi fi } function generate_config_log_folders() { echo "Generating config and log folders" - sudo mkdir -p /etc/osm/docker - sudo cp -b ${DEVOPS}/installers/docker/docker-compose.yaml /etc/osm/docker/docker-compose.yaml - sudo mkdir -p /var/log/osm + $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml $OSM_DOCKER_WORK_DIR/docker-compose.yaml echo "Finished generation of config and log folders" } function generate_docker_env_files() { echo "Generating docker env files" - echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee /etc/osm/docker/lcm.env - echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a /etc/osm/docker/lcm.env + echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/lcm.env + echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" | $WORKDIR_SUDO tee -a $OSM_DOCKER_WORK_DIR/lcm.env + MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32` - if [ ! -f /etc/osm/docker/ro-db.env ]; then - echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro-db.env + if [ ! -f $OSM_DOCKER_WORK_DIR/ro-db.env ]; then + echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |$WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/ro-db.env fi - if [ ! -f /etc/osm/docker/ro.env ]; then - echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro.env + if [ ! -f $OSM_DOCKER_WORK_DIR/ro.env ]; then + echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |$WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/ro.env fi - echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env - cmp_overwrite ${DEVOPS}/installers/docker/mon.env /etc/osm/docker/mon.env + echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |$WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/mon.env + echo "Finished generation of docker env files" } -function deploy_lightweight() { - echo "Deploying lightweight build" +function generate_osmclient_script () { + echo "docker run -ti --network net${OSM_STACK_NAME} osm/osmclient:${OSM_DOCKER_TAG}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/osm + $WORKDIR_SUDO chmod +x "$OSM_DOCKER_WORK_DIR/osm" + echo "osmclient sidecar container can be found at: $OSM_DOCKER_WORK_DIR/osm" +} + +function init_docker_swarm() { if [ "${DEFAULT_MTU}" != "1500" ]; then DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s` DOCKER_GW_NET=`sg docker -c "docker network inspect ${DOCKER_NETS}" | grep Subnet | awk -F\" '{print $4}' | egrep "^172" | sort -u | tail -1 | awk -F\. '{if ($2 != 255) print $1"."$2+1"."$3"."$4; else print "-1";}'` sg docker -c "docker network create --subnet ${DOCKER_GW_NET} --opt com.docker.network.bridge.name=docker_gwbridge --opt com.docker.network.bridge.enable_icc=false --opt com.docker.network.bridge.enable_ip_masquerade=true --opt com.docker.network.driver.mtu=${DEFAULT_MTU} docker_gwbridge" fi sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}" - sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM" - remove_stack osm - sg docker -c "docker stack deploy -c /etc/osm/docker/docker-compose.yaml osm" - #docker-compose -f /etc/osm/docker/docker-compose.yaml up -d + return 0 +} + +function create_docker_network() { + echo "creating network" + sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} net${OSM_STACK_NAME}" + echo "creating network DONE" +} + +function deploy_lightweight() { + + echo "Deploying lightweight build" + OSM_NBI_PORT=9999 + OSM_RO_PORT=9090 + OSM_UI_PORT=80 + + if [ -n "$NO_HOST_PORTS" ]; then + OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT) + OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT) + OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT) + else + OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT:$OSM_NBI_PORT) + OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT:$OSM_RO_PORT) + OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT:$OSM_UI_PORT) + fi + echo "export ${OSM_PORTS[@]}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/osm_ports.sh + echo "export OSM_NETWORK=net${OSM_STACK_NAME}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh + echo "export TAG=${OSM_DOCKER_TAG}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh + + pushd $OSM_DOCKER_WORK_DIR + sg docker -c "source ./osm_ports.sh; docker stack deploy -c $OSM_DOCKER_WORK_DIR/docker-compose.yaml $OSM_STACK_NAME" + popd + echo "Finished deployment of lightweight build" } function deploy_elk() { - sudo mkdir -p /etc/osm/docker/osm_elk - sudo cp -b ${DEVOPS}/installers/docker/osm_elk/* /etc/osm/docker/osm_elk + echo "Pulling docker images for ELK" + sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image" + sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image" + sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image" + echo "Finished pulling elk docker images" + $WORKDIR_SUDO mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk" + $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk remove_stack osm_elk echo "Deploying ELK stack" - sg docker -c "docker stack deploy -c /etc/osm/docker/osm_elk/docker-compose.yml osm_elk" + sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_elk/docker-compose.yml osm_elk" echo "Waiting for ELK stack to be up and running" time=0 - step=2 - timelength=20 + step=5 + timelength=40 elk_is_up=1 while [ $time -le $timelength ]; do - if [[ $(curl -XGET http://127.0.0.1:5601/status -I | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then + if [[ $(curl -f -XGET http://127.0.0.1:5601/status -I 2>/dev/null | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then elk_is_up=0 break fi @@ -665,11 +798,11 @@ function deploy_elk() { #Create index pattern curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \ "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \ - -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" + -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null #Make it the default index - curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \ + curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \ "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \ - -d"{\"value\":\"logstash-*\"}" + -d"{\"value\":\"logstash-*\"}" 2>/dev/null else echo "Cannot connect to Kibana to create index pattern." echo "Once Kibana is running, you can use the following instructions to create index pattern:" @@ -685,28 +818,41 @@ function deploy_elk() { } function deploy_perfmon() { + echo "Pulling docker images for PM (Grafana and Prometheus)" + sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image" + sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image" + echo "Finished pulling PM docker images" echo "Generating osm/kafka-exporter docker image" sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter --no-cache" || FATAL "cannot build kafka-exporter docker image" echo "Finished generation of osm/kafka-exporter docker image" - sudo mkdir -p /etc/osm/docker/osm_metrics - sudo cp -b ${DEVOPS}/installers/docker/osm_metrics/*.yml /etc/osm/docker/osm_metrics - sudo cp -b ${DEVOPS}/installers/docker/osm_metrics/*.json /etc/osm/docker/osm_metrics + $WORKDIR_SUDO mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics + $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics + $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics remove_stack osm_metrics echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)" - sg docker -c "docker stack deploy -c /etc/osm/docker/osm_metrics/docker-compose.yml osm_metrics" + sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_metrics/docker-compose.yml osm_metrics" echo "Finished deployment of PM stack" return 0 } function install_lightweight() { + OSM_DOCKER_WORK_DIR="$OSM_WORK_DIR/stack/$OSM_STACK_NAME" + [ ! -d "$OSM_DOCKER_WORK_DIR" ] && $WORKDIR_SUDO mkdir -p $OSM_DOCKER_WORK_DIR + [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges." + [ -z "$ASSUME_YES" ] && ! ask_user "The installation will configure LXD, install juju, install docker CE and init a docker swarm, as pre-requirements. Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1 + track proceed echo "Installing lightweight build of OSM" LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")" trap 'rm -rf "${LWTEMPDIR}"' EXIT DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'` + [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0" DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` + [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route" DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') - if [ -z "$INSTALL_NOLXD" ]; then + + # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to + if [ -z "$OSMLCM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ]; then need_packages_lw="lxd" echo -e "Checking required packages: $need_packages_lw" dpkg -l $need_packages_lw &>/dev/null \ @@ -718,24 +864,39 @@ function install_lightweight() { || sudo apt-get install -y $need_packages_lw \ || FATAL "failed to install $need_packages_lw" fi - install_juju - OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'` - OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'` - [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address" - [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret" + track prereqok + [ -z "$INSTALL_NOJUJU" ] && install_juju + + if [ -z "$OSMLCM_VCA_HOST" ]; then + juju_createcontroller + OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_STACK_NAME"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'` + [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address" + fi + if [ -z "$OSMLCM_VCA_SECRET" ]; then + OSMLCM_VCA_SECRET=$(parse_juju_password $OSM_STACK_NAME) + [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret" + fi + track juju - install_docker_ce + [ -n "$INSTALL_NODOCKER" ] || install_docker_ce track docker_ce #install_docker_compose - generate_docker_images + [ -z "$DOCKER_NOBUILD" ] && generate_docker_images track docker_build generate_docker_env_files + generate_config_log_folders + + [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm + # remove old stack + remove_stack $OSM_STACK_NAME + create_docker_network deploy_lightweight + generate_osmclient_script track docker_deploy [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu [ -n "$INSTALL_ELK" ] && deploy_elk && track elk [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon - install_osmclient + [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient track osmclient wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null track end @@ -751,19 +912,20 @@ function install_vimemu() { git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR # build vim-emu docker echo "Building vim-emu Docker container..." - sudo docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile --no-cache $EMUTEMPDIR/ || FATAL "cannot build vim-emu-img docker image" + + sg docker -c "docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile --no-cache $EMUTEMPDIR/" || FATAL "cannot build vim-emu-img docker image" # start vim-emu container as daemon echo "Starting vim-emu Docker container 'vim-emu' ..." if [ -n "$INSTALL_LIGHTWEIGHT" ]; then # in lightweight mode, the emulator needs to be attached to netOSM - sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py + sg docker -c "docker run --name vim-emu -t -d --restart always --privileged --pid='host' --network=net${OSM_STACK_NAME} -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py" else # classic build mode - sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py + sg docker -c "docker run --name vim-emu -t -d --restart always --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py" fi echo "Waiting for 'vim-emu' container to start ..." sleep 5 - export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu) + export VIMEMU_HOSTNAME=$(sg docker -c "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu") echo "vim-emu running at ${VIMEMU_HOSTNAME} ..." # print vim-emu connection info echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:" @@ -789,7 +951,9 @@ function dump_vars(){ echo "INSTALL_ONLY=$INSTALL_ONLY" echo "INSTALL_ELK=$INSTALL_ELK" echo "INSTALL_PERFMON=$INSTALL_PERFMON" + echo "TO_REBUILD=$TO_REBUILD" echo "INSTALL_NOLXD=$INSTALL_NOLXD" + echo "INSTALL_NODOCKER=$INSTALL_NODOCKER" echo "RELEASE=$RELEASE" echo "REPOSITORY=$REPOSITORY" echo "REPOSITORY_BASE=$REPOSITORY_BASE" @@ -824,8 +988,8 @@ SHOWOPTS="" COMMIT_ID="" ASSUME_YES="" INSTALL_FROM_SOURCE="" -RELEASE="-R ReleaseFOUR" -REPOSITORY="-r stable" +RELEASE="ReleaseFOUR" +REPOSITORY="stable" INSTALL_VIMEMU="" INSTALL_FROM_LXDIMAGES="" LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd" @@ -834,13 +998,26 @@ INSTALL_LIGHTWEIGHT="y" INSTALL_ONLY="" INSTALL_ELK="" INSTALL_PERFMON="" +TO_REBUILD="" INSTALL_NOLXD="" +INSTALL_NODOCKER="" +INSTALL_NOJUJU="" NOCONFIGURE="" RELEASE_DAILY="" SESSION_ID=`date +%s` OSM_DEVOPS= - -while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do +OSMLCM_VCA_HOST= +OSMLCM_VCA_SECRET= +OSM_STACK_NAME=osm +NO_HOST_PORTS="" +DOCKER_NOBUILD="" +REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg" +REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian" +WORKDIR_SUDO=sudo +OSM_WORK_DIR="/etc/osm" +OSM_DOCKER_TAG=latest + +while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:H:S:s:w:t:" o; do case "${o}" in h) usage && exit 0 @@ -849,16 +1026,20 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do COMMIT_ID=${OPTARG} ;; r) - REPOSITORY="-r ${OPTARG}" + REPOSITORY="${OPTARG}" + REPO_ARGS+=(-r "$REPOSITORY") ;; R) - RELEASE="-R ${OPTARG}" + RELEASE="${OPTARG}" + REPO_ARGS+=(-R "$RELEASE") ;; k) - REPOSITORY_KEY="-k ${OPTARG}" + REPOSITORY_KEY="${OPTARG}" + REPO_ARGS+=(-k "$REPOSITORY_KEY") ;; u) - REPOSITORY_BASE="-u ${OPTARG}" + REPOSITORY_BASE="${OPTARG}" + REPO_ARGS+=(-u "$REPOSITORY_BASE") ;; l) LXD_REPOSITORY_BASE="${OPTARG}" @@ -869,12 +1050,39 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do D) OSM_DEVOPS="${OPTARG}" ;; + s) + OSM_STACK_NAME="${OPTARG}" + ;; + H) + OSMLCM_VCA_HOST="${OPTARG}" + ;; + S) + OSMLCM_VCA_SECRET="${OPTARG}" + ;; + w) + # when specifying workdir, do not use sudo for access + WORKDIR_SUDO= + OSM_WORK_DIR="${OPTARG}" + ;; + t) + OSM_DOCKER_TAG="${OPTARG}" + ;; o) INSTALL_ONLY="y" [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue ;; + m) + [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue + [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue + [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue + [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue + [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue + [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue + [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue + [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue + ;; -) [ "${OPTARG}" == "help" ] && usage && exit 0 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue @@ -886,6 +1094,7 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue + [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue @@ -895,6 +1104,10 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue + [ "${OPTARG}" == "nohostports" ] && NO_HOST_PORTS="y" && continue + [ "${OPTARG}" == "nojuju" ] && INSTALL_NOJUJU="y" && continue + [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue + [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue echo -e "Invalid option: '--$OPTARG'\n" >&2 usage && exit 1 ;; @@ -916,6 +1129,9 @@ done [ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui" [ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui" [ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui" +[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui" +[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui" +[ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" != " NONE" ] && echo $TO_REBUILD | grep -q NONE && FATAL "Incompatible option: -m NONE cannot be used with other -m options" if [ -n "$SHOWOPTS" ]; then dump_vars @@ -927,20 +1143,6 @@ fi # if develop, we force master [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" -# forcing source from master removed. Now only install from source when explicit -# [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y" - -if [ -z "$OSM_DEVOPS" ]; then - if [ -n "$TEST_INSTALLER" ]; then - echo -e "\nUsing local devops repo for OSM installation" - TEMPDIR="$(dirname $(realpath $(dirname $0)))" - else - echo -e "\nCreating temporary dir for OSM installation" - TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" - trap 'rm -rf "$TEMPDIR"' EXIT - fi -fi - need_packages="git jq wget curl tar" echo -e "Checking required packages: $need_packages" dpkg -l $need_packages &>/dev/null \ @@ -953,25 +1155,28 @@ dpkg -l $need_packages &>/dev/null \ || FATAL "failed to install $need_packages" if [ -z "$OSM_DEVOPS" ]; then - if [ -z "$TEST_INSTALLER" ]; then - echo -e "\nCloning devops repo temporarily" - git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR - RC_CLONE=$? - fi + if [ -n "$TEST_INSTALLER" ]; then + echo -e "\nUsing local devops repo for OSM installation" + OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))" + else + echo -e "\nCreating temporary dir for OSM installation" + OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" + trap 'rm -rf "$OSM_DEVOPS"' EXIT + + git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS + + if [ -z "$COMMIT_ID" ]; then + echo -e "\nGuessing the current stable release" + LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1` + [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0 - echo -e "\nGuessing the current stable release" - LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1` - [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0 - echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS" - [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS" - - if [ -n "$RELEASE_DAILY" ]; then - echo "Using master/HEAD devops" - git -C $TEMPDIR checkout master - elif [ -z "$TEST_INSTALLER" ]; then - git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS + echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS" + COMMIT_ID="tags/$LATEST_STABLE_DEVOPS" + else + echo -e "\nDEVOPS Using commit $COMMIT_ID" + fi + git -C $OSM_DEVOPS checkout $COMMIT_ID fi - OSM_DEVOPS=$TEMPDIR fi OSM_JENKINS="$OSM_DEVOPS/jenkins" @@ -1020,14 +1225,14 @@ elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in O install_from_lxdimages else #install from binaries echo -e "\nCreating the containers and installing from binaries ..." - $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed" + $OSM_DEVOPS/jenkins/host/install RO ${REPO_ARGS[@]} || FATAL "RO install failed" ro_is_up && track RO $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed" vca_is_up && track VCA $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed" mon_is_up && track MON - $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed" - $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed" + $OSM_DEVOPS/jenkins/host/install SO ${REPO_ARGS[@]} || FATAL "SO install failed" + $OSM_DEVOPS/jenkins/host/install UI ${REPO_ARGS[@]} || FATAL "UI install failed" #so_is_up && track SOUI track SOUI fi