chore(snippets): bring in commands and functions from the kb

This commit is contained in:
Michele Cereda
2024-04-20 01:09:35 +02:00
parent 3282e0b845
commit 41174d61ba
8 changed files with 104 additions and 2 deletions

27
snippets/aws.fish Normal file
View File

@@ -0,0 +1,27 @@
#!fish
alias aws-caller-info 'aws sts get-caller-identity'
alias aws-ssm 'aws ssm start-session --target'
function aws-assume-role-by-name
set current_caller (aws-caller-info --output json | jq -r '.UserId' -)
aws-iam-role-arn-from-name "$argv[1]" \
| xargs -I {} \
aws sts assume-role \
--role-arn "{}" \
--role-session-name "$current_caller-as-$argv[1]-stsSession" \
&& echo "Assumed role $argv[1]; Session name: '$current_caller-as-$argv[1]-stsSession'"
end
function aws-iam-role-arn-from-name
aws iam list-roles --output 'text' \
--query "Roles[?RoleName == '$argv[1]'].Arn"
end
alias aws-ssm-gitlabAutoscalingManager-ita-b "aws ec2 describe-instances --output text \
--filters \
'Name=availability-zone,Values=eu-south-1b' \
'Name=instance-state-name,Values=running' \
'Name=tag:Name,Values=Gitlab Autoscaling Manager' \
--query 'Reservations[].Instances[0].InstanceId' \
| xargs -ot aws ssm start-session --target"

19
snippets/functions.sh Normal file
View File

@@ -0,0 +1,19 @@
#!sh
is_strictly_false () {
if [[ "$1" =~ '0|^[Ff][Aa][Ll][Ss][Ee]$|^[Nn][Oo]?$|^$' ]]
then
true
else
false
fi
}
is_strictly_true () {
if [[ "$1" =~ '1|^[Tt][Rr][Uu][Ee]$|^[Yy]([Ee][Ss])?$' ]]
then
# 0 as in "function ended successfully"
true
else
false
fi
}

View File

@@ -0,0 +1,7 @@
#!sh
gitlab-runner exec docker \
--env 'AWS_ACCESS_KEY_ID=AKIA…' --env 'AWS_SECRET_ACCESS_KEY=FsN4…' --env 'AWS_REGION=eu-west-1' \
--env 'DOCKER_AUTH_CONFIG={ "credsStore": "ecr-login" }' \
--docker-volumes "$HOME/.aws/credentials:/root/.aws/credentials:ro" \
'pulumi preview'

6
snippets/gitlab.sh Normal file
View File

@@ -0,0 +1,6 @@
#!sh
sudo yum check-update
sudo yum info 'gitlab-ee'
sudo rpm -qa | grep 'gitlab-ee'
tmux new-session -A -s 'gitlab-upgrade' "sudo yum update 'gitlab-ee'"

7
snippets/gpg.fish Normal file
View File

@@ -0,0 +1,7 @@
#!fish
gpg-connect-agent reloadagent '/bye'
gpg-connect-agent updatestartuptty '/bye' \
&& set -x 'SSH_AUTH_SOCK' (gpgconf --list-dirs 'agent-ssh-socket') \
&& set -x 'GPG_TTY' (tty)

View File

@@ -5,8 +5,7 @@
set -e
curl "https://github.com/k3s-io/k3s/releases/download/v1.19.7%2Bk3s1/k3s" \
--location \
--remote-name
--location --remote-name
sudo k3s server &
# Kubeconfig is written to /etc/rancher/k3s/k3s.yaml

5
snippets/osx.sh Normal file
View File

@@ -0,0 +1,5 @@
#!sh
scutil --set 'ComputerName' "$(defaults read '/Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName')"
scutil --set 'HostName' "$(defaults read '/Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName')"
scutil --set 'LocalHostName' "$(defaults read '/Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName')"

32
snippets/pulumi.fish Normal file
View File

@@ -0,0 +1,32 @@
#!fish
function pulumi-all-of-type
pulumi stack export \
| jq -r --arg type "$argv[1]" '.deployment.resources[]|select(.type==$type).urn'
end
# Examples:
# - $ pulumi-all-of-typeRegex 'Endpoint$'
# urn:pulumi:dev::ds::aws:sagemaker/endpoint:Endpoint::ml-endpoint
function pulumi-all-of-typeRegex
pulumi stack export \
| jq -r --arg regex "$argv[1]" '.deployment.resources[]|select(.type|test($regex)).urn'
end
function pulumi-id2urn
pulumi stack export \
| jq -r --arg id "$argv[1]" '.deployment.resources[]|select(.id==$id).urn'
end
function pulumi-urn2id
pulumi stack export \
| jq -r --arg urn "$argv[1]" '.deployment.resources[]|select(.urn==$urn).id'
end
# Examples:
# - $ pulumi-urnRegex2urn 'gitlab_ee_main_instance$'
# urn:pulumi:dev::start::aws:ec2/instance:Instance::monitoring-instance
function pulumi-urnRegex2urn
pulumi stack export \
| jq -r --arg regex "$argv[1]" '.deployment.resources[]|select(.urn|test($regex)).urn'
end