-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcloud-init.yaml
More file actions
103 lines (97 loc) · 3.27 KB
/
cloud-init.yaml
File metadata and controls
103 lines (97 loc) · 3.27 KB
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
#cloud-config
apt_update: true
apt_upgrade: true
packages:
- at
users:
- name: ubuntu
uid: 1000
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
write_files:
- path: /etc/cloud-init.sh
permissions: '0755'
owner: root:root
content: |
echo "OPS_CLOUD_INIT_VER=3" >>/etc/environment
IP="$(ip -o -4 addr | awk '$2 ~/en/ { print $4}' | cut -d/ -f1)"
# install k3s, direnv, task
curl -sfL https://get.k3s.io | sh -
# set home and user
USR="$(getent passwd 1000 | awk -F: '{print $1}')"
HOME="/home/$USR"
# copy authkey if there is a root one
mkdir -p /home/$USR/.ssh
if test -e /root/.ssh/authorized_keys
then cat /root/.ssh/authorized_keys >>/home/$USR/.ssh/authorized_keys
fi
# access k3s
mkdir -p "$HOME/.kube"
cat /etc/rancher/k3s/k3s.yaml "$HOME/.kube/config" | sed -e 's!server: https://127.0.0.1:!server: https://'$IP':!' >"$HOME/.kube/config"
echo "export KUBECONFIG=/home/$USR/.kube/config" >>$HOME/.bashrc
chown -Rvf "$USR" /home/$USR
#sudo -u $USR bash /etc/install-opsv.sh
echo "== DONE =="
- path: /etc/install-opsv.sh
permissions: '0755'
owner: root:root
content: |
curl -sL bit.ly/get-ops | bash
# TODO: use the released version not main
echo "export OPS_BRANCH=main" >> ~/.bashrc
source ~/.bashrc
ops -t
ops -info
# configure opsv
ops config slim
IP="$(ip -o -4 addr | awk '$2 ~/en/ { print $4}' | cut -d/ -f1)"
ops config apihost "$IP.nip.io"
ops setup cluster
- path: /home/ubuntu/waitready
permissions: '0755'
owner: ubuntu:ubuntu
defer: true
content: |
#!/bin/bash
sudo cloud-init status --wait
tail -f /tmp/cloud-init.log | while read line
do echo "$line"
if [[ "$line" == *"== DONE =="* ]]
then exit 0
fi
done
- path: /home/ubuntu/i-am-a-developer
permissions: '0755'
defer: true
owner: ubuntu:ubuntu
content: |
# get openserverless sources
cd $HOME
# install task and skywalking-eyes
sudo snap install task --classic
sudo snap install go --classic
go install github.com/apache/skywalking-eyes/cmd/license-eye@latest
echo "export PATH=\$PATH:\$HOME/go/bin" >> .bashrc
# install direnv and nix
curl -sL https://nixos.org/nix/install | sh
source .profile
curl -sL https://direnv.net/install.sh | sudo bash
echo 'eval "$(direnv hook bash)"' >> .bashrc
source .bashrc
# setup openserverless
git clone https://github.com/apache/openserverless.git --recurse-submodules
cd openserverless
bash sync-branch.sh
bash direnv-init.sh
# TODO add a .git-hooks directory with hooks
#git config core.hooksPath .git-hooks
runcmd:
- |
cd /home/ubuntu
# add z.sh and .aliases
curl -sL "https://raw.githubusercontent.com/rupa/z/master/z.sh" -o ".z.sh"
curl -sL https://raw.githubusercontent.com/sciabarracom/openserverless/refs/heads/main/bash_aliases -o ".bash_aliases"
echo 'source $HOME/.z.sh' >> .bashrc
chown ubuntu:ubuntu .z.sh .bashrc .bash_aliases
echo -e '#!/bin/bash\n/etc/cloud-init.sh 2>&1 >/tmp/cloud-init.log\n' | at now