This repository has been archived by the owner on Sep 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
local_build.sh
executable file
·77 lines (66 loc) · 2.7 KB
/
local_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
cd /LocalBuild/agent-resources
if [ $IS_INNER_CONTAINER == true ]
then
if [ ! -z "${BUILDSPEC_PATH}" ]
then
RELATIVE_PATH=${BUILDSPEC_PATH}
if [[ ${BUILDSPEC_PATH} = *"$SOURCE_PATH"* ]]
then
TEMP=${BUILDSPEC_PATH#$SOURCE_PATH}
RELATIVE_PATH=${TEMP#"/"}
fi
echo ${RELATIVE_PATH} > /codebuild/input/buildspec.yml
fi
touch /codebuild/output/log
tail -F /codebuild/output/log &
sh ./start > /dev/null
else
AGENT_ID=$(docker ps | sed -n 2p | cut -c 1-12)
AGENT_WAIT_ATTEMPT=1
while [[ -z ${AGENT_ID} ]]; do
if [[ ${WAIT_ATTEMPT} -gt 3 ]]; then
echo "Giving up!"
exit 1
fi
echo "Waiting for agent ID ..."
AGENT_WAIT_ATTEMPT=$(($AGENT_WAIT_ATTEMPT+1))
sleep 3s
AGENT_ID=$(docker ps | sed -n 2p | cut -c 1-12)
done
echo "Got agent ID ${AGENT_ID}"
export LOCAL_AGENT_IMAGE=$(docker inspect --format='{{.Config.Image}}' ${AGENT_ID})
export CODEBUILD_LOCAL_SOURCE_DIRECTORY=${SOURCE}
export IMAGE_FOR_CODEBUILD_LOCAL_BUILD=${IMAGE_NAME}
export CODEBUILD_LOCAL_ARTIFACTS_DIRECTORY=${ARTIFACTS}
export CODEBUILD_LOCAL_BUILDSPEC_PATH=${BUILDSPEC}
cp docker-compose.yml customer-specific.yml
# Environment variable file has precedent over AWS Configuration. Any AWS config variables in both the customers local space
# and their environment variable file will receive the value from the file. This is maintained by ensuring that we set the
# file variables after we set up the customers AWS Configuration.
if [ ! -z "${AWS_CONFIGURATION}" ]
then
if [[ "$AWS_CONFIGURATION" = *".aws"* ]]
then
/LocalBuild/agent-resources/bin/edit-docker-compose ${AWS_CONFIGURATION} /LocalBuild/agent-resources/customer-specific.yml "AWSConfiguration"
fi
printenv | grep -v AWS_CONFIGURATION | grep AWS_ > awsconfig.txt
/LocalBuild/agent-resources/bin/edit-docker-compose awsconfig.txt /LocalBuild/agent-resources/customer-specific.yml "EnvironmentVariables"
fi
if [ ! -z "${ENV_VAR_FILE}" ]
then
/LocalBuild/agent-resources/bin/edit-docker-compose /LocalBuild/envFile/$ENV_VAR_FILE /LocalBuild/agent-resources/customer-specific.yml "EnvironmentVariables"
fi
# Validate docker-compose config
docker-compose -f customer-specific.yml config --quiet || exit 1
# Clean up any previous runs
docker-compose -f customer-specific.yml down -v
# Start
docker-compose -f customer-specific.yml up --abort-on-container-exit | tee build_logs
if grep -q "Phase complete: [A-Z_]* Success: false" build_logs
then
exit 1
else
exit 0
fi
fi