-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgen-secret.sh
executable file
·26 lines (21 loc) · 938 Bytes
/
gen-secret.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
#!/bin/bash
set -e
regex="docker login -u (.+) -p (.+) -e (.+) (.+)"
if [[ $(aws ecr get-login) =~ $regex ]]
then
login=$(echo "${BASH_REMATCH[1]}:${BASH_REMATCH[2]}" | base64)
echo "Configuring registry ${BASH_REMATCH[4]:8}..."
dockerconfig="{\"auths\":{\"${BASH_REMATCH[4]:8}\":{\"auth\": \"${login}\"}}}"
dockerconfigjson=$(echo ${dockerconfig} | base64)
secret="apiVersion: v1\nkind: Secret\nmetadata:\n name: aws-ecr-credentials\ndata:\n .dockerconfigjson: ${dockerconfigjson}\ntype: kubernetes.io/dockerconfigjson"
echo -e ${secret} | kubectl replace -f - --force
cat <<EOF
In order to use the new secret to pull images, add the following to your Pod definition:
spec:
imagePullSecrets:
- name: aws-ecr-credentials
[...]
Remember that AWS ECR login credentials expire in 12 hours!
More info at https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
EOF
fi