forked from vigneshsweekaran/hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yml
50 lines (47 loc) · 2.1 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
version: 0.2
env:
variables:
IMAGE_REPO_NAME: "hello-world"
AWS_ACCOUNT_ID: "616853969531"
parameter-store:
DOCKER_PASSWORD: /codeBuild/dockerPassword
phases:
install:
runtime-versions:
java: corretto8
commands:
- yum install -y maven
finally:
- java -version
- mvn --version
pre_build:
commands:
- echo Logging in to Dockerhub for docker pull limit...
- docker login -u vigneshsweekaran -p $DOCKER_PASSWORD
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
build:
on-failure: ABORT
commands:
- echo Build started on `date`
- echo Maven build...
- mvn clean package
- echo Building the Docker image...
- docker build -t $IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER .
- docker tag $IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER
- docker tag $IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:latest
post_build:
on-failure: ABORT
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:latest
- sed -i "s/aws_region/$AWS_DEFAULT_REGION/" codedeploy/scripts/application_start.sh
- sed -i "s/repository_url/$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/" codedeploy/scripts/application_start.sh
- sed -i "s/image_url/$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com\/$IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER/" codedeploy/scripts/application_start.sh
artifacts:
files:
- appspec.yml
- codedeploy/scripts/*
name: hello-world-build-artifacts