#!/usr/bin/env bash set -xe # This is the script used by ASF Jenkins to build and check Mesos for # a given OS and compiler combination. # Require the following environment variables to be set. : $(OS:?"Environment variable 'OS' must be set (e.g., OS=ubuntu:14.04)") : $(BUILDTOOL:?"Environment variable 'BUILDTOOL' must be set (e.g., BUILDTOOL=autotools)") : $(COMPILER:?"Environment variable 'COMPILER' must be set (e.g., COMPILER=gcc)") : $(CONFIGURATION:?"Environment variable 'CONFIGURATION' must be set (e.g., CONFIGURATION='--enable-libevent --enable-ssl')") : $(ENVIRONMENT:?"Environment variable 'ENVIRONMENT' must be set (e.g., ENVIRONMENT='GLOG_v=1 MESOS_VERBOSE=1')") # Change to the root of Mesos repo for docker build context. global MESOS_DIRECTORY := $[ cd "$[ dirname $0]/.." && pwd] cd $MESOS_DIRECTORY # TODO(vinod): Once ASF CI supports Docker 1.5 use a custom name for # Dockerfile to avoid overwriting Dockerfile (if it exists) at the root # of the repo. global DOCKERFILE := '"Dockerfile'" rm -f $DOCKERFILE # Just in case a stale one exists. # Helper function that appends instructions to docker file. proc append_dockerfile { echo $1 >> $DOCKERFILE } # TODO(vinod): Add support for Fedora and Debian. matchstr $OS { centos* { # NOTE: Currently we only support CentOS7+ due to the # compiler versions needed to compile Mesos. append_dockerfile "FROM $OS" # Install dependencies. append_dockerfile "RUN yum install -y which" append_dockerfile "RUN yum groupinstall -y 'Development Tools'" append_dockerfile "RUN yum install -y epel-release" # Needed for clang. append_dockerfile "RUN yum install -y clang git maven cmake" append_dockerfile "RUN yum install -y java-1.8.0-openjdk-devel python-devel zlib-devel libcurl-devel openssl-devel cyrus-sasl-devel cyrus-sasl-md5 apr-devel subversion-devel apr-utils-devel libevent-devel libev-devel" # Add an unprivileged user. append_dockerfile "RUN adduser mesos" } *ubuntu* { # NOTE: Currently we only support Ubuntu13.10+ due to the # compiler versions needed to compile Mesos. append_dockerfile "FROM $OS" # NOTE: We need to do this to fix some flakiness while fetching packages. # See https://bugs.launchpad.net/ubuntu/+source/apt/+bug/972077 append_dockerfile "RUN rm -rf /var/lib/apt/lists/*" # Install dependencies. # IBM Power only supports Ubuntu 14.04 and gcc compiler. test $[uname -m] = "x86_64" && global CLANG_PKG := 'clang-3.5' || global CLANG_PKG := '' append_dockerfile "RUN apt-get update" append_dockerfile "RUN apt-get -y install build-essential $CLANG_PKG git maven autoconf libtool cmake" append_dockerfile "RUN apt-get -y install openjdk-7-jdk python-dev libcurl4-nss-dev libsasl2-dev libapr1-dev libsvn-dev libevent-dev libev-dev" append_dockerfile "RUN apt-get -y install wget curl sed" # Add an unpriviliged user. append_dockerfile "RUN adduser --disabled-password --gecos '' mesos" } * { echo "Unknown OS $OS" exit 1 } } matchstr $COMPILER { gcc { append_dockerfile "ENV CC gcc" append_dockerfile "ENV CXX g++" } clang { matchstr $OS { *ubuntu* { append_dockerfile "ENV CC clang-3.5" append_dockerfile "ENV CXX clang++-3.5" } * { append_dockerfile "ENV CC clang" append_dockerfile "ENV CXX clang++" } } } * { echo "Unknown Compiler $COMPILER" exit 1 } } # Set working directory. append_dockerfile "WORKDIR mesos" # Copy Mesos source tree into the image. append_dockerfile "COPY . /mesos/" # NOTE: We run all the tests as unprivileged 'mesos' user because # we need to fix cgroups related tests to work inside Docker; certain # tests (e.g., ContainerizerTest) enable cgroups isolation if the user # is 'root'. # TODO(vinod): Fix cgroups tests to work inside Docker. append_dockerfile "RUN chown -R mesos /mesos" append_dockerfile "USER mesos" # Generate xml reports to be displayed by jenkins xUnit plugin. append_dockerfile "ENV GTEST_OUTPUT xml:report.xml" # Ensure `make distcheck` inherits configure flags. append_dockerfile "ENV DISTCHECK_CONFIGURE_FLAGS $CONFIGURATION" # Set the environment for build. append_dockerfile "ENV $ENVIRONMENT" # Perform coverity build if requested. if test -n $COVERITY_TOKEN { # Note currently the coverity build is only tested with ubuntu:14:04, autotools, and gcc. # Download coverity tools, build using coverity wrapper and upload results. append_dockerfile "ENV MESOS_VERSION $[grep "AC_INIT" configure.ac | sed 's/AC_INIT[(]\[mesos\], \[\(.*\)\][)]/\1/]" append_dockerfile "RUN wget https://scan.coverity.com/download/linux64 --post-data \"token=$COVERITY_TOKEN&project=Mesos\" -O coverity_tool.tgz" append_dockerfile "RUN tar xvf coverity_tool.tgz; mv cov-analysis-linux* cov-analysis" append_dockerfile "CMD ./bootstrap && ./configure $CONFIGURATION && cov-analysis/bin/cov-build -dir cov-int make -j6 && tar czcf mesos.tgz cov-int && tail cov-int/build-log.txt && curl --form \"token=$COVERITY_TOKEN\" --form \"email=dev@mesos.apache.org\" --form \"file=@mesos.tgz\" --form \"version=$MESOS_VERSION\" --form \"description='Continious Coverity Build'\" https://scan.coverity.com/builds?project=Mesos" } else { # Build and check Mesos. matchstr $BUILDTOOL { autotools { append_dockerfile "CMD ./bootstrap && ./configure $CONFIGURATION && make -j6 distcheck 2>&1" } cmake { # Transform autotools-like parameters to cmake-like. # Remove "'". global CONFIGURATION := $(CONFIGURATION//\'/"") # Replace "-" with "_". global CONFIGURATION := $(CONFIGURATION//-/"_") # Replace "__" with "-D". global CONFIGURATION := $(CONFIGURATION//__/"-D") # To Upper Case. global CONFIGURATION := $(CONFIGURATION^^) # Add "=1" suffix to each variable. env IFS=' ' read -r -a array <<< $CONFIGURATION global CONFIGURATION := ''"" for element in [$(array[@])] { global CONFIGURATION := ""$CONFIGURATION $element=1"" } # MESOS-5433: `distcheck` is not currently supported by our CMake scripts. # MESOS-5624: In source build is not yet supported. # Also, we run `make` in addition to `make check` because the latter only # compiles stout and libprocess sources and tests. append_dockerfile "CMD ./bootstrap && mkdir build && cd build && cmake $CONFIGURATION .. && make -j6 check && make -j6" } * { echo "Unknown build tool $BUILDTOOL" exit 1 } } } # Generate a random image tag. global TAG := "mesos-$[date +%s]-$RANDOM" # Build the Docker image. # TODO(vinod): Instead of building Docker images on the fly host the # images on DockerHub and use them. docker build --no-cache=true -t $TAG . # Set a trap to delete the image on exit. trap "docker rmi $TAG" EXIT # Uncomment below to print kernel log incase of failures. # trap "dmesg" ERR # Now run the image. # NOTE: We run in 'privileged' mode to circumvent permission issues # with AppArmor. See https://github.com/docker/docker/issues/7276. docker run --privileged --rm $TAG (CommandList children: [ (C {(set)} {(-xe)}) (C {(Lit_Other ":")} { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonQMark arg_word: {(DQ ("Environment variable 'OS' must be set (e.g., OS=ubuntu:14.04)"))} ) spids: [21 27] ) } ) (C {(Lit_Other ":")} { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonQMark arg_word: {(DQ ("Environment variable 'BUILDTOOL' must be set (e.g., BUILDTOOL=autotools)"))} ) spids: [31 37] ) } ) (C {(Lit_Other ":")} { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonQMark arg_word: {(DQ ("Environment variable 'COMPILER' must be set (e.g., COMPILER=gcc)"))} ) spids: [41 47] ) } ) (C {(Lit_Other ":")} { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonQMark arg_word: { (DQ ( "Environment variable 'CONFIGURATION' must be set (e.g., CONFIGURATION='--enable-libevent --enable-ssl')" ) ) } ) spids: [51 57] ) } ) (C {(Lit_Other ":")} { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonQMark arg_word: { (DQ ( "Environment variable 'ENVIRONMENT' must be set (e.g., ENVIRONMENT='GLOG_v=1 MESOS_VERBOSE=1')" ) ) } ) spids: [61 67] ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MESOS_DIRECTORY) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ ($ VSub_Number "$0"))})] ) left_token: spids: [79 87] ) (/..) ) } ) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [74 95] ) } spids: [73] ) ] spids: [73] ) (C {(cd)} {(DQ ($ VSub_Name "$MESOS_DIRECTORY"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DOCKERFILE) op: Equal rhs: {(DQ (Dockerfile))} spids: [113] ) ] spids: [113] ) (C {(rm)} {(-f)} {($ VSub_Name "$DOCKERFILE")}) (FuncDef name: append_dockerfile body: (BraceGroup children: [ (SimpleCommand words: [{(echo)} {($ VSub_Number "$1")}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$DOCKERFILE")} spids: [143] ) ] ) ] spids: [136] ) spids: [132 135] ) (Case to_match: {($ VSub_Name "$OS")} arms: [ (case_arm pat_list: [{(centos) (Lit_Other "*")}] action: [ (C {(append_dockerfile)} {(DQ ("FROM ") ($ VSub_Name "$OS"))}) (C {(append_dockerfile)} {(DQ ("RUN yum install -y which"))}) (C {(append_dockerfile)} {(DQ ("RUN yum groupinstall -y 'Development Tools'"))}) (C {(append_dockerfile)} {(DQ ("RUN yum install -y epel-release"))}) (C {(append_dockerfile)} {(DQ ("RUN yum install -y clang git maven cmake"))}) (C {(append_dockerfile)} { (DQ ( "RUN yum install -y java-1.8.0-openjdk-devel python-devel zlib-devel libcurl-devel openssl-devel cyrus-sasl-devel cyrus-sasl-md5 apr-devel subversion-devel apr-utils-devel libevent-devel libev-devel" ) ) } ) (C {(append_dockerfile)} {(DQ ("RUN adduser mesos"))}) ] spids: [161 163 239 -1] ) (case_arm pat_list: [{(Lit_Other "*") (ubuntu) (Lit_Other "*")}] action: [ (C {(append_dockerfile)} {(DQ ("FROM ") ($ VSub_Name "$OS"))}) (C {(append_dockerfile)} {(DQ ("RUN rm -rf /var/lib/apt/lists/*"))}) (AndOr children: [ (C {(Lit_Other "[")} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(uname)} {(-m)})]) left_token: spids: [293 297] ) ) } {(Lit_Other "=")} {(DQ (x86_64))} {(Lit_Other "]")} ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CLANG_PKG) op: Equal rhs: {(clang-3.5)} spids: [310] ) ] spids: [310] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CLANG_PKG) op: Equal rhs: {(SQ )} spids: [315] ) ] spids: [315] ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) (C {(append_dockerfile)} {(DQ ("RUN apt-get update"))}) (C {(append_dockerfile)} { (DQ ("RUN apt-get -y install build-essential ") ($ VSub_Name "$CLANG_PKG") (" git maven autoconf libtool cmake") ) } ) (C {(append_dockerfile)} { (DQ ( "RUN apt-get -y install openjdk-7-jdk python-dev libcurl4-nss-dev libsasl2-dev libapr1-dev libsvn-dev libevent-dev libev-dev" ) ) } ) (C {(append_dockerfile)} {(DQ ("RUN apt-get -y install wget curl sed"))}) (C {(append_dockerfile)} {(DQ ("RUN adduser --disabled-password --gecos '' mesos"))}) ] spids: [242 245 360 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(C {(echo)} {(DQ ("Unknown OS ") ($ VSub_Name "$OS"))}) (C {(exit)} {(1)})] spids: [363 364 380 -1] ) ] spids: [154 158 382] ) (Case to_match: {($ VSub_Name "$COMPILER")} arms: [ (case_arm pat_list: [{(gcc)}] action: [ (C {(append_dockerfile)} {(DQ ("ENV CC gcc"))}) (C {(append_dockerfile)} {(DQ ("ENV CXX g++"))}) ] spids: [392 393 410 -1] ) (case_arm pat_list: [{(clang)}] action: [ (Case to_match: {($ VSub_Name "$OS")} arms: [ (case_arm pat_list: [{(Lit_Other "*") (ubuntu) (Lit_Other "*")}] action: [ (C {(append_dockerfile)} {(DQ ("ENV CC clang-3.5"))}) (C {(append_dockerfile)} {(DQ ("ENV CXX clang++-3.5"))}) ] spids: [424 427 444 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (C {(append_dockerfile)} {(DQ ("ENV CC clang"))}) (C {(append_dockerfile)} {(DQ ("ENV CXX clang++"))}) ] spids: [447 448 465 -1] ) ] spids: [417 421 468] ) ] spids: [413 414 471 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (C {(echo)} {(DQ ("Unknown Compiler ") ($ VSub_Name "$COMPILER"))}) (C {(exit)} {(1)}) ] spids: [474 475 491 -1] ) ] spids: [385 389 493] ) (C {(append_dockerfile)} {(DQ ("WORKDIR mesos"))}) (C {(append_dockerfile)} {(DQ ("COPY . /mesos/"))}) (C {(append_dockerfile)} {(DQ ("RUN chown -R mesos /mesos"))}) (C {(append_dockerfile)} {(DQ ("USER mesos"))}) (C {(append_dockerfile)} {(DQ ("ENV GTEST_OUTPUT xml:report.xml"))}) (C {(append_dockerfile)} {(DQ ("ENV DISTCHECK_CONFIGURE_FLAGS ") ($ VSub_Name "$CONFIGURATION"))}) (C {(append_dockerfile)} {(DQ ("ENV ") ($ VSub_Name "$ENVIRONMENT"))}) (If arms: [ (if_arm cond: [(C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$COVERITY_TOKEN"))} {(Lit_Other "]")})] action: [ (C {(append_dockerfile)} { (DQ ("ENV MESOS_VERSION ") (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(DQ (AC_INIT))} {(configure.ac)}) (C {(sed)} {(SQ <"s/AC_INIT[(]\\[mesos\\], \\[\\(.*\\)\\][)]/\\1/">)}) ] negated: False ) ] ) left_token: spids: [609 625] ) ) } ) (C {(append_dockerfile)} { (DQ ("RUN wget https://scan.coverity.com/download/linux64 --post-data ") (EscapedLiteralPart token:) ("token=") ($ VSub_Name "$COVERITY_TOKEN") ("&project=Mesos") (EscapedLiteralPart token:) (" -O coverity_tool.tgz") ) } ) (C {(append_dockerfile)} {(DQ ("RUN tar xvf coverity_tool.tgz; mv cov-analysis-linux* cov-analysis"))} ) (C {(append_dockerfile)} { (DQ ("CMD ./bootstrap && ./configure ") ($ VSub_Name "$CONFIGURATION") ( " && cov-analysis/bin/cov-build -dir cov-int make -j6 && tar czcf mesos.tgz cov-int && tail cov-int/build-log.txt && curl --form " ) (EscapedLiteralPart token:) ("token=") ($ VSub_Name "$COVERITY_TOKEN") (EscapedLiteralPart token:) (" --form ") (EscapedLiteralPart token:) ("email=dev@mesos.apache.org") (EscapedLiteralPart token:) (" --form ") (EscapedLiteralPart token:) ("file=@mesos.tgz") (EscapedLiteralPart token:) (" --form ") (EscapedLiteralPart token:) ("version=") ($ VSub_Name "$MESOS_VERSION") (EscapedLiteralPart token:) (" --form ") (EscapedLiteralPart token:) ("description='Continious Coverity Build'") (EscapedLiteralPart token:) (" https://scan.coverity.com/builds?project=Mesos") ) } ) ] spids: [-1 593] ) ] else_action: [ (Case to_match: {($ VSub_Name "$BUILDTOOL")} arms: [ (case_arm pat_list: [{(autotools)}] action: [ (C {(append_dockerfile)} { (DQ ("CMD ./bootstrap && ./configure ") ($ VSub_Name "$CONFIGURATION") (" && make -j6 distcheck 2>&1") ) } ) ] spids: [693 694 706 -1] ) (case_arm pat_list: [{(cmake)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFIGURATION) op: Equal rhs: { (BracedVarSub token: suffix_op: (PatSub pat: {(EscapedLiteralPart token:)} replace: {(DQ )} do_all: True do_prefix: False do_suffix: False ) spids: [722 730] ) } spids: [721] ) ] spids: [721] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFIGURATION) op: Equal rhs: { (BracedVarSub token: suffix_op: (PatSub pat: {(-)} replace: {(DQ (_))} do_all: True do_prefix: False do_suffix: False ) spids: [738 747] ) } spids: [737] ) ] spids: [737] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFIGURATION) op: Equal rhs: { (BracedVarSub token: suffix_op: (PatSub pat: {(__)} replace: {(DQ (-D))} do_all: True do_prefix: False do_suffix: False ) spids: [755 764] ) } spids: [754] ) ] spids: [754] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFIGURATION) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DCaret arg_word:{}) spids: [772 775] ) } spids: [771] ) ] spids: [771] ) (SimpleCommand words: [{(read)} {(-r)} {(-a)} {(array)}] redirects: [ (Redir op_id: Redir_TLess fd: -1 arg_word: {(DQ ($ VSub_Name "$CONFIGURATION"))} spids: [796] ) ] more_env: [(env_pair name:IFS val:{(SQ <" ">)} spids:[783])] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFIGURATION) op: Equal rhs: {(DQ )} spids: [804] ) ] spids: [804] ) (ForEach iter_name: element iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [816 821] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFIGURATION) op: Equal rhs: { (DQ ($ VSub_Name "$CONFIGURATION") (" ") ($ VSub_Name "$element") ("=1") ) } spids: [828] ) ] spids: [828] ) ] spids: [825 837] ) spids: [814 -1] ) (C {(append_dockerfile)} { (DQ ("CMD ./bootstrap && mkdir build && cd build && cmake ") ($ VSub_Name "$CONFIGURATION") (" .. && make -j6 check && make -j6") ) } ) ] spids: [709 710 866 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (C {(echo)} {(DQ ("Unknown build tool ") ($ VSub_Name "$BUILDTOOL"))}) (C {(exit)} {(1)}) ] spids: [869 870 886 -1] ) ] spids: [686 690 889] ) ] spids: [679 891] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TAG) op: Equal rhs: {(mesos-) (CommandSubPart command_list: (CommandList children: [(C {(date)} {(Lit_Other "+") (Lit_Other "%") (s)})] ) left_token: spids: [899 905] ) (-) ($ VSub_Name "$RANDOM") } spids: [897] ) ] spids: [897] ) (C {(docker)} {(build)} {(--no-cache) (Lit_Other "=") (true)} {(-t)} {($ VSub_Name "$TAG")} {(.)}) (C {(trap)} {(DQ ("docker rmi ") ($ VSub_Name "$TAG"))} {(EXIT)}) (C {(docker)} {(run)} {(--privileged)} {(--rm)} {($ VSub_Name "$TAG")}) ] )