From 96b72e2bba775646c3fb129849c3626672641ef0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Aug 2023 21:05:48 -0400 Subject: [PATCH] add buildspec.yml codebuild.yml ecr.yml file --- Dockerfile | 5 +++ buildspec.yml | 21 ++++++------ codebuild.yml | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ ecr.yml | 11 +++++++ 4 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 Dockerfile create mode 100644 codebuild.yml create mode 100644 ecr.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c0b57b0f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM amazoncorretto:17.0.7-alpine +VOLUME /tmp +ADD target/spring-petclinic-3.1.0.jar app.jar +EXPOSE 80 +ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] \ No newline at end of file diff --git a/buildspec.yml b/buildspec.yml index 0b9d6d036..f6133c99b 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -1,21 +1,24 @@ ---- version: 0.2 + phases: install: - runtime-versions: - java: corretto17 + runtime-versions: + java: openjdk8 pre_build: commands: - - echo Nothing to do in prebuil + - 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 install + - 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: - - spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar -... \ No newline at end of file + - target/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar \ No newline at end of file diff --git a/codebuild.yml b/codebuild.yml new file mode 100644 index 000000000..f71394e85 --- /dev/null +++ b/codebuild.yml @@ -0,0 +1,89 @@ +--- +AWSTemplateFormatVersion: 2010-09-09 + + +Parameters: + GitHubUrl: + Type: String + LogGroup: + Type: String + LogStream: + Type: String + RepoName: + Type: String + AllowedPattern: (?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)* + +Resources: + ECRRepository: + Type: AWS::ECR::Repository + Properties: + RepositoryName: !Ref RepoName + CodeBuildProject: + Type: AWS::CodeBuild::Project + Properties: + Artifacts: + Type: NO_ARTIFACTS + Source: + Type: GITHUB + Location: !Ref GitHubUrl + Auth: + Type: OAUTH + Environment: + ComputeType: BUILD_GENERAL1_SMALL + Image: aws/codebuild/standard:3.0 + Type: LINUX_CONTAINER + PrivilegedMode: True + EnvironmentVariables: + - Name: REPO + Type: PLAINTEXT + Value: !Ref ECRRepository + LogsConfig: + CloudWatchLogs: + GroupName: !Ref LogGroup + Status: ENABLED + StreamName: !Ref LogStream + Triggers: + FilterGroups: + - - Type: EVENT + Pattern: PUSH + Webhook: True + Name: !Ref AWS::StackName + ServiceRole: !Ref CodeBuildServiceRole + + CodeBuildServiceRole: + Type: AWS::IAM::Role + Properties: + Path: / + AssumeRolePolicyDocument: + Version: 2012-10-17 + Statement: + - Effect: Allow + Principal: + Service: codebuild.amazonaws.com + Action: sts:AssumeRole + Policies: + - PolicyName: root + PolicyDocument: + Version: 2012-10-17 + Statement: + - Resource: "*" + Effect: Allow + Action: + - logs:CreateLogGroup + - logs:CreateLogStream + - logs:PutLogEvents + - ecr:GetAuthorizationToken + - PolicyName: ecr + PolicyDocument: + Version: 2012-10-17 + Statement: + - Resource: !GetAtt ECRRepository.Arn + Effect: Allow + Action: + - ecr:* + + + + + + diff --git a/ecr.yml b/ecr.yml new file mode 100644 index 000000000..5ef7adce7 --- /dev/null +++ b/ecr.yml @@ -0,0 +1,11 @@ +--- +AWSTemplateFormatVersion: 2010-09-09 +Parameters: + RepoName: + Type: String + AllowedPattern: (?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)* +Resources: + ECRRepository: + Type: AWS::ECR::Repository + Properties: + RepositoryName: !Ref RepoName \ No newline at end of file