Skip to content

Commit

Permalink
Merge pull request #9 from eSailors/retry
Browse files Browse the repository at this point in the history
Retry token
  • Loading branch information
matlockx authored Oct 26, 2018
2 parents 2970d90 + 9d64778 commit 80e0288
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions files/renew_token.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/bin/sh

set -e
set -xe

# update the auth token
CONFIG=/usr/local/openresty/nginx/conf/nginx.conf
AUTH=$(grep X-Forwarded-User $CONFIG | awk '{print $4}'| uniq|tr -d "\n\r")
TOKEN=$(aws ecr get-login --no-include-email | awk '{print $6}')

# retry till new get new token
while true; do
TOKEN=$(aws ecr get-login --no-include-email | awk '{print $6}')
[ ! -z "${TOKEN}" ] && break
echo "Warn: Unable to get new token, wait and retry!"
sleep 30
done


AUTH_N=$(echo AWS:${TOKEN} | base64 |tr -d "[:space:]")

sed -i "s|${AUTH%??}|${AUTH_N}|g" $CONFIG
Expand Down
2 changes: 1 addition & 1 deletion files/root
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Refresh the AWS ECR token periodically.
# min hour day month weekday command
0 * * * * /renew_token.sh
0 */6 * * * /renew_token.sh

0 comments on commit 80e0288

Please sign in to comment.