From bd0066f615ef01e0a349c10269f961af44c431e8 Mon Sep 17 00:00:00 2001 From: Jonas Juselius Date: Wed, 18 Dec 2019 10:08:28 +0100 Subject: [PATCH] Add convenience scripts --- bootstrap/bin/copy-score-backups.sh | 8 ++++ bootstrap/bin/docker-prune-stopped.fish | 1 + bootstrap/bin/gitlab-prune-registry.sh | 49 +++++++++++++++++++++++++ bootstrap/bin/ws-curl.sh | 12 ++++++ 4 files changed, 70 insertions(+) create mode 100755 bootstrap/bin/copy-score-backups.sh create mode 100755 bootstrap/bin/docker-prune-stopped.fish create mode 100755 bootstrap/bin/gitlab-prune-registry.sh create mode 100755 bootstrap/bin/ws-curl.sh diff --git a/bootstrap/bin/copy-score-backups.sh b/bootstrap/bin/copy-score-backups.sh new file mode 100755 index 0000000..7a33394 --- /dev/null +++ b/bootstrap/bin/copy-score-backups.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +pod=`kubectl get pods -n mssql | grep Running | grep consto-ks | cut -d' ' -f1` +bak=`kubectl exec -n mssql $pod ls -- -1 /var/opt/mssql/data/ | grep '.bak$'` + +for i in $bak; do + kubectl cp mssql/$pod:/var/opt/mssql/data/$i . +done diff --git a/bootstrap/bin/docker-prune-stopped.fish b/bootstrap/bin/docker-prune-stopped.fish new file mode 100755 index 0000000..e83a66c --- /dev/null +++ b/bootstrap/bin/docker-prune-stopped.fish @@ -0,0 +1 @@ +for i in (seq 2 5); ssh k0- docker system prune -a;end diff --git a/bootstrap/bin/gitlab-prune-registry.sh b/bootstrap/bin/gitlab-prune-registry.sh new file mode 100755 index 0000000..4a0f2e7 --- /dev/null +++ b/bootstrap/bin/gitlab-prune-registry.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +token=UTjgSspYQcX-BVUd1UsC +api=https://gitlab.itpartner.no/api/v4 + +prune () { + id=$1 + reg=$(curl -s --header "PRIVATE-TOKEN: $token" \ + "$api/projects/$id/registry/repositories" \ + | json_pp | sed -n 's/^ *"id" *: *\([0-9]\+\).*/\1/p') + for i in $reg; do + curl -s --request DELETE --data 'keep_n=10' \ + --data 'name_regex=.*[0-9].*' \ + --header "PRIVATE-TOKEN: $token" \ + "$api/projects/$id/registry/repositories/$i/tags" + done +} + +gc () { + pod=$(kubectl get pod -n gitlab -lapp=registry | tail -1 | cut -d' ' -f1) + kubectl exec -n gitlab $pod -- \ + registry garbage-collect /etc/docker/registry/config.yml -m +} + +all () { + groups=$(curl -s --header "PRIVATE-TOKEN: $token" "$api/groups" \ + | json_pp | sed -n 's/^ *"id" *: *\([0-9]\+\).*/\1/p') + for g in $groups; do + proj=$(curl -s --header "PRIVATE-TOKEN: $token" \ + "$api/groups/$g/projects?simple=true&include_subgroups=true" \ + | json_pp | sed -n 's/^ \{6\}"id" *: *\([0-9]\+\).*/\1/p') + for p in $proj; do + prune $p + done + done +} + +projects () { + for i in $@; do + prune $(echo $i | sed 's,/,%2F,g') + done +} + +case $1 in + --all) all ;; + *) projects $@ +esac + +gc diff --git a/bootstrap/bin/ws-curl.sh b/bootstrap/bin/ws-curl.sh new file mode 100755 index 0000000..81166b5 --- /dev/null +++ b/bootstrap/bin/ws-curl.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +host=$1; shift + +curl -i -N \ + -H "Connection: upgrade"\ + -H "Upgrade: websocket"\ + -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ=="\ + -H "Sec-WebSocket-Version: 13"\ + -H "Origin: http://foo.com/"\ + -H "Host: $host" $@ +