-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdocker_image.sh
executable file
·42 lines (32 loc) · 1.13 KB
/
docker_image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
current_image=""
while true; do
image_target_name=$(cat "$(pwd)/container/image_target_name")
base_image_name=$(cat "$(pwd)/container/image_base")
if [ -z "$image_target_name" ]; then
sleep 30
exit 1
fi
if [ -z "$base_image_name" ]; then
sleep 30
exit 1
fi
if [ "$current_image" = "$image_target_name" ]; then
echo "$current_image already pushed"
sleep 30
continue
fi
current_image=$image_target_name
export ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text)
export AWS_REGION=$(aws configure get region)
release_image="$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/esd_container:$image_target_name"
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"
docker tag "$base_image_name" "$release_image"
docker push "$release_image"
untagged_images=$(docker images --filter "dangling=true" -q)
for image_id in $untagged_images; do
docker rmi -f "$image_id"
done
sleep 5
done
exit 1