add buildspec.yml codebuild.yml ecr.yml file

This commit is contained in:
unknown 2023-08-15 21:05:48 -04:00
parent 9175223950
commit 96b72e2bba
4 changed files with 117 additions and 9 deletions

5
Dockerfile Normal file
View file

@ -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"]

View file

@ -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
...
- target/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar

89
codebuild.yml Normal file
View file

@ -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:*

11
ecr.yml Normal file
View file

@ -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