Sign inSign up

matvil/swarm-ecr-login

By matvil

•Updated over 8 years ago

Refresh AWS ECR login credentials for Docker Swarm services

Image
1

321

matvil/swarm-ecr-login repository overview

⁠Refresh ECR login token for Docker Swarm services

This image is refreshing ECR registry login token every 4 hours for every service whose image is stored on ECR.

Inspired by https://github.com/mRoca/docker-swarm-aws-ecr-auth/⁠

⁠Deployemnt

To successfully operate, the cotainer needs access to the Docker socket and AWS credentials:

version: '3.6'
services:
  ecr-login:
    image: matvil/swarm-ecr-login
    env:
      AWS_ACCESS_KEY_ID: XYZ
      AWS_SECRET_ACCESS_KEY: ABC
      AWS_DEFAULT_REGION: ap-southeast-1
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
    deploy:
      replicas: 1

⁠Operation

Every ${SLEEP_TIME} seconds (by default, 14400 - 4 hours) aws ecr get-login operation is performed and docker service update --with-registry-auth --detach=true $SERVICE_NAME is called against every service having .dkr.ecr. in its image's name:

#!/bin/sh

while true; do
    eval $(aws ecr get-login --no-include-email)

    for service in $(docker service ls --format "{{.Name}} {{.Image}}" | awk '$2~/\.dkr\.ecr\./ {print $1}'); do
        echo "Updating service $service"
        docker service update --with-registry-auth --detach=true "$service"
    done
    sleep ${SLEEP_TIME}
done

Tag summary

Content type

Image

Digest

Size

38.1 MB

Last updated

over 8 years ago

docker pull matvil/swarm-ecr-login