codebuild.yaml cats and dogs workshop

version: 0.2

phases:
pre_build:
commands:
- aws --version
- aws ecr get-login-password --region cn-northwest-1 | docker login --username AWS --password-stdin .dkr.ecr.cn-northwest-1.amazonaws.com.cn
- export REPOSITORY_URI=.dkr.ecr.cn-northwest-1.amazonaws.com.cn/lookup
- export COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- export IMAGE_TAG=${COMMIT_HASH:=latest}
- echo FROM public.ecr.aws/amazonlinux/amazonlinux:2 >> Dockerfile
- echo WORKDIR /app >> Dockerfile
- echo COPY test /app/ >> Dockerfile
- echo COPY config.ini /app >> Dockerfile
- echo RUN chmod +x /app/test >> Dockerfile
- echo EXPOSE 80 >> Dockerfile
- echo CMD ["/app/test"] >> Dockerfile
build:
commands:
- echo Build started on date
- echo Building the Docker image...
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on date
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"test","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json

FROM public.ecr.aws/amazonlinux/amazonlinux:2
WORKDIR /app
COPY test /app/
COPY config.ini /app
RUN chmod +x /app/test
EXPOSE 80
CMD ["/app/test"]

sudo tee /etc/yum.repos.d/pgdg.repo <<EOF
[pgdg14]
name=PostgreSQL 14 for RHEL/CentOS 7 - x86_64
baseurl=https://download.postgresql.org/pub/repos/yum/14/redhat/rhel-7-x86_64
enabled=1
gpgcheck=0
EOF

{
"pipeline": {
"roleArn": "arn:aws:iam::111111111111:role/AWS-CodePipeline-Service",
"stages": [
{
"name": "Source",
"actions": [
{
"inputArtifacts": [],
"name": "Source",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"version": "1",
"provider": "S3"
},
"outputArtifacts": [
{
"name": "MyApp"
}
],
"configuration": {
"S3Bucket": "awscodepipeline-demo-bucket",
"S3ObjectKey": "aws-codepipeline-s3-aws-codedeploy_linux.zip"
},
"runOrder": 1
}
]
},
{
"name": "Beta",
"actions": [
{
"inputArtifacts": [
{
"name": "MyApp"
}
],
"name": "CodePipelineDemoFleet",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"version": "1",
"provider": "CodeDeploy"
},
"outputArtifacts": [],
"configuration": {
"ApplicationName": "CodePipelineDemoApplication",
"DeploymentGroupName": "CodePipelineDemoFleet"
},
"runOrder": 1
}
]
}
],
"artifactStore": {
"type": "S3",
"location": "codepipeline-us-east-1-11EXAMPLE11"
},
"name": "MySecondPipeline",
"version": 1
}
}

posted @ 2025-05-23 14:38  我又飞了  阅读(13)  评论(0)    收藏  举报