-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec_docker.yml
36 lines (31 loc) · 1.42 KB
/
buildspec_docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
version: 0.2
env:
variables:
IMAGE_TAG: "latest" # Default value for the tag. Can be overridden.
exported-variables:
- IMAGE_DIGEST
- IMAGE_IDENTIFIER
phases:
install:
commands:
- npm install
pre_build:
commands:
- echo "Extracting AWS Account ID from CODEBUILD_BUILD_ARN..."
- export ACCOUNT_ID=$(echo $CODEBUILD_BUILD_ARN | cut -f5 -d ':')
- export repository_name="hotel-app" # Set your repository name here
- echo "Logging into Amazon ECR..."
- aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
build:
commands:
- echo "Building the Docker image..."
- docker build -t $repository_name:$IMAGE_TAG .
- echo "Tagging the Docker image for ECR..."
- docker tag $repository_name:$IMAGE_TAG $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$repository_name:$IMAGE_TAG
- echo "Pushing the Docker image to ECR..."
- docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$repository_name:$IMAGE_TAG
post_build:
commands:
- echo "Retrieving the image digest from ECR..."
- IMAGE_DIGEST=$(aws ecr describe-images --repository-name $repository_name --image-ids imageTag=$IMAGE_TAG --query 'imageDetails[0].imageDigest' --output text)
- IMAGE_IDENTIFIER="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${repository_name}@${IMAGE_DIGEST}"