Skip to content

Commit a1739f3

Browse files
committed
Add option for secondary sources
1 parent f25d6b3 commit a1739f3

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

local_builds/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ Download and use our codebuild_build.sh script to run your local builds.
2424

2525
**Optional:**
2626
-l Used to override the default local agent image.
27-
-s Used to specify a source directory. Defaults to the current working directory.
2827
-c Use the AWS configuration and credentials from your local host. This includes ~/.aws and any AWS_* environment variables.
2928
-b Used to specify a buildspec override file. Defaults to buildspec.yml in the source directory.
3029
-e Used to specify a file containing environment variables.
3130
-m Used to mount the source directory to the customer build container directly.
31+
-s Used to specify a source directory. Defaults to the current working directory.
32+
* First (-s) is for primary source
33+
* Use additional (-s) in `<sourceIdentifier>:<sourceLocation>` format for secondary source
34+
* For `sourceIdentifier`, use a value that is fewer than 128 characters and contains only alphanumeric characters and underscores
3235

3336
**Environment variable file format:**
3437
* Expects each line to be in VAR=VAL format

local_builds/codebuild_build.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ function usage {
3535
echo " -a Used to specify an artifact output directory."
3636
echo "Options:"
3737
echo " -l IMAGE Used to override the default local agent image."
38-
echo " -s DIR Used to specify a source directory. Defaults to the current working directory."
38+
echo " -s Used to specify source information. Defaults to the current working directory for primary source."
39+
echo " * First (-s) is for primary source"
40+
echo " * Use additional (-s) in <sourceIdentifier>:<sourceLocation> format for secondary source"
41+
echo " * For sourceIdentifier, use a value that is fewer than 128 characters and contains only alphanumeric characters and underscores"
3942
echo " -c Use the AWS configuration and credentials from your local host. This includes ~/.aws and any AWS_* environment variables."
4043
echo " -b FILE Used to specify a buildspec override file. Defaults to buildspec.yml in the source directory."
4144
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
6164
b ) buildspec=$OPTARG;;
6265
c ) awsconfig_flag=true;;
6366
m ) mount_src_dir_flag=true;;
64-
s ) source_dir=$OPTARG;;
67+
s ) source_dirs+=("$OPTARG");;
6568
e ) environment_variable_file=$OPTARG;;
6669
l ) local_agent_image=$OPTARG;;
6770
h ) usage; exit;;
@@ -86,13 +89,6 @@ then
8689
exit 1
8790
fi
8891

89-
if [ -z "$source_dir" ]
90-
then
91-
source_dir=$(allOSRealPath $PWD)
92-
else
93-
source_dir=$(allOSRealPath $source_dir)
94-
fi
95-
9692
docker_command="docker run -it "
9793
if isOSWindows
9894
then
@@ -102,8 +98,24 @@ else
10298
fi
10399

104100
docker_command+="\"IMAGE_NAME=$image_name\" -e \
105-
\"ARTIFACTS=$(allOSRealPath $artifact_dir)\" -e \
106-
\"SOURCE=$source_dir\""
101+
\"ARTIFACTS=$(allOSRealPath $artifact_dir)\""
102+
103+
if [ -z "$source_dirs" ]
104+
then
105+
docker_command+=" -e \"SOURCE=$(allOSRealPath $PWD)\""
106+
else
107+
for index in "${!source_dirs[@]}"; do
108+
if [ $index -eq 0 ]
109+
then
110+
docker_command+=" -e \"SOURCE=$(allOSRealPath ${source_dirs[$index]})\""
111+
else
112+
identifier=${source_dirs[$index]%%:*}
113+
src_dir=$(allOSRealPath ${source_dirs[$index]#*:})
114+
115+
docker_command+=" -e \"SECONDARY_SOURCE_$index=$identifier:$src_dir\""
116+
fi
117+
done
118+
fi
107119

108120
if [ -n "$buildspec" ]
109121
then
@@ -162,4 +174,4 @@ echo ""
162174
echo $exposed_command
163175
echo ""
164176

165-
eval $docker_command
177+
eval $docker_command

0 commit comments

Comments
 (0)