1- # docker/build_push_to_ecr.sh
2-
31#! /bin/bash
42
53# Set variables
@@ -12,6 +10,8 @@ AWS_REGION="eu-west-2"
1210ACCOUNT_ID=$( aws sts get-caller-identity --query Account --output text)
1311REPOSITORY_NAME=" imms-fhir-api-grafana"
1412IMAGE_TAG=" 11.0.0-22.04_stable"
13+ LOCAL_IMAGE_NAME=" $REPOSITORY_NAME :$IMAGE_TAG "
14+ IMAGE_NAME=" $ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/$LOCAL_IMAGE_NAME "
1515TAGS=" Key=Environment,Value=non-prod Key=Project,Value=immunisation-fhir-api-grafana"
1616LIFECYCLE_POLICY_FILE=" lifecycle-policy.json"
1717
@@ -42,39 +42,23 @@ printf "Building and pushing Docker image to ECR...\n"
4242aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com
4343
4444printf " Building Docker image...\n"
45- # Build Docker image
46- # docker build -t $REPOSITORY_NAME:$IMAGE_TAG .
47- # Build Docker image for linux/amd64 architecture
4845# Remove existing Docker image if it exists
49- docker rmi $ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/$REPOSITORY_NAME :$IMAGE_TAG --force
46+ docker rmi $IMAGE_NAME --force
47+
48+ # Pull the base image for linux/amd64 architecture
5049docker pull --platform linux/amd64 grafana/grafana:latest
50+
51+ # Build Docker image for linux/amd64 architecture and push to ECR
5152docker buildx create --use
52- docker buildx build --platform linux/amd64 -t $ACCOUNT_ID .dkr.ecr. $AWS_REGION .amazonaws.com/ $REPOSITORY_NAME : $IMAGE_TAG --push .
53+ docker buildx build --platform linux/amd64 -t $IMAGE_NAME --push .
5354
5455# Check if the build was successful
5556if [ $? -ne 0 ]; then
5657 echo " Docker build failed."
5758 exit 1
5859fi
5960
60- printf " Tagging Docker image...\n"
61- # Tag Docker image
62- docker tag $REPOSITORY_NAME :$IMAGE_TAG $ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/$REPOSITORY_NAME :$IMAGE_TAG
63-
64- # Check if the tag was successful
65- if [ $? -ne 0 ]; then
66- echo " Docker tag failed."
67- exit 1
68- fi
69-
70- printf " Pushing Docker image to ECR...\n"
71- # Push Docker image to ECR
72- docker push $ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/$REPOSITORY_NAME :$IMAGE_TAG
73-
74- # Check if the push was successful
75- if [ $? -ne 0 ]; then
76- echo " Docker push failed."
77- exit 1
78- fi
61+ # Inspect the built image
62+ echo " Image: $LOCAL_IMAGE_NAME "
7963
8064echo " Docker image built and pushed to ECR successfully."
0 commit comments