From 3b0d5aa1d2d8d40aef789b7c7b0b8f2e9bf3546c Mon Sep 17 00:00:00 2001 From: drymer Date: Sun, 7 Oct 2018 21:17:17 +0200 Subject: [PATCH] Update docker and kubernetes functions --- roles/shell-dotfiles/files/aliases | 62 +++++++++++++++++++++++++++- roles/shell-dotfiles/files/functions | 48 ++++++++++++++++----- 2 files changed, 97 insertions(+), 13 deletions(-) diff --git a/roles/shell-dotfiles/files/aliases b/roles/shell-dotfiles/files/aliases index 46a9475..d4743c9 100644 --- a/roles/shell-dotfiles/files/aliases +++ b/roles/shell-dotfiles/files/aliases @@ -8,14 +8,72 @@ alias ec="emacsclient -t" alias nav="qutebrowser --target tab-bg-silent " alias rmr="/bin/rm" alias weechat="docker run -ti --name weechat --rm -v ~/.weechat:/weechat --net=host registry.daemons.it/weechat" +alias scrcpy='docker run -ti --privileged -v /dev/bus/usb:/dev/bus/usb -v ~/.android:/root/.android -v /tmp/.X12-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -p 5037:5037 -v $HOME/.Xauthority:/root/.Xauthority --net=host registry.daemons.it/scrcpy' +alias alpine='docker run -ti alpine sh' alias ledger="ledger -f ~/Documentos/Finanzas/finanzas.ldg" -alias cdtemp="cd `mktemp -d`" alias gitinit="git config user.email drymer@autistici.org; git config user.name drymer; git config commit.gpgsign true" alias ytv="cd ~/.syncthing/VideosMovil; torify youtube-dl -f 18 " alias h='function hdi(){ howdoi $* -n 3; }; hdi' alias watch='watch -n1' -alias scrcpy='docker run -ti --privileged -v /dev/bus/usb:/dev/bus/usb -v ~/.android:/root/.android -v /tmp/.X12-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -p 5037:5037 -v $HOME/.Xauthority:/root/.Xauthority --net=host scrcpy' alias cwd='pwd | tr -d "\r\n" | xclip -selection clipboard' alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'" alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\\: .*|GET \\/.*\"" alias alarm="notify-send -u critical \"Ya ha terminado el proceso\"" +# A beautiful cat: go get -u github.com/jingweno/ccat +alias cat="ccat" + +# Kubernetes, copied from oh my zsh plugin +# This command is used a LOT both below and in daily life +alias k=kubectl + +# Apply a YML file +alias kaf='kubectl apply -f' + +# Drop into an interactive terminal on a container +alias keti='kubectl exec -ti' + +# Manage configuration quickly to switch contexts between local, dev ad staging. +alias kcuc='kubectl config use-context' +alias kcsc='kubectl config set-context' +alias kcdc='kubectl config delete-context' +alias kccc='kubectl config current-context' + +# Pod management. +alias kgp='kubectl get pods' +alias kep='kubectl edit pods' +alias kdp='kubectl describe pods' +alias kdelp='kubectl delete pods' + +# Service management. +alias kgs='kubectl get svc' +alias kes='kubectl edit svc' +alias kds='kubectl describe svc' +alias kdels='kubectl delete svc' + +# Ingress management +alias kgi='kubectl get ingress' +alias kei='kubectl edit ingress' +alias kdi='kubectl describe ingress' +alias kdeli='kubectl delete ingress' + +# Secret management +alias kgsec='kubectl get secret' +alias kdsec='kubectl describe secret' +alias kdelsec='kubectl delete secret' + +# Deployment management. +alias kgd='kubectl get deployment' +alias ked='kubectl edit deployment' +alias kdd='kubectl describe deployment' +alias kdeld='kubectl delete deployment' +alias ksd='kubectl scale deployment' +alias krsd='kubectl rollout status deployment' + +# Rollout management. +alias kgrs='kubectl get rs' +alias krh='kubectl rollout history' +alias kru='kubectl rollout undo' + +# Logs +alias kl='kubectl logs' +alias klf='kubectl logs -f' diff --git a/roles/shell-dotfiles/files/functions b/roles/shell-dotfiles/files/functions index 2383bce..18b1297 100644 --- a/roles/shell-dotfiles/files/functions +++ b/roles/shell-dotfiles/files/functions @@ -10,13 +10,8 @@ function busca() { find ~/.basura/ -name "*$@*" } -# Sube cosas para compartir a mi servidor -function upload_stuff() { - for i in $@ - do - rsync -P -e ssh $i drymer@daemons.it:/var/www/blog/mierdas/ > /dev/null - echo "https://daemons.it/mierdas/$i" - done +function cdtemp() { + cd `mktemp -d` } # Un bucle infinito facilitado @@ -247,6 +242,17 @@ function kenter(){ kubectl exec -ti $1 $2 $3 $command } +# Crea un pod de debian si no existe y lo borra al terminar +function kdebian(){ + debian_pod=$(kubectl get pod | grep debian | awk '{print $1}') + if [[ -z $debian_pod ]] + then + kubectl run -i --tty debian --image=debian + else + kubectl exec -ti $debian_pod bash + fi + kubectl delete deploy debian +} # Actualiza kubectl function upgrade_kubectl (){ @@ -279,12 +285,32 @@ function reveal () { sleep 3 && xdg-open http:localhost:8000 } async &! - docker run -ti --name revealjs --rm -v `pwd`:/revealjs/files/ -p 8000:8000 revealjs + docker run -ti --name registry.daemons.it/reveal --rm -v `pwd`:/revealjs/files/ -p 8000:8000 revealjs +} +## reveal-md +function revealmd () { + async () { + sleep 3 && xdg-open http:localhost:1948/main.md + } + async &! + docker run -ti --name registry.daemons.it/reveal-md --rm -v `pwd`:/revealjs/files/ -p 1948:1948 revealmd } -## Tox -function docker-tox () { - docker run -ti -v `pwd`:/tox registry.daemons.it/tox:latest tox "$@" +## Hugo +function docker-hugo() { + docker run -ti -v `pwd`:/hugo -p 1313:1313 registry.daemons.it/hugo:latest "$@" + # Ugly hack to ensure that all permissions are correctly set + sudo chown -R `whoami` `pwd` +} + +nginx_this(){ + docker stop nginx_this &> /dev/null + docker rm nginx_this &> /dev/null + docker run -d -v `pwd`:/usr/share/nginx/html --name nginx_this -p \ + 2000:80 nginx:alpine + + # open browser + my-sensible-browser "http://127.0.0.1:2000" } # Autocompletados