1- REGION=eu-west-3
2- REPOSITORIES=(fuseki)
1+ REGION=eu-west-1
32MONGO_IMAGE=docker.io/mongo:5.0.10
43FUSEKI_IMAGE=docker.io/secoresearch/fuseki:4.5.0
54METABASE_IMAGE=docker.io/metabase/metabase:v0.43.4
6- AIRFLOW_POSTGRES=docker.io/postgres:14.4-alpine
5+ AIRFLOW_POSTGRES_IMAGE=docker.io/postgres:14.4-alpine
6+ REDIS_IMAGE=docker.io/redis:7.0.4-alpine3.16
7+ MONGO_EXPRESS_IMAGE=docker.io/mongo-express:0.54.0
78
8- IMAGES_TO_BE_BUILD=(airflow digest-api )
9+
10+ IMAGES_TO_BE_BUILD=(airflow digest_api metabase_postgres)
11+ IMAGES_FROM_DOCKER_HUB=(fuseki airflow_postgres metabase mongo redis mongo_express)
912
1013touch .repositories_ids
1114
1215create_repository (){
1316 echo " Creating repository for $1 "
14- aws ecr create-repository --repository-name $1 --image-scanning-configuration scanOnPush=true -- region $2 > repo.json
17+ aws ecr create-repository --repository-name $1 --region $2 > repo.json
1518 REPO_NAME=$1
1619 REPO_ID=` jq -r " .repository.repositoryUri" repo.json`
1720 echo ${REPO_NAME^^} _REPO_ID=$REPO_ID >> .repositories_ids
@@ -21,35 +24,74 @@ create_repository(){
2124
2225
2326build_image_and_push_to_repo (){
27+ echo " Building image for $1 "
2428 REPO=$1
2529 REPO_NAME=${REPO^^}
2630 REPO_ID=${REPO_NAME} _REPO_ID
2731 echo ${! REPO_ID}
28- aws ecr get-login-password --region eu-west-3 | podman login --username AWS --password-stdin ${! REPO_ID}
29- podman build -t $1 ../$1 / --label=$1 -image
32+ aws ecr get-login-password --region $REGION | podman login --username AWS --password-stdin ${! REPO_ID}
33+ if [ " $REPO " = " metabase_postgres" ]; then
34+ REPO=metabase
35+ fi
36+ podman build -t $REPO ../$REPO / --label=$1 -image
3037 IMAGE=` podman images --filter label=$1 -image --format {{.Repository}}:{{.Tag}}`
38+ echo " image found is $IMAGE "
39+ TAG=$( echo $IMAGE | cut -d' :' -f 2)
40+ echo " TAG found is $TAG "
41+ if [ ! -z $TAG ]
42+ then
43+ podman tag $IMAGE ${! REPO_ID} :$TAG
44+ podman push ${! REPO_ID} :$TAG
45+ fi
46+
3147 podman tag $IMAGE ${! REPO_ID} :latest
3248 podman push ${! REPO_ID} :latest
33- }
3449
50+ echo ${REPO_NAME} _IMAGE_URI=${! REPO_ID} :latest >> .env
51+ echo " Image for $1 has been pushed in AWS"
52+ podman system prune --all --force && podman rmi --all
53+ }
3554
55+ get_built_image_and_push_to_repo (){
56+ echo " Getting image for $1 "
57+ REPO=$1
58+ REPO_NAME=${REPO^^}
59+ REPO_ID=${REPO_NAME} _REPO_ID
60+ IMAGE_TO_PULL=${REPO_NAME} _IMAGE
61+ echo " REPO_ID=${! REPO_ID} "
62+ echo ${! IMAGE_TO_PULL}
63+ aws ecr get-login-password --region $REGION | podman login --username AWS --password-stdin ${! REPO_ID}
64+ podman pull ${! IMAGE_TO_PULL}
65+ echo " string to compare is $REPO "
66+ IMAGE_NAME_TO_FIND=$REPO
67+ if [ " $REPO " = " airflow_postgres" ]; then
68+ IMAGE_NAME_TO_FIND=postgres
69+ fi
70+ echo " Image to find is $IMAGE_NAME_TO_FIND "
71+ IMAGE=` podman images --format {{.Repository}}:{{.Tag}} | grep $IMAGE_NAME_TO_FIND `
72+ echo " image found is $IMAGE "
73+ TAG=$( echo $IMAGE | cut -d' :' -f 2)
74+ podman tag $IMAGE ${! REPO_ID} :latest
75+ podman tag $IMAGE ${! REPO_ID} :$TAG
76+ podman push ${! REPO_ID} :latest
77+ podman push ${! REPO_ID} :$TAG
78+ echo ${REPO_NAME} _IMAGE_URI=${! REPO_ID} :latest >> .env
79+ echo " Image for $1 has been pushed in AWS"
80+ podman system prune --all --force && podman rmi --all
81+ }
3682
37- for REPO in " ${REPOSITORIES [@]} "
83+ for IMAGE in " ${IMAGES_FROM_DOCKER_HUB [@]} "
3884do
39- # create_repository $REPO $REGION
85+ create_repository $IMAGE $REGION
4086 source .repositories_ids
4187 export $( cat .repositories_ids | xargs)
42- build_image_and_push_to_repo $REPO
88+ get_built_image_and_push_to_repo $IMAGE
4389done
4490
45-
46- # podman images --filter label=label --format {{.Repository}}
47- # podman images --format {{.Repository}} | grep fuseki
48- #
49- #
50- # podman build -t fuseki ../fuseki/ --label=label
51- #
52- # docker push 013659641721.dkr.ecr.eu-west-3.amazonaws.com/fuseki:latest
53-
54-
55- # aws ecr get-login-password --region eu-west-3 | podman login --username AWS --password-stdin 013659641721.dkr.ecr.eu-west-3.amazonaws.com
91+ for IMAGE in " ${IMAGES_TO_BE_BUILD[@]} "
92+ do
93+ create_repository $IMAGE $REGION
94+ source .repositories_ids
95+ export $( cat .repositories_ids | xargs)
96+ build_image_and_push_to_repo $IMAGE
97+ done
0 commit comments