From b0e57c1fa494e35f1629e85da30c585442ad9f0b Mon Sep 17 00:00:00 2001 From: Darren McGhee Date: Mon, 20 Apr 2020 12:08:34 +0100 Subject: [PATCH] modified buildspec --- buildspec.yml | 9 +++++++-- codebuild.yml | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index defd69462..604a36d6f 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -6,14 +6,19 @@ phases: java: openjdk8 pre_build: commands: - - echo Nothing to do in prebuild + - AWS_ACC=$(echo $CODEBUILD_BUILD_ARN | cut -d':' -f5) + - REPOSITORY_URI=$AWS_ACC.dkr.ecr.$AWS_REGION.amazonaws.com build: commands: - echo Build started on `date` - mvn package + - docker build . -t $REPOSITORY_URI/${REPO}:latest + - echo Build completed on `date` post_build: commands: - - echo Build completed on `date` + - $(aws ecr get-login --region $AWS_REGION --no-include-email) + - aws ecr describe-repositories --registry-id ${AWS_ACC} --repository-name ${REPO} + - docker push $REPOSITORY_URI/${REPO}:latest artifacts: files: - target/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar \ No newline at end of file diff --git a/codebuild.yml b/codebuild.yml index 9ae85d499..a3b5efb04 100644 --- a/codebuild.yml +++ b/codebuild.yml @@ -30,8 +30,13 @@ Resources: Type: OAUTH Environment: ComputeType: BUILD_GENERAL1_SMALL - Image: aws/codebuild/standard:latest + Image: aws/codebuild/standard:3.0 Type: LINUX_CONTAINER + PrivilegedMode: True + EnvironmentVariables: + - Name: REPO + Type: PLAINTEXT + Value: !Ref ECRRepository LogsConfig: CloudWatchLogs: GroupName: !Ref LogGroup @@ -67,5 +72,12 @@ Resources: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents - - + - ecr:GetAuthorizationToken + - PolicyName: ecr + PolicyDocument: + Version: 2012-10-17 + Statement: + - Resource: !GetAtt ECRRepository.Arn + Effect: Allow + Action: + - ecr:* \ No newline at end of file