-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yaml
31 lines (28 loc) · 1.44 KB
/
buildspec.yaml
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
version: 0.2
phases:
install:
runtime-versions:
java: corretto11.x # openjdk:11 is no longer supported for aws/codebuild/standard:4.0
commands:
- apt-get -y update && apt-get -y install moreutils # For using 'sponge' later
- mvn clean install # Creates a jar file
build:
commands:
- $(aws ecr get-login --no-include-email --region $AWS_REGION) # Login to AWS ECR
- IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) # Extracting first 7 characters of the commitID to use it as ImageTag
- docker build -t $ECR_REPO:latest . # Build the image with latest tag
- docker tag $ECR_REPO:latest $ECR_REPO:$IMAGE_TAG # Have an additional tag for the image relating to Git Commit
post_build:
commands:
- docker push $ECR_REPO:latest # Pushing the image to AWS ECR
- docker push $ECR_REPO:$IMAGE_TAG
- jq '.Parameters.ImageTag = "'$IMAGE_TAG'"' config-dev.json | sponge config-dev.json # Changes the ImageTag value for the Task Definition in deploy stage
- jq '.Parameters.ImageTag = "'$IMAGE_TAG'"' config-prod.json | sponge config-prod.json
artifacts:
files: # All the files which makes out of the build stage and shall be forwarded to the next stage are mentioned here. Every other file is no more available in the pipeline
- template.yaml
- config-dev.json
- config-prod.json
cache:
paths:
- '/root/.m2/**/*' # Caches maven dependencies for a quicker build