From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw1202.ocn.ad.jp (mogw1202.ocn.ad.jp [153.149.235.3]) by dpdk.org (Postfix) with ESMTP id 247B41D8DB for ; Fri, 15 Jun 2018 10:37:59 +0200 (CEST) Received: from mf-smf-ucb022c2 (mf-smf-ucb022c2.ocn.ad.jp [153.153.66.140]) by mogw1202.ocn.ad.jp (Postfix) with ESMTP id 211ECB0023C; Fri, 15 Jun 2018 17:37:58 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb030 ([153.149.230.164]) by mf-smf-ucb022c2 with ESMTP id TkF3fhpOgQtJhTkF3f2Xir; Fri, 15 Jun 2018 17:37:58 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.166]) by ntt.pod01.mv-mta-ucb030 with id ywdx1x00W3c2f7501wdxlz; Fri, 15 Jun 2018 08:37:57 +0000 Received: from localhost.localdomain (p5164-ipngn8501marunouchi.tokyo.ocn.ne.jp [153.214.228.164]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Fri, 15 Jun 2018 17:37:57 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Fri, 15 Jun 2018 17:37:40 +0900 Message-Id: <20180615083754.20220-2-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180615083754.20220-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180615083754.20220-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 01/15] tools/sppc: add SPP container build tool X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2018 08:37:59 -0000 From: Yasufumi Ogawa Build tool is used for creating docker image. It consists of main script and common libraries. * build/main.py * lib/common.py * conf/env.py You can specify the versions of DPDK or other applications and repository if you need. You can also specify Linux distribution and its version. $ python build/build.py --dpdk-branch v18.02 \ --spp-repo https://github.com/your/spp.git 'env.py' defines environmental variables used on the container image. Signed-off-by: Yasufumi Ogawa --- tools/sppc/build/main.py | 188 ++++++++++++++++++++++++++++++++++++ tools/sppc/conf/__init__.py | 0 tools/sppc/conf/env.py | 13 +++ tools/sppc/lib/__init__.py | 0 tools/sppc/lib/common.py | 30 ++++++ 5 files changed, 231 insertions(+) create mode 100755 tools/sppc/build/main.py create mode 100644 tools/sppc/conf/__init__.py create mode 100644 tools/sppc/conf/env.py create mode 100644 tools/sppc/lib/__init__.py create mode 100644 tools/sppc/lib/common.py diff --git a/tools/sppc/build/main.py b/tools/sppc/build/main.py new file mode 100755 index 0000000..d33a6f2 --- /dev/null +++ b/tools/sppc/build/main.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation + +from __future__ import absolute_import +import argparse +import os +import subprocess +import sys + +work_dir = os.path.dirname(__file__) +sys.path.append(work_dir + '/..') +from lib import common +from conf import env + + +def parse_args(): + parser = argparse.ArgumentParser( + description="Docker image builder for DPDK applications") + parser.add_argument( + '-t', '--target', + type=str, + help="Build target ('dpdk', 'pktgen' or 'spp')") + parser.add_argument( + '-ci', '--container-image', + type=str, + help="Name of container image") + parser.add_argument( + '--dist-name', + type=str, + default='ubuntu', + help="Name of Linux distribution") + parser.add_argument( + '--dist-ver', + type=str, + default='latest', + help="Version of Linux distribution") + parser.add_argument( + '--dpdk-repo', + type=str, + default="http://dpdk.org/git/dpdk", + help="Git URL of DPDK") + parser.add_argument( + '--dpdk-branch', + type=str, + help="Specific version or branch of DPDK") + parser.add_argument( + '--pktgen-repo', + type=str, + default="http://dpdk.org/git/apps/pktgen-dpdk", + help="Git URL of pktgen-dpdk") + parser.add_argument( + '--pktgen-branch', + type=str, + help="Specific version or branch of pktgen-dpdk") + parser.add_argument( + '--spp-repo', + type=str, + default="http://dpdk.org/git/apps/spp", + help="Git URL of SPP") + parser.add_argument( + '--spp-branch', + type=str, + help="Specific version or branch of SPP") + parser.add_argument( + '--only-envsh', + action='store_true', + help="Create config 'env.sh' and exit without docker build") + parser.add_argument( + '--dry-run', + action='store_true', + help="Print matrix for checking and exit without docker build") + return parser.parse_args() + + +def create_env_sh(dst_dir): + """Create config file for DPDK environment variables + + Create 'env.sh' which defines $RTE_SDK and $RTE_TARGET inside a + container to be referredd from 'run.sh' and Dockerfile. + """ + contents = "export RTE_SDK=%s\n" % env.RTE_SDK + contents += "export RTE_TARGET=%s" % env.RTE_TARGET + + f = open('%s/env.sh' % dst_dir, 'w') + f.write(contents) + f.close() + + +def main(): + args = parse_args() + + if args.target is not None: + target_dir = '%s/%s/%s' % ( # Dockerfile is contained here + work_dir, args.dist_name, args.target) + # Container image name, for exp 'sppc/dpdk-ubuntu:18.04' + container_image = common.container_img_name( + env.CONTAINER_IMG_NAME[args.target], + args.dist_name, + args.dist_ver) + else: + print("Error: Target '-t [dpdk|pktgen|spp]' is required!") + exit() + + # Decide which of Dockerfile with given base image version + dockerfile = '%s/Dockerfile.%s' % (target_dir, args.dist_ver) + + # Overwrite container's name if it is given. + if args.container_image is not None: + container_image = args.container_image + + # Setup branches if user specifies. + if args.dpdk_branch is not None: + dpdk_branch = "-b %s" % args.dpdk_branch + else: + dpdk_branch = '' + + if args.pktgen_branch is not None: + pktgen_branch = "-b %s" % args.pktgen_branch + else: + pktgen_branch = '' + + if args.spp_branch is not None: + spp_branch = "-b %s" % args.spp_branch + else: + spp_branch = '' + + # Check for just creating env.sh, or run docker build. + if args.only_envsh is True: + if args.dry_run is False: + create_env_sh(target_dir) + print("Info: '%s/env.sh' created." % target_dir) + exit() + else: + print("Info: Nothin done because you gave %s with %s." % ( + '--only-envsh', '--dry-run')) + exit() + else: + create_env_sh(target_dir) + + # Setup environment variables on host to pass 'docker build'. + env_opts = [ + 'http_proxy', + 'https_proxy', + 'no_proxy' + ] + + docker_cmd = ['sudo', 'docker', 'build', '\\'] + + for opt in env_opts: + if opt in os.environ.keys(): + docker_cmd += [ + '--build-arg', '%s=%s' % (opt, os.environ[opt]), '\\'] + + docker_cmd += [ + '--build-arg', 'home_dir=%s' % env.HOMEDIR, '\\', + '--build-arg', 'rte_sdk=%s' % env.RTE_SDK, '\\', + '--build-arg', 'rte_target=%s' % env.RTE_TARGET, '\\', + '--build-arg', 'dpdk_repo=%s' % args.dpdk_repo, '\\', + '--build-arg', 'dpdk_branch=%s' % dpdk_branch, '\\'] + + if args.target == 'pktgen': + docker_cmd += [ + '--build-arg', 'pktgen_repo=%s' % args.pktgen_repo, '\\', + '--build-arg', 'pktgen_branch=%s' % pktgen_branch, '\\'] + elif args.target == 'spp': + docker_cmd += [ + '--build-arg', 'spp_repo=%s' % args.spp_repo, '\\', + '--build-arg', 'spp_branch=%s' % spp_branch, '\\'] + + docker_cmd += [ + '-f', '%s' % dockerfile, '\\', + '-t', container_image, '\\', + target_dir] + + common.print_pretty_commands(docker_cmd) + + if args.dry_run is True: + exit() + + # Remove delimiters for print_pretty_commands(). + while '\\' in docker_cmd: + docker_cmd.remove('\\') + subprocess.call(docker_cmd) + + +if __name__ == '__main__': + main() diff --git a/tools/sppc/conf/__init__.py b/tools/sppc/conf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/sppc/conf/env.py b/tools/sppc/conf/env.py new file mode 100644 index 0000000..f6df15a --- /dev/null +++ b/tools/sppc/conf/env.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation + + +HOMEDIR = '/root' +RTE_SDK = '/root/dpdk' +RTE_TARGET = 'x86_64-native-linuxapp-gcc' + +CONTAINER_IMG_NAME = { + 'dpdk': 'sppc/dpdk', + 'pktgen': 'sppc/pktgen', + 'spp': 'sppc/spp'} diff --git a/tools/sppc/lib/__init__.py b/tools/sppc/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/sppc/lib/common.py b/tools/sppc/lib/common.py new file mode 100644 index 0000000..7102d43 --- /dev/null +++ b/tools/sppc/lib/common.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation + + +def print_pretty_commands(cmds): + """Print given command in pretty format""" + + print(' '.join(cmds).replace('\\', '\\\n')) + + +def container_img_name(base, dist_name, dist_ver): + """Generate container image name + + Return the name of container image for '-t' of docker command + such as 'sppc/dpdk-ubuntu:16.04' or 'sppc/spp-ubuntu:18.04'. + 'base' is defined as 'env.CONTAINER_IMG_NAME' in lib module. + """ + return '%s-%s:%s' % (base, dist_name, dist_ver) + + +def error_exit(objname): + """Print error message and exit + + This function is used for notifying an argument for the object + is not given. + """ + + print('Error: \'%s\' is not defined.' % objname) + exit() -- 2.17.1