From 2f4c3eca2cc08caa3560da153cf5ba6a2268c10e Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Sun, 19 Aug 2018 23:28:03 +0200 Subject: [jump req] Add build/deploy specific requirements Add support for different prerequisites depending on the current operation (docker build or cluster deploy). Leverage the new support to pre-install upcoming deps: - python-pip (build); - docker-compose (deploy); JIRA: FUEL-383 Change-Id: Ic3e6062b1943e3584f0b1f80d2e33b8812defced Signed-off-by: Alexandru Avadanii --- ci/deploy.sh | 2 +- mcp/scripts/lib.sh | 3 ++- mcp/scripts/requirements_deb.yaml | 7 ++++++- mcp/scripts/requirements_rpm.yaml | 7 ++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ci/deploy.sh b/ci/deploy.sh index ea8524a85..d3704a1dd 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -240,7 +240,7 @@ if [ ${USE_EXISTING_PKGS} -eq 1 ]; then notify "[NOTE] Skipping distro pkg installation" 2 else notify "[NOTE] Installing required distro pkgs" 2 - jumpserver_pkg_install + jumpserver_pkg_install 'deploy' fi if ! virsh list >/dev/null 2>&1; then diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh index c566cc993..c3a71a436 100644 --- a/mcp/scripts/lib.sh +++ b/mcp/scripts/lib.sh @@ -321,6 +321,7 @@ function prepare_vms { } function jumpserver_pkg_install { + local req_type=$1 if [ -n "$(command -v apt-get)" ]; then pkg_type='deb'; pkg_cmd='sudo apt-get install -y' else @@ -328,7 +329,7 @@ function jumpserver_pkg_install { fi eval "$(parse_yaml "./requirements_${pkg_type}.yaml")" for section in 'common' "$(uname -i)"; do - section_var="requirements_pkg_${section}[*]" + section_var="${req_type}_${section}[*]" pkg_list+=" ${!section_var}" done # shellcheck disable=SC2086 diff --git a/mcp/scripts/requirements_deb.yaml b/mcp/scripts/requirements_deb.yaml index 04ddcf631..c04f2a1d7 100644 --- a/mcp/scripts/requirements_deb.yaml +++ b/mcp/scripts/requirements_deb.yaml @@ -6,13 +6,18 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## --- -requirements_pkg: +build: + # Common pkgs required for all builds, no matter the type, arch etc. + common: + - python-pip +deploy: # Common pkgs required for all deploys, no matter the type, arch etc. common: - bridge-utils - cloud-guest-utils - cpu-checker - curl + - docker-compose - e2fsprogs - git - kpartx diff --git a/mcp/scripts/requirements_rpm.yaml b/mcp/scripts/requirements_rpm.yaml index 3df4d0a80..50ce5d9f5 100644 --- a/mcp/scripts/requirements_rpm.yaml +++ b/mcp/scripts/requirements_rpm.yaml @@ -6,13 +6,18 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## --- -requirements_pkg: +build: + # Common pkgs required for all builds, no matter the type, arch etc. + common: + - python-pip +deploy: # Common pkgs required for all deploys, no matter the type, arch etc. common: - bc - bridge-utils - cloud-utils-growpart - curl + - docker-compose - elfutils-libelf-devel - e2fsprogs - genisoimage -- cgit 1.2.3-korg From 7bdedca0da908d4b42f17457f04ea87b69c480e3 Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Mon, 20 Aug 2018 00:11:02 +0200 Subject: [deploy.sh] Install Docker if not present JIRA: FUEL-383 Change-Id: I19d27ca59a3f24d1bd66e39457a6ca267bccce19 Signed-off-by: Alexandru Avadanii --- ci/deploy.sh | 1 + mcp/scripts/lib.sh | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/ci/deploy.sh b/ci/deploy.sh index d3704a1dd..47662f796 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -241,6 +241,7 @@ if [ ${USE_EXISTING_PKGS} -eq 1 ]; then else notify "[NOTE] Installing required distro pkgs" 2 jumpserver_pkg_install 'deploy' + docker_install fi if ! virsh list >/dev/null 2>&1; then diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh index c3a71a436..5f1275dc5 100644 --- a/mcp/scripts/lib.sh +++ b/mcp/scripts/lib.sh @@ -572,3 +572,14 @@ function get_nova_compute_pillar_data { echo "${value}" fi } + +function docker_install { + # Mininum effort attempt at installing Docker if missing + if ! which docker; then + curl -fsSL https://get.docker.com -o get-docker.sh + sudo sh get-docker.sh + rm get-docker.sh + # On RHEL distros, the Docker service should be explicitly started + sudo systemctl start docker + fi +} -- cgit 1.2.3-korg From 7d35eed8eb4b0c1047dba575f365060cebac9659 Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Sun, 19 Aug 2018 17:52:02 +0200 Subject: [submodule] Add docker-salt-formulas, ci/build.sh - add new git submodule pointing to upstream docker build scripts; - add patch extending Docker tags with an '-(arch)' suffix, aligning with OPNFV tagging requiremnts; - add wrapper for starting Docker builds; - install build-specific distro package requirements, as well as pip-managed packages (e.g. pipenv); JIRA: FUEL-383 Change-Id: Id4fc886206d7eaf7e6d02810380f2391609ba405 Signed-off-by: Alexandru Avadanii --- .gitmodules | 4 ++ ci/build.sh | 79 ++++++++++++++++++++++ docker | 1 + .../0001-OPNFV-tag-convention-alignment.patch | 78 +++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100755 ci/build.sh create mode 160000 docker create mode 100644 mcp/patches/docker/0001-OPNFV-tag-convention-alignment.patch diff --git a/.gitmodules b/.gitmodules index c7c44587c..d3501c3ec 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,7 @@ path = mcp/scripts/pharos url = https://github.com/opnfv/pharos branch = master +[submodule "docker"] + path = docker + url = https://github.com/epcim/docker-salt-formulas + branch = master diff --git a/ci/build.sh b/ci/build.sh new file mode 100755 index 000000000..9bca18770 --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,79 @@ +#!/bin/bash -e +# shellcheck disable=SC1004,SC1090 +############################################################################## +# Copyright (c) 2018 Mirantis Inc., Enea AB and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +############################################################################## +# BEGIN of Exit handlers +# +do_exit () { + local RC=$? + if [ ${RC} -eq 0 ]; then + notify_n "[OK] MCP: Docker build finished succesfully!" 2 + else + notify_n "[ERROR] MCP: Docker build threw a fatal error!" + fi +} +# +# End of Exit handlers +############################################################################## + +############################################################################## +# BEGIN of variables to customize +# +CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x +MCP_REPO_ROOT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..") +DEPLOY_DIR=$(cd "${MCP_REPO_ROOT_PATH}/mcp/scripts"; pwd) +DOCKER_DIR=$(cd "${MCP_REPO_ROOT_PATH}/docker"; pwd) +DOCKER_TAG=${1:-latest} + +source "${DEPLOY_DIR}/globals.sh" +source "${DEPLOY_DIR}/lib.sh" + +# +# END of variables to customize +############################################################################## + +############################################################################## +# BEGIN of main +# + +# Enable the automatic exit trap +trap do_exit SIGINT SIGTERM EXIT + +# Set no restrictive umask so that Jenkins can remove any residuals +umask 0000 + +# Clone git submodules and apply our patches +make -C "${MCP_REPO_ROOT_PATH}/mcp/patches" deepclean patches-import + +pushd "${DOCKER_DIR}" > /dev/null + +# Install distro packages and pip-managed prerequisites +notify "[NOTE] Installing required build-time distro and pip pkgs" 2 +jumpserver_pkg_install 'build' +pip install pipenv --user +docker_install + +pipenv --two +pipenv install +pipenv shell \ + "invoke build saltmaster-reclass \ + --require 'salt salt-formulas reclass tini-saltmaster' \ + --dist=ubuntu \ + --dist-rel=xenial \ + --formula-rev=nightly \ + --opnfv-tag='${DOCKER_TAG}' \ + --salt='stable 2017.7'; \ + exit" + +popd > /dev/null + +# +# END of main +############################################################################## diff --git a/docker b/docker new file mode 160000 index 000000000..d580f1ef2 --- /dev/null +++ b/docker @@ -0,0 +1 @@ +Subproject commit d580f1ef272a29268a1825e7f810979ade6b2b71 diff --git a/mcp/patches/docker/0001-OPNFV-tag-convention-alignment.patch b/mcp/patches/docker/0001-OPNFV-tag-convention-alignment.patch new file mode 100644 index 000000000..aa0b01c39 --- /dev/null +++ b/mcp/patches/docker/0001-OPNFV-tag-convention-alignment.patch @@ -0,0 +1,78 @@ +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +: Copyright (c) 2018 Mirantis Inc., Enea AB and others. +: +: All rights reserved. This program and the accompanying materials +: are made available under the terms of the Apache License, Version 2.0 +: which accompanies this distribution, and is available at +: http://www.apache.org/licenses/LICENSE-2.0 +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +From: Alexandru Avadanii +Date: Tue, 21 Aug 2018 02:42:35 +0200 +Subject: [PATCH] OPNFV tag convention alignment + +* (arch)- prefix Docker tags + Hacky implementation that only detects 'arm64', otherwise it will + default to 'amd64'. + Note that Docker arch notation uses 'arm64' instead of 'aarch64'. +* Override Docker tag to align with OPNFV format +* use Docker repository: opnfv/fuel + +Signed-off-by: Alexandru Avadanii +--- + invoke.yml | 2 +- + tasks.py | 7 +++++-- + 2 files changed, 6 insertions(+), 3 deletions(-) + +diff --git a/invoke.yml b/invoke.yml +index 0bd793e..291f4c7 100644 +--- a/invoke.yml ++++ b/invoke.yml +@@ -65,7 +65,7 @@ target: + + dockermake: + destination: 'images' +- repository: 'docker.io/epcim/salt' ++ repository: 'docker.io/opnfv/fuel' + # options: '--no-cache' + # options: '--bust-cache reclass' + # options: '--registry-user epcim' +diff --git a/tasks.py b/tasks.py +index d6bf3bc..092c6e7 100644 +--- a/tasks.py ++++ b/tasks.py +@@ -6,6 +6,7 @@ from invoke import Collection, task + from string import Template + import re + import ast ++import platform + + # TODOs: + # - WIP - use namespace to expose images/targets as inoke tasks # image = Collection('image') +@@ -25,8 +26,9 @@ def all(ctx, dry=False, push=False, dry_targets=False, filter=None, **kwargs): + dry=dry, push=push, dry_targets=dry_targets, filter=filter, **kwargs) + + @task +-def build(ctx, target, require=[], dist='debian', dist_rel='stretch', salt=None, formula_rev=None, push=False, dry=False, dry_targets=False, **kwargs): ++def build(ctx, target, require=[], dist='debian', dist_rel='stretch', salt=None, formula_rev=None, opnfv_tag='latest', push=False, dry=False, dry_targets=False, **kwargs): + ++ kwargs['arch'] = 'arm64' if platform.machine() == 'aarch64' else 'amd64' + kwargs['dist'] = dist + kwargs['dist_rel'] = dist_rel + kwargs['dry'] = True if dry_targets or dry else False +@@ -35,6 +37,7 @@ def build(ctx, target, require=[], dist='debian', dist_rel='stretch', salt=None, + kwargs['require'] = require + kwargs['salt'] = salt + kwargs['target'] = target ++ kwargs['opnfv_tag'] = opnfv_tag + # command formating + update + fmt = {'tag': ''} + fmt.update(ctx.dockermake) +@@ -56,7 +59,7 @@ def build(ctx, target, require=[], dist='debian', dist_rel='stretch', salt=None, + # execute + cmd = Template(""" + ${dry}docker-make -f DockerMake.${dist}.yml -u ${repository}: --name ${target} \ +- \t-t ${dist}-${dist_rel}${tag} \ ++ \t-t ${arch}-${opnfv_tag} \ + \t--requires ${requires} \ + \t--build-arg SALT_VERSION="${salt}" \ + \t--build-arg SALT_FORMULA_VERSION="${formula_rev}" \ -- cgit 1.2.3-korg From 10a751f1e43a1c719ad4f313fb8059847de6190a Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Wed, 22 Aug 2018 01:38:31 +0200 Subject: [docker build] Install OpenSSH server While at it, create the 'ubuntu' user with passwordless sudo and preinstall salt-formula-gnocchi (missing git repo workaround), as well as various useful packages (e.g. net-tools). JIRA: FUEL-383 Change-Id: I5902c37110331acfd3fd4fccb92104de7b5ece6b Signed-off-by: Alexandru Avadanii --- ci/build.sh | 2 +- ...02-OPNFV-package-installation-Ubuntu-user.patch | 63 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 mcp/patches/docker/0002-OPNFV-package-installation-Ubuntu-user.patch diff --git a/ci/build.sh b/ci/build.sh index 9bca18770..313edaed4 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -64,7 +64,7 @@ pipenv --two pipenv install pipenv shell \ "invoke build saltmaster-reclass \ - --require 'salt salt-formulas reclass tini-saltmaster' \ + --require 'salt salt-formulas opnfv reclass tini-saltmaster' \ --dist=ubuntu \ --dist-rel=xenial \ --formula-rev=nightly \ diff --git a/mcp/patches/docker/0002-OPNFV-package-installation-Ubuntu-user.patch b/mcp/patches/docker/0002-OPNFV-package-installation-Ubuntu-user.patch new file mode 100644 index 000000000..546e4e9e2 --- /dev/null +++ b/mcp/patches/docker/0002-OPNFV-package-installation-Ubuntu-user.patch @@ -0,0 +1,63 @@ +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +: Copyright (c) 2018 Mirantis Inc., Enea AB and others. +: +: All rights reserved. This program and the accompanying materials +: are made available under the terms of the Apache License, Version 2.0 +: which accompanies this distribution, and is available at +: http://www.apache.org/licenses/LICENSE-2.0 +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +From: Alexandru Avadanii +Date: Wed, 22 Aug 2018 01:35:06 +0200 +Subject: [PATCH] OPNFV package installation, Ubuntu user + +* Install OpenSSH server (and client), so other OPNFV projects can + easily connect to the Salt master node; +* Install 'salt-formula-gnocchi' distro package (empty git formula + workaround); +* While at it, create 'ubuntu' user so other OPNFV projects don't + have to switch to 'root' login; + +Signed-off-by: Alexandru Avadanii +--- + DockerMake.yml | 28 ++++++++++++++++++++++++++++ + 1 file changed, 28 insertions(+) + +diff --git a/DockerMake.yml b/DockerMake.yml +index 2c75586..9b044a3 100644 +--- a/DockerMake.yml ++++ b/DockerMake.yml +@@ -108,6 +108,34 @@ salt-formulas: + && bash -c 'source /srv/salt/formula-fetch.sh && setupPyEnv && fetchAll' \ + && eval ${LAYER_CLEANUP} + ++opnfv: ++ build: | ++ # Some formulas have empty git repos, use the package version ++ ARG SALT_FORMULA_VERSION="nightly" ++ ENV SALT_FORMULA_VERSION $SALT_FORMULA_VERSION ++ ARG SALT_FORMULA_LIST="salt-formula-gnocchi" ++ ENV SALT_FORMULA_LIST $SALT_FORMULA_LIST ++ ENV APT_REPOSITORY "deb http://apt.mirantis.com/xenial ${SALT_FORMULA_VERSION} salt" ++ ENV APT_REPOSITORY_GPG "http://apt.mirantis.com/public.gpg" ++ RUN echo "Layer extra salt-formulas packages" \ ++ && echo "$APT_REPOSITORY" | tee /etc/apt/sources.list.d/salt-formulas.list >/dev/null \ ++ && curl -sL $APT_REPOSITORY_GPG | $SUDO apt-key add - \ ++ && eval ${LAYER_PKGUPDT} \ ++ && ${LAYER_INSTALL} ${SALT_FORMULA_LIST} -y --fix-missing -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \ ++ && eval ${LAYER_CLEANUP} ++ RUN echo "Layer with OPNFV packages" \ ++ && eval ${LAYER_PKGUPDT} \ ++ && ${LAYER_INSTALL} \ ++ gawk \ ++ inetutils-ping \ ++ kmod \ ++ net-tools \ ++ openssh-server \ ++ && useradd -m ubuntu \ ++ && echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/ubuntu \ ++ && eval ${LAYER_CLEANUP} ++ ++ + wheel: + requires: + - base -- cgit 1.2.3-korg