@@ -16,39 +16,40 @@ phases:
1616 commands :
1717 - echo Logging in to Docker Hub...
1818 - echo $DOCKER_HUB_PAT | docker login -u $DOCKER_HUB_USERNAME --password-stdin
19+
20+ - echo "Logging in to AWS ECR..."
21+ - ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
22+ - AWS_REGION=us-east-1
23+ - ECR_REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
24+ - aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
1925
2026 build :
2127 # This will build and push the docker image to ECR and package the
2228 # Cloudformation template to be passed as an Artifact to future pipeline
2329 # steps. It will also run unit tests and linting.
2430 commands :
2531 - set -e
26- - BRANCH_NAME=${CODEBUILD_WEBHOOK_HEAD_REF#"refs/heads/"}
32+
33+ - echo ECR_REPOSITORY=$ECR_REPOSITORY
34+ - echo BRANCH=$BRANCH
2735
2836 - cd $CODEBUILD_SRC_DIR
2937
30- - echo "Validating Cloudformation Templates..."
31- - cfn-lint cicd/1-setup/*.template.yml
32- - cfn-lint cicd/2-cicd/*.template.yml
33- - cfn-lint cicd/3-app/aiproxy/template.yml
38+ - ./ci-lint.sh
39+
40+ - echo "Running Unit Tests..."
41+ - echo "This is where I would run my unit tests"
3442
3543 - echo "Building Docker Image..."
3644 - IMAGE_NAME=aiproxy
37- - IMAGE_TAG=$(git rev-parse -- short HEAD)
45+ - IMAGE_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7} # short commit hash
3846 - docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
3947
40- - echo "Running Unit Tests..."
41- - echo "This is where I would run my unit tests"
42-
4348 - echo "Pushing Docker Image to ECR..."
44- - ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
45- - AWS_REGION=$(aws configure get region)
46- - ECR_REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
47- - ECR_REPO_NAME="aiproxy-${BRANCH_NAME}"
48- - FULL_IMAGE_NAME="${ECR_REGISTRY}/${ECR_REPO_NAME}:${IMAGE_TAG}"
49- - aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
50- - docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${FULL_IMAGE_NAME}
51- - docker push ${FULL_IMAGE_NAME}
49+ - docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${ECR_REPOSITORY}:${IMAGE_TAG}
50+ - docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${ECR_REPOSITORY}:latest
51+ - docker push ${ECR_REPOSITORY}:${IMAGE_TAG}
52+ - docker push ${ECR_REPOSITORY}:latest
5253
5354 - echo "Linting cloudformation..."
5455 - cd $CODEBUILD_SRC_DIR
@@ -57,6 +58,7 @@ phases:
5758 - cat template.yml
5859
5960 - echo "Creating environment config..."
61+ - IMAGE_URI="${ECR_REPOSITORY}:${IMAGE_TAG}"
6062 - cicd/3-app/aiproxy/config/create-environment-config.sh
6163
6264 - echo "Packaging Cloudformation Template..."
0 commit comments