I’ve a father or mother listing containing a number of sub-directories. Every of those youngster directories is a unique utility and accommodates a Dockerfile.
I need to construct and push every picture to AWS ECR.
The listing seems as follows:
├── apps
├── microservice1
├── app.js
├── Dockerfile
├── package deal.json
└── readiness.txt
├── frontend
├── Dockerfile
├── index.html
├── package deal.json
├── server.js
├── microservice2
├── app.py
├── bootstrap.sh
├── Dockerfile
└── necessities.txt
Discover there are 3 apps, every with their very own Dockerfile, underneath the father or mother apps listing.
Within the under code snippet, we have now already set AWS_REGION to our desired area title.
You probably have not carried out this, run export AWS_REGION='eu-west-1', or applicable.
Additionally set the ACCOUNT_ID to your AWS’s account ID.
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
PROJECT_NAME=our-project-name
export APP_VERSION=1.0
for app in microservice1 microservice2 frontend; do
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 ||
aws ecr create-repository --repository-name $PROJECT_NAME/$app >/dev/null
TARGET=$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$PROJECT_NAME/$app:$APP_VERSION
docker construct -t $TARGET apps/$app
docker push $TARGET
carried out
Observe how we use the for loop on line 4 above to loop by our listing names inside the apps father or mother listing.