This is an automated email from the ASF dual-hosted git repository. msciabarra pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/openserverless.git
commit e0642f0944b70de1ca1354114c901e218570d85f Author: Michele Sciabarra <[email protected]> AuthorDate: Sat Jul 6 12:48:24 2024 +0200 documentation, extra scripts, submodules --- .gitmodules | 4 +- README.md | 53 ++++++++++++++++--- aliases | 117 ++++++++++++++++++++++++++++++++++++++++++ cli/.envrc | 1 + cli/shell.nix | 10 ++++ cloud-init.yaml | 32 +++++++++--- openserverless-documentation | 1 - openserverless.code-workspace | 23 +++++++++ operator/.envrc | 1 + operator/shell.nix | 10 ++++ sync-branch.sh | 26 ++++++++++ update-tree.sh | 4 ++ website | 1 + 13 files changed, 268 insertions(+), 15 deletions(-) diff --git a/.gitmodules b/.gitmodules index 0b16eb5..32b3f54 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "openserverless-documentation"] - path = openserverless-documentation +[submodule "website"] + path = website url = ssh://[email protected]/nuvolaris/openserverless-documentation diff --git a/README.md b/README.md index 983811b..8553c32 100644 --- a/README.md +++ b/README.md @@ -30,20 +30,61 @@ The method we use to setup a VM in Linux and Mac is using [multipass](https://mu - Otherwise follow [those instructions](https://multipass.run/install) -Once you have `multipass` type the following +Once you have `multipass` type the following and wait util you see `status: done` +``` +multipass launch -nopenserverless -c4 -d20g -m8g --cloud-init https://raw.githubusercontent.com/nuvolaris/openserverless/main/cloud-init.yaml +multipass exec "openserverless" -- sudo cloud-init status --wait +``` + +## Setup SSH access for VSCode + +## Setup access to multipass in Mac and Linux + +To access the virtual machine from VSCode you need to setup a key and a configuration. Follow those steps: + +1. Check if you already have a key in `$HOME/.ssh/id_rsa`. If not, generate one with `ssh-keygen -t rsa` (just press enter to confirm) + +2. copy the key in the virtual machine: ``` -multipass launch -nopenserverless -c4 -d20g -m8g --cloud-init cloud-init.yaml +cat ~/.ssh/id_rsa.pub | multipass exec openserverless -- tee -a .ssh/authorized_keys +``` +3. Create a configuration named `openserverless` to easily access it. -multipass launch -nopenserverless -c4 -d20g -m8g --cloud-init https://raw.githubusercontent.com/nuvolaris/openserverless/main/cloud-init.yaml +First type `multipass list`. You will see something like this: -multipass exec "openserverless" -- sudo cloud-init status --wait +```` +Name State IPv4 Image +openserverless Running 10.6.73.253 Ubuntu 24.04 LTS + 10.42.0.0 + 10.42.0.1 ``` -#### Removal -If you do now want to keep the vm anymore, ensure you have backed up all your files. Then use the following commands to cleanup: +Take note of the `<IP>` in the `openserverless line` (in this case `10.6.73.253` but yours can be different) + +Add to the file `~/ssh/config` the following + +``` +Host openserverless + Hostname <IP> + User ubuntu + IdentityFile ~/.ssh/id_rsa +``` + +4. Check you have access without password: + +``` +ssh openserverless +``` + +### Cleanup + + +If you do now want to keep the vm anymore, esure you have backed up all your files. Then remove it in your cloud provider (check your cloud provider documentation). + +For multipass, use the following commands to cleanup: ``` multipass delete openserverless diff --git a/aliases b/aliases new file mode 100644 index 0000000..729b526 --- /dev/null +++ b/aliases @@ -0,0 +1,117 @@ +## NOTE! This script should be sourced, not executed. +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +alias va="vi ~/openserverless/aliases ; source ~/openserverless/aliases" + +# prompt +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' +} +export PS1="[\h:\[\e[32m\]\w:\[\e[91m\]\$(parse_git_branch)\[\e[00m\]]\n$ " + + +function secrets { + if ! which op + then echo "download the op cli from https://developer.1password.com/docs/cli/get-started/" + return + fi + if ! test -e .env.dist + then echo "no .env.dist listing the required secrets" + return + fi + echo "reading .env.dist to generate .env and .env.src from 1password" + echo "I OVERWRITE the existing files, type your password or interrupt now" + eval $(op signin) + rm -f .env .env.src + cat .env.dist | awk '{ + if(match($1, /^(.*)=(.*):/, a)) { + print a[1] " op://secrets/" a[2] "/" a[1] + } + }' | while read VAR SEC + do + VAL="$(op read $SEC)" + echo read $VAR + echo "$VAR=$VAL" >>.env + echo "echo export and config $VAR" >>.env.src + echo "export $VAR=\"$VAL\"" >>.env.src + echo "nuv -config \"$VAR=$VAL\"" >>.env.src + done + source .env.src +} + +export KNS="default" +alias k='kubectl -n $KNS' +alias kg='kubectl -n $KNS get' +alias kgy='kubectl -n $KNS -o yaml get' +alias kap='kubectl -n $KNS apply -f' +alias kde='kubectl -n $KNS describe' +alias kdel='kubectl -n $KNS delete' +alias kin="kubectl cluster-info" + +function kex { + ME=$1 + CMD=${2:-bash} + kubectl -n $KNS exec -ti $(kubectl -n $KNS get po | awk "/$ME/"'{print $1}') -- $CMD +} + +function klo { + ME=$1 + shift + kubectl -n $KNS logs $(kubectl -n $KNS get po | awk "/$ME/"'{print $1}') "$@" +} + +function kns { + if test -z "$1" + then kubectl get ns + echo "*** current: $KNS ***" + else export KNS="$1" + kubectl config set-context --current --namespace "$1" + fi +} + +alias kwa="watch kubectl get po,deploy,sts,jobs,svc,ingress --no-headers" +alias kwp="watch kubectl get po,deploy,sts,jobs --no-headers" +alias kws="watch kubectl get svc,ingress --no-headers" +alias kwc="watch kubectl get cm,secret --no-headers" + +alias kfin='kubectl patch -p {"metadata":{"finalizers":[]}} --type=merge' + +alias ga="git add" +alias gst="git status" +alias glog="git log --pretty=oneline" +alias gdf="git diff --name-only" +alias gcm="git commit -m" +alias gcam="git commit -a -m" +alias gpom="git push origin main" + +function gsnap { + if test -z "$1" + then echo msg please + else x=""; for i in "$@" ; do x="$x$i " ; done + git commit -a -m "$x" + git push + fi +} + +alias t=task +alias tt='task -d ..' +alias ttt='task -d ../..' +alias dtag="date +%y%m%d%H" +alias lenv='export $(xargs <.env)' +alias nssh="ssh -oStrictHostKeyChecking=no" diff --git a/cli/.envrc b/cli/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/cli/.envrc @@ -0,0 +1 @@ +use nix diff --git a/cli/shell.nix b/cli/shell.nix new file mode 100644 index 0000000..34426f6 --- /dev/null +++ b/cli/shell.nix @@ -0,0 +1,10 @@ +let + nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-23.11"; + pkgs = import nixpkgs { config = {}; overlays = []; }; +in + +pkgs.mkShellNoCC { + packages = with pkgs; [ + go + ]; +} diff --git a/cloud-init.yaml b/cloud-init.yaml index fc2fdd4..65c66d6 100644 --- a/cloud-init.yaml +++ b/cloud-init.yaml @@ -2,14 +2,34 @@ apt_update: true apt_upgrade: true runcmd: - - > + - | + # install k3s, direnv, task curl -sfL https://get.k3s.io | sh - - - > curl -sfL https://direnv.net/install.sh | bash + snap install task --classic + echo "OPS_CLOUD_INIT_VER=1" >>/etc/environment - | + # set home and user USR="$(getent passwd 1000 | awk -F: '{print $1}')" - mkdir -p "/home/$USR/.kube" - cp /etc/rancher/k3s/k3s.yaml "/home/$USR/.kube/config" - chown -Rvf "$USR" "/home/$USR/.kube" - curl -L https://nixos.org/nix/install | sudo -u "$USR" sh -s -- --daemon + HOME="/home/$USR" + # access k3s + mkdir -p "$HOME/.kube" + cp /etc/rancher/k3s/k3s.yaml "$HOME/.kube/config" + echo "export KUBECONFIG=/home/$USR/.kube/config" >>$HOME/.bashrc + # use direnv for autoinit + echo 'eval "$(direnv hook bash)"' >>$HOME/.bashrc + # install nix + curl -L https://nixos.org/nix/install | sudo -u "$USR" sh -s -- --no-daemon + # get openserverless sources + cd $HOME + git clone ssh://[email protected]/nuvolaris/openserverless --recurse-submodules + # add aliases + echo "source $HOME/openserverless/aliases" >>$HOME/.bashrc + # change owner to everything + chown -Rvf "$USR" "$HOME" + # allow direnv for submodules + sudo -u $USR direnv allow $HOME/openserverless/cli + sudo -u $USR direnv allow $HOME/openserverless/operator + sudo -u $USR direnv allow $HOME/openserverless/website + \ No newline at end of file diff --git a/openserverless-documentation b/openserverless-documentation deleted file mode 160000 index e94376f..0000000 --- a/openserverless-documentation +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e94376f1ae7fabf27d9f955f2db344750ccd48fe diff --git a/openserverless.code-workspace b/openserverless.code-workspace new file mode 100644 index 0000000..6a9a4f5 --- /dev/null +++ b/openserverless.code-workspace @@ -0,0 +1,23 @@ +{ + "folders": [ + { + "name": "operator", + "path": "operator" + }, + { + "name": "cli", + "path": "cli" + }, + { + "name": "website", + "path": "website" + } + ], + "settings": { + "workbench.colorCustomizations": { + "activityBar.background": "#0F3506", + "titleBar.activeBackground": "#154A09", + "titleBar.activeForeground": "#F1FDEE" + } + } +} \ No newline at end of file diff --git a/operator/.envrc b/operator/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/operator/.envrc @@ -0,0 +1 @@ +use nix diff --git a/operator/shell.nix b/operator/shell.nix new file mode 100644 index 0000000..85c40b1 --- /dev/null +++ b/operator/shell.nix @@ -0,0 +1,10 @@ +let + nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-23.11"; + pkgs = import nixpkgs { config = {}; overlays = []; }; +in + +pkgs.mkShellNoCC { + packages = with pkgs; [ + python3 + ]; +} diff --git a/sync-branch.sh b/sync-branch.sh new file mode 100644 index 0000000..413f5ea --- /dev/null +++ b/sync-branch.sh @@ -0,0 +1,26 @@ +#!/bin/bash +me="$(realpath $0)" +if test -z "$1" +then + cd "$(dirname $0)" + git submodule --quiet foreach --recursive "$me \$toplevel/.gitmodules \$name" + #>_submodules + #cat _submodules +else + #echo "*** $1 - $2 ***" + #pwd + BRANCH=$(git config -f "$1" "submodule.$2.branch") + if test -z "$BRANCH" + then echo "??? $(pwd) no branch: $2" + else + CUR=$(git rev-parse --abbrev-ref HEAD) + if test "$CUR" = "HEAD" + then git checkout "origin/$BRANCH" -B "$BRANCH" + else + if test "$CUR" = "$BRANCH" + then echo "ok: $2@$CUR " + else echo "!!! $2: found: $CUR expected: $BRANCH" + fi + fi + fi +fi \ No newline at end of file diff --git a/update-tree.sh b/update-tree.sh new file mode 100644 index 0000000..d6ab36b --- /dev/null +++ b/update-tree.sh @@ -0,0 +1,4 @@ +#!/bin/bash +git pull origin main --rebase +git submodule update --recursive --remote +bash sync-branch.sh diff --git a/website b/website new file mode 160000 index 0000000..fd07b29 --- /dev/null +++ b/website @@ -0,0 +1 @@ +Subproject commit fd07b29963c2bbf283118011a20ec8874a13aefd
