Skip to content

Commit

Permalink
Verify if the image is available before trying to update the service
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmoschini committed Apr 17, 2020
1 parent 331475f commit 4edaef0
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions shepherd
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ update_services() {
if [[ " $blacklist " != *" $name "* ]]; then
image_with_digest="$(docker service inspect "$name" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')"
image=$(echo "$image_with_digest" | cut -d@ -f1)
echo "Trying to update service $name with image $image"
docker service update "$name" $detach_option $registry_auth --image="$image" > /dev/null

previousImage=$(docker service inspect "$name" -f '{{.PreviousSpec.TaskTemplate.ContainerSpec.Image}}')
currentImage=$(docker service inspect "$name" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')
if [ "$previousImage" == "$currentImage" ]; then
echo "No updates to service $name!"
if ! DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $image > /dev/null; then

This comment has been minimized.

Copy link
@alexanderwink

alexanderwink May 8, 2020

This fails if you are have a registry that requires login?

This comment has been minimized.

Copy link
@djmaze

djmaze May 10, 2020

Collaborator

I think the whole process currently does not work with a login-based registry. See #42 for more information.

This comment has been minimized.

Copy link
@andresmoschini

andresmoschini May 11, 2020

Author Contributor

I did not read #42 and I did not analyze this comment, but I can confirm that I am using it with DockerHub using private repositories with this configuration:

version: "3.7"

services:
  shepherd:
    image: mazzolino/shepherd
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./Secret.shared.docker-config.json:/root/.docker/config.json
    environment:
      - SLEEP_TIME=5m
      - WITH_REGISTRY_AUTH=true
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager

This comment has been minimized.

Copy link
@AeroSteveO

AeroSteveO Aug 24, 2020

I'm running into issues from this line on a locally hosted docker registry, it doesn't go to the else statement despite DOCKER_CLI_EXPERIMENTAL not being defined in my environment, and instead fails on the docker manifest call, commenting out the sections using the docker manifest allows it to work as expected

echo "Error updating service $name! Image $image does not exist or it is not available"
else
echo "Service $name was updated!"
if [[ "$apprise_sidecar_url" != "" ]]; then
title="[Shepherd] Service $name updated"
body="Service $name was updated from $previousImage to $currentImage"
curl -X POST -H "Content-Type: application/json" --data "{\"title\": \"$title\", \"body\": \"$body\"}" "$apprise_sidecar_url"
echo "Trying to update service $name with image $image"
docker service update "$name" $detach_option $registry_auth --image="$image" > /dev/null

previousImage=$(docker service inspect "$name" -f '{{.PreviousSpec.TaskTemplate.ContainerSpec.Image}}')
currentImage=$(docker service inspect "$name" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')
if [ "$previousImage" == "$currentImage" ]; then
echo "No updates to service $name!"
else
echo "Service $name was updated!"
if [[ "$apprise_sidecar_url" != "" ]]; then
title="[Shepherd] Service $name updated"
body="Service $name was updated from $previousImage to $currentImage"
curl -X POST -H "Content-Type: application/json" --data "{\"title\": \"$title\", \"body\": \"$body\"}" "$apprise_sidecar_url"
fi
fi
fi
fi
Expand Down

0 comments on commit 4edaef0

Please sign in to comment.