-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild_image.sh
49 lines (38 loc) · 1.2 KB
/
build_image.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
#!/bin/bash
abort()
{
echo >&2 '
***************
*** ABORTED ***
***************
'
echo "An error occurred. Exiting..." >&2
exit 1
}
trap 'abort' 0
set -e
sh ./gradlew bootJar
mkdir build/dependency
cd build/dependency
jar -xf ../libs/*.jar
cd ../..
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 371417955885.dkr.ecr.us-east-1.amazonaws.com
docker build -t springio/dockerize-spring-boot .
# Extract branch name from CODEBUILD_WEBHOOK_HEAD_REF
# E.g. refs/heads/main
regex="([^\/]+$)"
echo $CODEBUILD_WEBHOOK_EVENT
echo $CODEBUILD_WEBHOOK_BASE_REF
echo $CODEBUILD_WEBHOOK_HEAD_REF
TAG=$([ "$CODEBUILD_WEBHOOK_EVENT" = "PULL_REQUEST_MERGED" ] && [ "$CODEBUILD_WEBHOOK_BASE_REF" = "refs/heads/main" ] && echo "latest" || if [[ $CODEBUILD_WEBHOOK_HEAD_REF =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi)
IMAGE_URI=public.ecr.aws/f5n7q8r5/aws-spring-param-store:$TAG
echo "the tag $TAG, $IMAGE_URI"
docker tag springio/dockerize-spring-boot:latest $IMAGE_URI
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/f5n7q8r5
docker push $IMAGE_URI
trap : 0
echo >&2 '
************
*** DONE ***
************
'