From a1739f3d37a0836a1c58bd6b380a59cfbb324637 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 18 Mar 2019 18:54:49 -0700 Subject: [PATCH] Add option for secondary sources --- local_builds/README.md | 5 ++++- local_builds/codebuild_build.sh | 36 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/local_builds/README.md b/local_builds/README.md index 7d53c686..4fd53c7a 100644 --- a/local_builds/README.md +++ b/local_builds/README.md @@ -24,11 +24,14 @@ Download and use our codebuild_build.sh script to run your local builds. **Optional:** -l Used to override the default local agent image. - -s Used to specify a source directory. Defaults to the current working directory. -c Use the AWS configuration and credentials from your local host. This includes ~/.aws and any AWS_* environment variables. -b Used to specify a buildspec override file. Defaults to buildspec.yml in the source directory. -e Used to specify a file containing environment variables. -m Used to mount the source directory to the customer build container directly. + -s Used to specify a source directory. Defaults to the current working directory. + * First (-s) is for primary source + * Use additional (-s) in `:` format for secondary source + * For `sourceIdentifier`, use a value that is fewer than 128 characters and contains only alphanumeric characters and underscores **Environment variable file format:** * Expects each line to be in VAR=VAL format diff --git a/local_builds/codebuild_build.sh b/local_builds/codebuild_build.sh index 82412d58..6e4f9d33 100755 --- a/local_builds/codebuild_build.sh +++ b/local_builds/codebuild_build.sh @@ -35,7 +35,10 @@ function usage { echo " -a Used to specify an artifact output directory." echo "Options:" echo " -l IMAGE Used to override the default local agent image." - echo " -s DIR Used to specify a source directory. Defaults to the current working directory." + echo " -s Used to specify source information. Defaults to the current working directory for primary source." + echo " * First (-s) is for primary source" + echo " * Use additional (-s) in : format for secondary source" + echo " * For sourceIdentifier, use a value that is fewer than 128 characters and contains only alphanumeric characters and underscores" echo " -c Use the AWS configuration and credentials from your local host. This includes ~/.aws and any AWS_* environment variables." echo " -b FILE Used to specify a buildspec override file. Defaults to buildspec.yml in the source directory." echo " -m Used to mount the source directory to the customer build container directly." @@ -61,7 +64,7 @@ while getopts "cmi:a:s:b:e:l:h" opt; do b ) buildspec=$OPTARG;; c ) awsconfig_flag=true;; m ) mount_src_dir_flag=true;; - s ) source_dir=$OPTARG;; + s ) source_dirs+=("$OPTARG");; e ) environment_variable_file=$OPTARG;; l ) local_agent_image=$OPTARG;; h ) usage; exit;; @@ -86,13 +89,6 @@ then exit 1 fi -if [ -z "$source_dir" ] -then - source_dir=$(allOSRealPath $PWD) -else - source_dir=$(allOSRealPath $source_dir) -fi - docker_command="docker run -it " if isOSWindows then @@ -102,8 +98,24 @@ else fi docker_command+="\"IMAGE_NAME=$image_name\" -e \ - \"ARTIFACTS=$(allOSRealPath $artifact_dir)\" -e \ - \"SOURCE=$source_dir\"" + \"ARTIFACTS=$(allOSRealPath $artifact_dir)\"" + +if [ -z "$source_dirs" ] +then + docker_command+=" -e \"SOURCE=$(allOSRealPath $PWD)\"" +else + for index in "${!source_dirs[@]}"; do + if [ $index -eq 0 ] + then + docker_command+=" -e \"SOURCE=$(allOSRealPath ${source_dirs[$index]})\"" + else + identifier=${source_dirs[$index]%%:*} + src_dir=$(allOSRealPath ${source_dirs[$index]#*:}) + + docker_command+=" -e \"SECONDARY_SOURCE_$index=$identifier:$src_dir\"" + fi + done +fi if [ -n "$buildspec" ] then @@ -162,4 +174,4 @@ echo "" echo $exposed_command echo "" -eval $docker_command +eval $docker_command \ No newline at end of file