-
Notifications
You must be signed in to change notification settings - Fork 12
/
cloudinit.txt
94 lines (65 loc) · 2.78 KB
/
cloudinit.txt
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
#!/bin/bash
echo "tail -f /var/log/cloud-init-output.log" > /root/logs.sh
chmod +x /root/logs.sh
curl -SLs https://get.docker.com | sudo sh
curl -SLs https://dl.get-arkade.dev | sudo sh
arkade get k3sup && \
arkade get kubectl && \
arkade get faas-cli && \
sudo chmod +x $HOME/.arkade/bin/* && \
sudo mv $HOME/.arkade/bin/* /usr/local/bin/
export IP=$(curl -sfSL https://checkip.amazonaws.com)
echo IP: $IP
mkdir -p /root/.kube/
k3sup install --local --tls-san $IP \
--no-extras \
--merge --local-path=/root/.kube/config
mkdir -p /home/coder/project/openfaas \
&& chmod 777 /home/coder/project/openfaas
arkade install openfaas
kubectl rollout status deploy/gateway -n openfaas
export OPENFAAS_URL=http://$IP:31112
PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo)
echo $PASSWORD > /home/coder/project/openfaas/04-gateway-password
echo $OPENFAAS_URL > /home/coder/project/openfaas/03-gateway-url
echo "export OPENFAAS_URL=$OPENFAAS_URL" | tee -a /home/coder/project/openfaas/01-add-to-bashrc.txt
echo "echo -n $PASSWORD | faas-cli login -g $OPENFAAS_URL -u admin --password-stdin" > /home/coder/project/openfaas/02-run-this.txt
chmod 777 -R /home/coder/project/openfaas
# Run VSCode last
sed -ie s/localhost/$IP/g /root/.kube/config
sed -ie s/127.0.0.1/$IP/g /root/.kube/config
chmod 777 /root/.kube/config
mkdir -p /root/certs
# Generate self-signed cert
openssl req -nodes -newkey rsa:2048 -keyout /root/certs/tmp-openfaas-ltd.key \
-out /root/certs/tmp-openfaas-ltd.crt -x509 -days 365 \
-subj "/C=UK/ST=CAMBS/L=Peterborough/O=OpenFaaS Ltd/OU=Workshop/CN=$IP"
chown 1000 -R /root/certs/
pass=$(head -c 16 /dev/urandom | shasum | cut -d' ' -f1)
hash=$(echo -n $pass | shasum | cut -d' ' -f1)
mkdir -p /root/.config/code-server
cat > /root/.config/code-server/config.yaml<<EOF
bind-addr: 0.0.0.0:8443
auth: password
password: $pass
EOF
chmod 777 -R /root/.config
useradd coder --uid 1000
chown coder:coder -R /root/.config
echo -n $pass > /home/coder/project/openfaas/01-add-to-bashrc.txt
docker rm -f vscode
docker run --name vscode \
--user coder \
-v /root/certs:/home/coder/certs \
-v /home/coder/project/openfaas:/home/coder/project/openfaas \
-v /root/.kube/config:/home/coder/.kube/config \
-v /root/.config/code-server:/home/coder/.config/code-server2 \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CODE_SERVER_CONFIG=/home/coder/.config/code-server2/config.yaml \
--restart=always \
--privileged \
-p 8443:8080 \
-d alexellis2/coder:2021-03-22 --config /home/coder/.config/code-server2/config.yaml --cert=/home/coder/certs/tmp-openfaas-ltd.crt --cert-key=/home/coder/certs/tmp-openfaas-ltd.key --disable-telemetry
# docker logs -f vscode
echo Password for UI: $pass
echo URL for UI: https://$IP:8443