diff --git a/Cd_buld_push_docker.sh b/Cd_buld_push_docker.sh new file mode 100644 index 0000000..f9d124c --- /dev/null +++ b/Cd_buld_push_docker.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# .env variables should look like this +#AWS_REGION="" +#AWS_ACCOUNT_ID="" +#IMAGE_NAME="" +#REPOSITORY_NAME="" +# Load environment variables from .env file +export $(grep -v '^#' .env | xargs) + +# Authenticate Docker with AWS ECR +aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com + +# Build the Docker image +docker build -t $IMAGE_NAME:latest . + +# Tag the Docker image +docker tag $IMAGE_NAME:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME:latest + +# Push the Docker image to ECR +docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME:latest