This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
generate-envrc.sh
executable file
·166 lines (143 loc) · 3.3 KB
/
generate-envrc.sh
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
# stops the execution if a command or pipeline has an error
set -eu
if command -v tput >/dev/null && tput setaf 1 >/dev/null 2>&1; then
# color codes
RED="$(tput setaf 1)"
RESET="$(tput sgr0)"
fi
ERR="${RED:-}ERROR:${RESET:-}"
source ./current_versions.sh
err() (
if [ -z "${1:-}" ]; then
cat >&2
else
echo "$ERR " "$@" >&2
fi
)
candidate_interfaces() (
ip -o link show |
awk -F': ' '{print $2}' |
sed 's/[ \t].*//;/^\(lo\|bond0\|\|\)$/d' |
sort
)
validate_tinkerbell_network_interface() (
local tink_interface=$1
if ! candidate_interfaces | grep -q "^$tink_interface$"; then
err "Invalid interface ($tink_interface) selected, must be one of:"
candidate_interfaces | err
return 1
else
return 0
fi
)
generate_password() (
head -c 12 /dev/urandom | sha256sum | cut -d' ' -f1
)
generate_envrc() (
local tink_interface=$1
validate_tinkerbell_network_interface "$tink_interface"
TINKERBELL_HOST_IP=${TINKERBELL_HOST_IP:-192.168.1.1}
TINKERBELL_NGINX_IP=${TINKERBELL_NGINX_IP:-$TINKERBELL_HOST_IP}
TINKERBELL_NGINX_URL=${TINKERBELL_NGINX_URL:-http://$TINKERBELL_NGINX_IP:8080}
TINKERBELL_REGISTRY_IP=${TINKERBELL_REGISTRY_IP:-$TINKERBELL_HOST_IP}
TINKERBELL_TINK_IP=${TINKERBELL_TINK_IP:-$TINKERBELL_HOST_IP}
local tink_password
tink_password=$(generate_password)
local registry_password
registry_password=$(generate_password)
cat <<EOF
---
apiVersion: v1
kind: ConfigMap
metadata:
name: boots
data:
DATA_MODEL_VERSION: "1"
DNS_SERVERS: 8.8.8.8
DOCKER_REGISTRY: ${TINKERBELL_REGISTRY_IP}
MIRROR_BASE_URL: ${TINKERBELL_NGINX_URL}
PUBLIC_IP: ${TINKERBELL_HOST_IP}
TINKERBELL_CERT_URL: http://${TINKERBELL_TINK_IP}:42114/cert
TINKERBELL_GRPC_AUTHORITY: ${TINKERBELL_TINK_IP}:42113
---
apiVersion: v1
kind: ConfigMap
metadata:
name: dhcrelay
data:
IF_DOWNSTREAM: $tink_interface
IF_UPSTREAM: cni0
---
apiVersion: v1
kind: ConfigMap
metadata:
name: tink-client
data:
DATA_MODEL_VERSION: "1"
TINKERBELL_CERT_URL: http://tink-server.default.svc.cluster.local:42114/cert
TINKERBELL_GRPC_AUTHORITY: tink-server.default.svc.cluster.local:42113
---
apiVersion: v1
kind: ConfigMap
metadata:
name: tink-init
data:
OSIE_DOWNLOAD_LINK: ${OSIE_DOWNLOAD_LINK}
TINKERBELL_TINK_WORKER_IMAGE: ${TINKERBELL_TINK_WORKER_IMAGE}
---
apiVersion: v1
kind: Secret
metadata:
name: db
stringData:
PGDATABASE: tinkerbell
PGHOST: db.default.svc.cluster.local
PGPASSWORD: tinkerbell
PGPORT: "5432"
PGSSLMODE: disable
PGUSER: tinkerbell
type: Opaque
---
apiVersion: v1
kind: Secret
metadata:
name: packet
stringData:
API_AUTH_TOKEN: ${PACKET_API_AUTH_TOKEN:-ignored}
API_BASE_URL: ignored
API_CONSUMER_TOKEN: ${PACKET_CONSUMER_TOKEN:-ignored}
PACKET_ENV: ${PACKET_ENV:-testing}
PACKET_VERSION: ${PACKET_VERSION:-ignored}
ROLLBAR_DISABLE: "1"
ROLLBAR_TOKEN: ignored
type: Opaque
---
apiVersion: v1
kind: Secret
metadata:
name: registry
stringData:
REGISTRY_HOST: registry.default.svc.cluster.local
REGISTRY_USERNAME: admin
REGISTRY_PASSWORD: $registry_password
type: Opaque
---
apiVersion: v1
kind: Secret
metadata:
name: tink-auth
stringData:
TINK_AUTH_USERNAME: admin
TINK_AUTH_PASSWORD: $tink_password
type: Opaque
EOF
)
main() (
if [ -z "${1:-}" ]; then
err "Usage: $0 network-interface-name > envrc.yaml"
exit 1
fi
generate_envrc "$1"
)
main "$@"