-
Notifications
You must be signed in to change notification settings - Fork 1
/
devstack-functions
119 lines (104 loc) · 3.06 KB
/
devstack-functions
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function aws-account() {
cut -d "-" -f 1 <<<$AWS_PROFILE
}
function ecs-exec() {
service=$1
shift
case $service in
arch-* | avr-*)
cluster=${service%%-*}
container=$cluster
command="sudo -u app -E -s HOME=/home/app bundle exec rails c"
;;
meadow)
cluster="meadow"
container=$cluster
command="bin/meadow remote"
;;
solr | zookeeper-*)
cluster="solrcloud"
container=${service%%-*}
command="/bin/bash"
;;
fcrepo)
cluster="fcrepo"
container=$cluster
command="/bin/bash"
;;
*)
cluster="default"
container=$cluster
command="/bin/bash"
;;
esac
if [[ "$@" != "" ]]; then
command="$@"
fi
task_id=$(aws ecs list-tasks --cluster $cluster --service $service | jq -r '.taskArns[0] | split("/") | last')
echo "Running \`${command}\` on task ${task_id}"
aws ecs execute-command --cluster ${cluster} --container ${container} --interactive --command "${command}" --task ${task_id}
}
function ecr-login() {
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
AWS_REGION=${AWS_REGION:=us-east-1}
ECR_REPO=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REPO}
}
function ecr-push() {
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
AWS_REGION=${AWS_REGION:=us-east-1}
ECR_REPO=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
docker tag $1 ${ECR_REPO}/$2
docker push ${ECR_REPO}/$2
docker image rm ${ECR_REPO}/$2
}
function tflinkvars() {
ln -s $NULIB_ROOT/tfvars/$1/*.tfvars .
}
function tfplan() {
terraform plan -var-file $(aws-account).tfvars -out $(aws-account).plan
}
function tfapply() {
terraform apply $(aws-account).plan
}
function tfselect() {
export AWS_PROFILE=$1-admin
aws-adfs login --profile $AWS_PROFILE
terraform workspace select $1 || terraform workspace new $1
}
function awslocal() {
aws --endpoint https://localhost.localstack.cloud:4566/ $@
}
function asdf-install-npm() {
tool_files=$(asdf-tool-versions)
node_versions=$(cat $(echo $tool_files) | grep nodejs | awk '{print $2}' | sort -u)
npm_versions=$(cat $(echo $tool_files) | grep npm | awk '{print $2}' | sort -u)
for nodejs in $(echo $node_versions); do
for npm in $(echo $npm_versions); do
echo "Installing npm v${npm} for NodeJS v${nodejs}"
ASDF_NODEJS_VERSION=${nodejs} npm install -g npm@${npm};
done
done
}
function asdf-install-plugins() {
tool_files=$(asdf-tool-versions)
plugins=$(cat $(echo $tool_files) | awk '{print $1}' | grep -v '#' | sort -u)
for plugin in $(echo $plugins); do
asdf plugin add $plugin
done
}
function asdf-tool-versions() {
result=""
if [ -e ./.tool-versions ]; then
result="${result} ${PWD}/.tool-versions"
fi
original_dir=$PWD
while [ $PWD != "/" ]; do
cd ..
if [ -e ./.tool-versions ]; then
result="${result} ${PWD}/.tool-versions"
fi
done
cd $original_dir
echo $result | xargs
}