Skip to content

Commit 717f08b

Browse files
committed
check pull on docker deploy idea
1 parent 546e639 commit 717f08b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# if pull and if id1 !== id2
2+
3+
ssh $REMOTE_HOST "cd $REMOTE_PATH && \
4+
5+
# Try to pull the new image, exit early if it fails
6+
docker pull $IMAGE_NAME_WITH_TAG || { echo 'Docker pull failed, aborting.'; exit 1; } && \
7+
8+
# Get the image ID of the current image
9+
OLD_IMAGE_ID=\$(docker images -q $IMAGE_NAME_WITH_TAG) && \
10+
11+
# Get the newly pulled image ID
12+
NEW_IMAGE_ID=\$(docker images -q $IMAGE_NAME_WITH_TAG) && \
13+
14+
# Compare old and new image IDs, exit if they are the same
15+
if [ \"\$OLD_IMAGE_ID\" = \"\$NEW_IMAGE_ID\" ]; then \
16+
echo 'Image is already up to date. Exiting.'; \
17+
exit 0; \
18+
fi && \
19+
20+
# Stop the running containers
21+
docker compose down && \
22+
23+
# Remove the old image if it exists
24+
[ -n \"\$OLD_IMAGE_ID\" ] && docker image rm \$OLD_IMAGE_ID || true && \
25+
26+
# Bring up the containers with the new image
27+
docker compose up -d"

0 commit comments

Comments
 (0)