Wednesday, February 21, 2024
HomeSoftware EngineeringHow one can push a number of Dockerfile apps to AWS ECR...

How one can push a number of Dockerfile apps to AWS ECR on the similar time


I’ve a guardian listing containing a number of sub-directories. Every of those youngster directories is a distinct software and accommodates a Dockerfile.

I need to construct and push every picture to AWS ECR.

The listing appears as follows:

├── apps
    ├── microservice1
        ├── app.js
        ├── Dockerfile
        ├── bundle.json
        └── readiness.txt
    ├── frontend
        ├── Dockerfile
        ├── index.html
        ├── bundle.json
        ├── server.js
    ├── microservice2
        ├── app.py
        ├── bootstrap.sh
        ├── Dockerfile
        └── necessities.txt

Discover there are 3 apps, every with their very own Dockerfile, beneath the guardian apps listing.

Within the beneath code snippet, now we have already set AWS_REGION to our desired area title.

If in case you have not completed this, run export AWS_REGION='eu-west-1', or acceptable.

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
completed

Observe how we use the for loop on line 4 above to loop by way of our listing names throughout the apps guardian listing.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments