-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildspec.yml
40 lines (40 loc) · 1.83 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
version: 0.2
env:
variables:
IMAGE_REPO_NAME: INSERT_REPO_NAME_HERE
AWS_ACCOUNT_ID: INSERT_ACCOUNT_ID_HERE
phases:
pre_build:
commands:
- GITBRANCH=${CODEBUILD_INITIATOR##*.}
- IMAGE_TAG=${GITBRANCH}
- DOCKER_IMAGE1=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
- echo Logging in to Amazon ECR...
- $(aws ecr get-login --region $AWS_DEFAULT_REGION)
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $DOCKER_IMAGE1
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- echo docker image $DOCKER_IMAGE1
- docker push $DOCKER_IMAGE1
- sed "s|__DOCKER_IMAGE1__|$DOCKER_IMAGE1|g" Dockerrun.aws.json.tpl >> Dockerrun.aws.json
- echo renamed and replaced variables in Dockerrun.aws.json.tpl file
- echo deleting Dockerfile
- rm Dockerfile
- echo Configuring awslogs container logging
- LOGCONFIG=$(grep name Dockerrun.aws.json | awk -F":" '{print $2}' | sed 's/[",]//g' | awk '{print " [stream-"$1"-container]\\n log_group_name=`{\"Fn::Join\":[\"/\", [\"/aws/elasticbeanstalk\", { \"Ref\":\"AWSEBEnvironmentName\" }]]}`/"$1"/stdouterr\\n log_stream_name={instance_id}\\n file=/var/log/containers/"$1"-*-stdouterr.log\\n\\n"}' | tr -d "\n")
- awk -v S="$LOGCONFIG" '/__LOGCONFIG__/{$0=S}1' .ebextensions/00-logstream.config.tpl >> .ebextensions/00-logstream.config
- echo Copying git branch specific configs from $GITBRANCH
- cp .ebextensions_$GITBRANCH/* .ebextensions/
- cp -R .ebextensions ebextensions
artifacts:
files:
- Dockerrun.aws.json
- ebextensions/**/*
- .ebextensions/**/*