-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildspec.yml
75 lines (67 loc) · 2.7 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
version: 0.2
# Pre-requisites
# - Create CodeBuild project
# - Provide minimal github credentials to access public repo
# test
phases:
pre_build:
on-failure: ABORT
commands:
- 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
- echo "Branchtag ${BRANCHTAG}; COMMITDATE=${COMMITDATE}; REPONAME=${REPONAME}; BRANCHNAME=${BRANCHNAME}"
build:
on-failure: ABORT
commands:
# 3.2.4 is required
#- rbenv versions
#- bundle install
#- bundle exec rubocop
- |
if [[ "${BRANCHTAG}" == "main" ]]
then
DOCKTAG='dev'
fi
- |
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
- |
for img in ${REPONAME}
do
echo "## Docker Image Tags $img" >> $RPT
aws ecr list-images --repository-name $img --filter tagStatus=TAGGED --output=text \
| cut -f3 \
| sed -e "s/^/- /" \
| sort >> $RPT
done
- aws s3 cp $RPT s3://${S3CFBUCKET}/$RPT
- aws s3 cp swagger.html s3://${S3CFBUCKET}/api/${REPONAME}/index.html
- aws s3 cp swagger.yml s3://${S3CFBUCKET}/api/${REPONAME}/
- aws cloudfront create-invalidation --distribution-id ${CFDISTRIBUTIONID} --paths /reports/* --region us-east-1
- aws cloudfront create-invalidation --distribution-id ${CFDISTRIBUTIONID} --paths /api/${REPONAME}/ --region us-east-1