Skip to content

Instantly share code, notes, and snippets.

@rahulkj
Last active March 27, 2020 15:32
Show Gist options
  • Save rahulkj/c1b64e3f70978565c44d90585de2bf9a to your computer and use it in GitHub Desktop.
Save rahulkj/c1b64e3f70978565c44d90585de2bf9a to your computer and use it in GitHub Desktop.
Docker pull and push to harbor
#!/bin/bash
export DOCKER_CONTENT_TRUST=0
export HARBOR_HOST=harbor.pks.homelab.io
export HARBOR_USERNAME=admin
export HARBOR_PASSWORD=welcome
export HARBOR_REPO=$HARBOR_HOST/prometheus-operator
docker login $HARBOR_HOST -u $HARBOR_USERNAME -p $HARBOR_PASSWORD
helm template prometheus-operator stable/prometheus --include-crds \
| grep "image: " | awk '{print $2}' | uniq | sed 's/\"//g' > test.txt
helm template prometheus-operator stable/prometheus --include-crds \
| grep config-reloader | grep :v | awk '{split($0,a,"="); print a[2]}' | sed 's/\"//g' >> test.txt
cat test.txt | sort | uniq > test1.txt
mv test1.txt test.txt
while read -r line; do
docker pull $line
image=$(echo $line | awk '{split($0,a,"="); print a[0]}')
tag=$(echo $line | awk '{split($0,a,"="); print a[1]}')
docker tag $line $HARBOR_REPO/$line
docker push $HARBOR_REPO/$line
done < test.txt
images=($(docker images --format "{{.Repository}}:{{.Tag}}"))
for i in "${images[@]}"; do docker rmi $i; done
kubectl get pods -n monitoring -o jsonpath="{..image}" | tr -s '[[:space:]]' '\n' | sort | uniq -c | awk '{print $2}' > deployed.txt
diff test.txt deployed.txt
rm -f *.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment