| #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 |