-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_and_update.sh
95 lines (80 loc) · 3.12 KB
/
build_and_update.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/bash
show_help() {
echo "SYNTAX: ./build_and_update.sh COMMAND"
echo ""
echo "COMMANDS:"
echo " all Builds and updates all services and containers used in deployment."
echo ""
echo " changed Builds and updates services with files modified since the last successful build."
echo " The files changed are determined via git diff of the correstponding commit IDs."
echo ""
exit 1
}
build_api_service() {
echo "Updating Lambda function (API Service)"
cd $CODEBUILD_SRC_DIR/lambda_services; zip -r /tmp/id.zip api_service
aws lambda update-function-code --function-name apbs-$IMAGE_TAG-id-L --publish --zip-file fileb:///tmp/id.zip
}
build_job_service() {
echo "Updating Lambda function (Job Service)"
cd $CODEBUILD_SRC_DIR/lambda_services; zip -r /tmp/job.zip job_service
aws lambda update-function-code --function-name apbs-$IMAGE_TAG-job-L --publish --zip-file fileb:///tmp/job.zip
}
build_docker() {
echo "Building the Docker image..."
export APBS_VERSION=`cat versions.json | jq -r '.apbs'`
export PDB2PQR_VERSION=`cat versions.json | jq -r '.pdb2pqr'`
echo docker build --build-arg PDB2PQR_VERSION=$PDB2PQR_VERSION --build-arg APBS_VERSION=$APBS_VERSION -t $IMAGE_REPO_NAME:main.base $CODEBUILD_SRC_DIR/src/docker
docker build --build-arg PDB2PQR_VERSION=$PDB2PQR_VERSION --build-arg APBS_VERSION=$APBS_VERSION -t $IMAGE_REPO_NAME:main.base $CODEBUILD_SRC_DIR/src/docker
docker tag $IMAGE_REPO_NAME:main.base $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
echo "Pushing the Docker image..."
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
#TODO: Restart running ECS task
}
build_changed() {
echo "Building services and containers modified since last successful build."
api_service_changed=0
job_service_changed=0
docker_changed=0
git diff --name-only $CODEBUILD_RESOLVED_SOURCE_VERSION $LAST_SUCCESSFUL_COMMIT_ID | while read file_path || [[ -n $file_path ]];
do
if [[ $file_path == src/docker/* ]] || [[ $file_path == versions.json ]] && [[ $docker_changed -ne 1 ]]
then
docker_changed=1
build_docker
fi
if [[ $file_path == lambda_services/job_service/* ]] && [[ $job_service_changed -ne 1 ]]
then
job_service_changed=1
build_job_service
fi
if [[ $file_path == lambda_services/api_service/* ]] && [[ $api_service_changed -ne 1 ]] # condition to check if path in ./lambda_services/api_service/ directory
then
api_service_changed=1
build_api_service
fi
done
}
build_all() {
echo "Building all services and containers"
build_docker
build_job_service
build_api_service
}
cli_argument="$1"
if [[ -z $cli_argument ]] ; then
echo "No argument provided."
show_help
else
case $cli_argument in
all)
build_all
;;
Webhook)
build_changed
;;
*)
build_all
;;
esac
fi