Re: faasd

From Funky Penguin, 2 Years ago, written in Plain Text, viewed 311 times. This paste is a reply to faasd from Colorant Parrot - view diff
URL https://paste.steamr.com/view/f9b11635 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2.  
  3. # Copyright OpenFaaS Author(s) 2022
  4.  
  5. set -e -x -o pipefail
  6.  
  7. export OWNER="openfaas"
  8. export REPO="faasd"
  9.  
  10. version=""
  11.  
  12. echo "Finding latest version from GitHub"
  13. version=$(curl -sI https://github.com/$OWNER/$REPO/releases/latest | grep -i "location:" | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
  14. echo "$version"
  15.  
  16. if [ ! $version ]; then
  17.   echo "Failed while attempting to get latest version"
  18.   exit 1
  19. fi
  20.  
  21. SUDO=sudo
  22. if [ "$(id -u)" -eq 0 ]; then
  23.   SUDO=
  24. fi
  25.  
  26. verify_system() {
  27.   if ! [ -d /run/systemd ]; then
  28.     fatal 'Can not find systemd to use as a process supervisor for faasd'
  29.   fi
  30. }
  31.  
  32. has_yum() {
  33.   [ -n "$(command -v yum)" ]
  34. }
  35.  
  36. has_apt_get() {
  37.   [ -n "$(command -v apt-get)" ]
  38. }
  39.  
  40. has_pacman() {
  41.   [ -n "$(command -v pacman)" ]
  42. }
  43.  
  44. install_required_packages() {
  45.   if $(has_apt_get); then
  46.     # Debian bullseye is missing iptables. Added to required packages
  47.     # to get it working in raspberry pi. No such known issues in
  48.     # other distros. Hence, adding only to this block.
  49.     # reference: https://github.com/openfaas/faasd/pull/237
  50.     $SUDO apt-get update -y
  51.     $SUDO apt-get install -y curl runc bridge-utils iptables
  52.   elif $(has_yum); then
  53.     $SUDO yum check-update -y || :
  54.     $SUDO yum install -y curl runc || :
  55.   elif $(has_pacman); then
  56.     $SUDO pacman -Syy
  57.     $SUDO pacman -Sy curl runc bridge-utils
  58.   else
  59.     fatal "Could not find apt-get, yum, or pacman. Cannot install dependencies on this OS."
  60.     exit 1
  61.   fi
  62. }
  63.  
  64. install_cni_plugins() {
  65.   cni_version=v0.9.1
  66.   suffix=""
  67.   arch=$(uname -m)
  68.   case $arch in
  69.   x86_64 | amd64)
  70.     suffix=amd64
  71.     ;;
  72.   aarch64)
  73.     suffix=arm64
  74.     ;;
  75.   arm*)
  76.     suffix=arm
  77.     ;;
  78.   *)
  79.     fatal "Unsupported architecture $arch"
  80.     ;;
  81.   esac
  82.  
  83.   $SUDO mkdir -p /opt/cni/bin
  84.   curl -sSL https://github.com/containernetworking/plugins/releases/download/${cni_version}/cni-plugins-linux-${suffix}-${cni_version}.tgz | $SUDO tar -xvz -C /opt/cni/bin
  85. }
  86.  
  87. install_containerd() {
  88.   arch=$(uname -m)
  89.   CONTAINERD_VER=1.6.3
  90.   case $arch in
  91.   x86_64 | amd64)
  92.     curl -sLSf https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VER}/containerd-${CONTAINERD_VER}-linux-amd64.tar.gz | $SUDO tar -xvz --strip-components=1 -C /usr/local/bin/
  93.     ;;
  94.   armv7l)
  95.     curl -sSL https://github.com/alexellis/containerd-arm/releases/download/v${CONTAINERD_VER}/containerd-${CONTAINERD_VER}-linux-armhf.tar.gz | $SUDO tar -xvz --strip-components=1 -C /usr/local/bin/
  96.     ;;
  97.   aarch64)
  98.       curl -sLSf https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VER}/containerd-${CONTAINERD_VER}-linux-arm64.tar.gz | $SUDO tar -xvz --strip-components=1 -C /usr/local/bin/
  99.  
  100.     ;;
  101.   *)
  102.     fatal "Unsupported architecture $arch"
  103.     ;;
  104.   esac
  105.  
  106.   $SUDO systemctl unmask containerd || :
  107.   $SUDO curl -SLfs https://raw.githubusercontent.com/containerd/containerd/main/containerd.service --output /etc/systemd/system/containerd.service
  108.   $SUDO systemctl enable containerd
  109.   $SUDO systemctl start containerd
  110.  
  111.   sleep 5
  112. }
  113.  
  114. install_faasd() {
  115.   arch=$(uname -m)
  116.   case $arch in
  117.   x86_64 | amd64)
  118.     suffix=""
  119.     ;;
  120.   aarch64)
  121.     suffix=-arm64
  122.     ;;
  123.   armv7l)
  124.     suffix=-armhf
  125.     ;;
  126.   *)
  127.     echo "Unsupported architecture $arch"
  128.     exit 1
  129.     ;;
  130.   esac
  131.  
  132.   $SUDO curl -fSLs "https://github.com/openfaas/faasd/releases/download/${version}/faasd${suffix}" --output "/usr/local/bin/faasd"
  133.   $SUDO chmod a+x "/usr/local/bin/faasd"
  134.  
  135.   mkdir -p /tmp/faasd-${version}-installation/hack
  136.   cd /tmp/faasd-${version}-installation
  137.   $SUDO curl -fSLs "https://raw.githubusercontent.com/openfaas/faasd/${version}/docker-compose.yaml" --output "docker-compose.yaml"
  138.   $SUDO curl -fSLs "https://raw.githubusercontent.com/openfaas/faasd/${version}/prometheus.yml" --output "prometheus.yml"
  139.   $SUDO curl -fSLs "https://raw.githubusercontent.com/openfaas/faasd/${version}/resolv.conf" --output "resolv.conf"
  140.   $SUDO curl -fSLs "https://raw.githubusercontent.com/openfaas/faasd/${version}/hack/faasd-provider.service" --output "hack/faasd-provider.service"
  141.   $SUDO curl -fSLs "https://raw.githubusercontent.com/openfaas/faasd/${version}/hack/faasd.service" --output "hack/faasd.service"
  142.   $SUDO /usr/local/bin/faasd install
  143. }
  144.  
  145. install_caddy() {
  146.   if [ ! -z "${FAASD_DOMAIN}" ]; then
  147.     arch=$(uname -m)
  148.     case $arch in
  149.     x86_64 | amd64)
  150.       suffix="amd64"
  151.       ;;
  152.     aarch64)
  153.       suffix=-arm64
  154.       ;;
  155.     armv7l)
  156.       suffix=-armv7
  157.       ;;
  158.     *)
  159.       echo "Unsupported architecture $arch"
  160.       exit 1
  161.       ;;
  162.     esac
  163.  
  164.     curl -sSL "https://github.com/caddyserver/caddy/releases/download/v2.4.3/caddy_2.4.3_linux_${suffix}.tar.gz" | $SUDO tar -xvz -C /usr/bin/ caddy
  165.     $SUDO curl -fSLs https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service --output /etc/systemd/system/caddy.service
  166.  
  167.     $SUDO mkdir -p /etc/caddy
  168.     $SUDO mkdir -p /var/lib/caddy
  169.    
  170.     if $(id caddy >/dev/null 2>&1); then
  171.       echo "User caddy already exists."
  172.     else
  173.       $SUDO useradd --system --home /var/lib/caddy --shell /bin/false caddy
  174.     fi
  175.  
  176.     $SUDO tee /etc/caddy/Caddyfile >/dev/null <<EOF
  177. {
  178.   email "${LETSENCRYPT_EMAIL}"
  179. }
  180.  
  181. ${FAASD_DOMAIN} {
  182.   reverse_proxy 127.0.0.1:8080
  183. }
  184. EOF
  185.  
  186.     $SUDO chown --recursive caddy:caddy /var/lib/caddy
  187.     $SUDO chown --recursive caddy:caddy /etc/caddy
  188.  
  189.     $SUDO systemctl enable caddy
  190.     $SUDO systemctl start caddy
  191.   else
  192.     echo "Skipping caddy installation as FAASD_DOMAIN."
  193.   fi
  194. }
  195.  
  196. install_faas_cli() {
  197.   curl -sLS https://cli.openfaas.com | $SUDO sh
  198. }
  199.  
  200. verify_system
  201. install_required_packages
  202.  
  203. $SUDO /sbin/sysctl -w net.ipv4.conf.all.forwarding=1
  204. echo "net.ipv4.conf.all.forwarding=1" | $SUDO tee -a /etc/sysctl.conf
  205.  
  206. install_cni_plugins
  207. install_containerd
  208. install_faas_cli
  209. install_faasd
  210. install_caddy

Reply to "Re: faasd"

Here you can reply to the paste above