-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yml
120 lines (109 loc) · 4.45 KB
/
buildspec.yml
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
version: 0.2
# Pre-requisites
# - Create CodeBuild project
# - Provide minimal github credentials to access public repo
# test
phases:
pre_build:
on-failure: ABORT
commands:
- cp settings.xml ~/.m2/
- export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain cdlib-uc3-mrt --domain-owner $AWS_ACCOUNT_ID --region $AWS_REGION --query authorizationToken --output text`
- aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin ${ECR_REGISTRY}
- COMMIT=`git rev-parse --short HEAD`
- # Get semantic tags for commit otherwise get all tags for commit, sort and choose the last value
- TAG=`(git tag --contains $COMMIT | egrep "^[0-9]+\.[0-9]+\.[0-9]+$" || git tag --contains $COMMIT || echo '') | sort | tail -1`
- |
if [[ "$MODE" == "OnPush" ]]
then
# Get Tag || Get Branch || Alternate Branch Lookup || Get Committ
BRANCHTAG=`echo $TAG | grep . || git symbolic-ref -q --short HEAD || git name-rev $(git rev-parse --short HEAD) | cut -d' ' -f2 || git rev-parse --short HEAD`
else
BRANCHTAG=$BRANCHNAME
fi
- DOCKTAG=$BRANCHTAG
- COMMITDATE=`git --no-pager log -1 --pretty='format:%cd' --date='format:%Y-%m-%d %H:%M:%S'`
- echo "Branchtag ${BRANCHTAG}; COMMITDATE=${COMMITDATE}; REPONAME=${REPONAME}; BRANCHNAME=${BRANCHNAME}"
build:
on-failure: ABORT
commands:
# - mvn -ntp clean install -Ddocker.skip -DskipITs -Dmaven.test.skip=true
- docker pull ${ECR_REGISTRY}/docker-hub/ghusta/fakesmtp
- mvn -ntp clean install
- |
if [[ "${BRANCHTAG}" == "main" ]]
then
SEMVER=''
DOCKTAG='dev'
elif [[ "${BRANCHTAG}" == "queue_LIB" ]]
then
SEMVER=''
DOCKTAG='dev'
elif [[ "${TAG}" == "" ]]
then
SEMVER="-Dversion=${BRANCHTAG}-SNAPSHOT"
else
SEMVER="-Dversion=${BRANCHTAG}"
fi
- echo "Semver [${SEMVER}]"
- mkdir -p /build/static
- |
echo "build_tag: ${BRANCHTAG}" > /build/static/build.content.txt
- ${JAVA_HOME}/bin/jar uf $(ls ingest-war/target/mrt-ingestwar-*.war) -C /build static/build.content.txt
- |
mvn -ntp deploy:deploy-file \
-Durl=${CODEARTIFACT_URL} \
-DrepositoryId=cdlib-uc3-mrt-uc3-mrt-java \
-Dfile=$(ls ingest-war/target/mrt-ingestwar-*.war) ${SEMVER}
- |
docker build --push --quiet \
--build-arg ECR_REGISTRY=${ECR_REGISTRY} \
-t ${ECR_REGISTRY}/${REPONAME}:${DOCKTAG} .
# report results
- mkdir -p reports
- RPT=reports/${REPONAME}.md
- echo "## Semantic Tags" > $RPT
- |
git for-each-ref --sort=-creatordate --format '- %(refname) (%(creatordate:short))' refs/tags \
| egrep "tags/[0-9]+\.[0-9]+\.[0-9]+ " \
| sed -e "s/refs\/tags\///" \
| head -10 >> $RPT
- echo "## Feature Tags" >> $RPT
- |
git for-each-ref --sort=-creatordate --format '- %(refname) (%(creatordate:short))' refs/tags \
| egrep -v "tags/[0-9]+\.[0-9]+\.[0-9]+ " \
| egrep -v "sprint-" \
| sed -e "s/refs\/tags\///" \
| head -10 >> $RPT
- echo "## Docker Image Tags ${REPONAME}" >> $RPT
- |
aws ecr list-images --repository-name ${REPONAME} --filter tagStatus=TAGGED --output=text \
| cut -f3 \
| sed -e "s/^/- /" \
| sort >> $RPT
- |
for pkg in mrt-ingestwar
do
echo "## Code Artifact Packages for $pkg" >> $RPT
aws codeartifact list-package-versions \
--domain=cdlib-uc3-mrt --repository=uc3-mrt-java \
--format=maven --namespace=org.cdlib.mrt \
--package=$pkg --status=Published --output=text \
| grep Published \
| cut -f4 \
| sed -e "s/^/- /" \
| sort >> $RPT
for ver in `aws codeartifact list-package-versions \
--domain=cdlib-uc3-mrt --repository=uc3-mrt-java \
--format=maven --namespace=org.cdlib.mrt \
--package=$pkg --status=Unlisted \
--output=text | grep Unlisted | cut -f4`
do
aws codeartifact delete-package-versions \
--domain=cdlib-uc3-mrt --repository=uc3-mrt-java \
--format=maven --namespace=org.cdlib.mrt \
--package=$pkg --versions=$ver --no-cli-pager
done
done
- aws s3 cp $RPT s3://${S3CFBUCKET}/$RPT
- aws cloudfront create-invalidation --distribution-id ${CFDISTRIBUTIONID} --paths /reports/* --region us-east-1