-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yml
45 lines (44 loc) · 2.02 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
version: 0.2
phases:
install:
runtime-versions:
docker: 19
pre_build:
commands:
- yum update -y
- yum install -y bind-utils
- echo nslookup
- nslookup testing-ca-074598670345.d.codeartifact.us-east-2.amazonaws.com
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- AWS_ACCOUNT_ID=$(echo ${CODEBUILD_BUILD_ARN} | cut -d ':' -f 5)
- REPOSITORY_URI=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/hello-world
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG1=${COMMIT_HASH:=latest}1
- IMAGE_TAG2=${COMMIT_HASH:=latest}2
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- ls
- docker build -t $REPOSITORY_URI:latest . #This uses Dockerfile in the repository to copy Java binary and create a Docker image
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG1
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG2
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG1
- docker push $REPOSITORY_URI:$IMAGE_TAG2
- echo "configure ecs task definition file"
- sed -i "s@{{AWS_ACCOUNT_ID}}@${AWS_ACCOUNT_ID}@g" task-definition.json
- sed -i "s@{{AWS_REGION}}@${AWS_REGION}@g" task-definition.json
- sed -i "s@{{APPLICATION_NAME_1}}@hello-world@g" task-definition.json
- sed -i "s@{{APPLICATION_NAME_2}}@hellow-world2@g" task-definition.json
- echo Writing image definitions file...
- printf '[{"name":"hello-world","imageUri":"%s"},{"name":"hellow-world2","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG1 $REPOSITORY_URI:$IMAGE_TAG2 > imagedefinitions.json # name should be name of container in task definition
- cat imagedefinitions.json
artifacts:
files: imagedefinitions.json