├── .DEREK.yml ├── Dockerfile ├── LICENSE ├── provision-digitalocean.sh ├── cloudinit.txt └── README.md /.DEREK.yml: -------------------------------------------------------------------------------- 1 | redirect: https://raw.githubusercontent.com/openfaas/faas/master/.DEREK.yml 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM codercom/code-server:3.9.1 2 | 3 | USER root 4 | 5 | RUN apt update -qy && \ 6 | apt install -qy nano tmux 7 | 8 | RUN curl -SLs https://get.docker.com | sh 9 | 10 | RUN curl -SLs https://dl.get-arkade.dev | sh 11 | RUN arkade get faas-cli && \ 12 | arkade get kubectl && \ 13 | arkade get helm && \ 14 | chmod +x $HOME/.arkade/bin/* && \ 15 | mv $HOME/.arkade/bin/* /usr/local/bin/ 16 | 17 | RUN usermod -aG docker coder 18 | 19 | ENV DISABLE_TELEMETRY=true 20 | 21 | WORKDIR /home/coder 22 | USER coder 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 openfaas-incubator 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /provision-digitalocean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Adapted from https://inlets.dev 4 | 5 | export SUFFIX=$(head -c 16 /dev/urandom | shasum | cut -c1-8) 6 | export DROPLETNAME="of-workshop-$SUFFIX" 7 | export SIZE="s-2vcpu-4gb" 8 | export IMAGE="ubuntu-16-04-x64" 9 | export REGION="lon1" 10 | export FIELDS="ID,Name,PublicIPv4" 11 | export USERDATA=`pwd`/cloudinit.txt 12 | 13 | echo "Creating: $DROPLETNAME" 14 | 15 | dropletInfo="$(doctl compute droplet create $DROPLETNAME \ 16 | --size $SIZE \ 17 | --image $IMAGE \ 18 | --region $REGION \ 19 | --user-data-file $USERDATA \ 20 | --format "$FIELDS" \ 21 | --no-header \ 22 | --wait \ 23 | )" 24 | 25 | if [ $? -eq 0 ]; 26 | then 27 | 28 | readfields=$(sed 's/,/ /g' <<<$FIELDS) 29 | read -r $readfields <<<"$dropletInfo" 30 | 31 | echo "==============================" 32 | echo "Droplet: $Name has been created" 33 | echo "IP: $PublicIPv4" 34 | echo "URL: https://$PublicIPv4:8443" 35 | echo "Login: ssh root@$PublicIPv4" 36 | echo "==============================" 37 | echo "To destroy this droplet run: doctl compute droplet delete -f $ID" 38 | 39 | fi 40 | 41 | -------------------------------------------------------------------------------- /cloudinit.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "tail -f /var/log/cloud-init-output.log" > /root/logs.sh 4 | chmod +x /root/logs.sh 5 | 6 | curl -SLs https://get.docker.com | sudo sh 7 | 8 | curl -SLs https://dl.get-arkade.dev | sudo sh 9 | arkade get k3sup && \ 10 | arkade get kubectl && \ 11 | arkade get faas-cli && \ 12 | sudo chmod +x $HOME/.arkade/bin/* && \ 13 | sudo mv $HOME/.arkade/bin/* /usr/local/bin/ 14 | 15 | export IP=$(curl -sfSL https://checkip.amazonaws.com) 16 | 17 | echo IP: $IP 18 | 19 | mkdir -p /root/.kube/ 20 | k3sup install --local --tls-san $IP \ 21 | --no-extras \ 22 | --merge --local-path=/root/.kube/config 23 | 24 | mkdir -p /home/coder/project/openfaas \ 25 | && chmod 777 /home/coder/project/openfaas 26 | 27 | arkade install openfaas 28 | 29 | kubectl rollout status deploy/gateway -n openfaas 30 | 31 | export OPENFAAS_URL=http://$IP:31112 32 | 33 | PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo) 34 | echo $PASSWORD > /home/coder/project/openfaas/04-gateway-password 35 | 36 | echo $OPENFAAS_URL > /home/coder/project/openfaas/03-gateway-url 37 | 38 | echo "export OPENFAAS_URL=$OPENFAAS_URL" | tee -a /home/coder/project/openfaas/01-add-to-bashrc.txt 39 | 40 | echo "echo -n $PASSWORD | faas-cli login -g $OPENFAAS_URL -u admin --password-stdin" > /home/coder/project/openfaas/02-run-this.txt 41 | 42 | chmod 777 -R /home/coder/project/openfaas 43 | 44 | # Run VSCode last 45 | 46 | sed -ie s/localhost/$IP/g /root/.kube/config 47 | sed -ie s/127.0.0.1/$IP/g /root/.kube/config 48 | chmod 777 /root/.kube/config 49 | 50 | mkdir -p /root/certs 51 | 52 | # Generate self-signed cert 53 | 54 | openssl req -nodes -newkey rsa:2048 -keyout /root/certs/tmp-openfaas-ltd.key \ 55 | -out /root/certs/tmp-openfaas-ltd.crt -x509 -days 365 \ 56 | -subj "/C=UK/ST=CAMBS/L=Peterborough/O=OpenFaaS Ltd/OU=Workshop/CN=$IP" 57 | 58 | chown 1000 -R /root/certs/ 59 | 60 | pass=$(head -c 16 /dev/urandom | shasum | cut -d' ' -f1) 61 | hash=$(echo -n $pass | shasum | cut -d' ' -f1) 62 | 63 | mkdir -p /root/.config/code-server 64 | 65 | cat > /root/.config/code-server/config.yaml< /home/coder/project/openfaas/01-add-to-bashrc.txt 77 | 78 | docker rm -f vscode 79 | docker run --name vscode \ 80 | --user coder \ 81 | -v /root/certs:/home/coder/certs \ 82 | -v /home/coder/project/openfaas:/home/coder/project/openfaas \ 83 | -v /root/.kube/config:/home/coder/.kube/config \ 84 | -v /root/.config/code-server:/home/coder/.config/code-server2 \ 85 | -v /var/run/docker.sock:/var/run/docker.sock \ 86 | -e CODE_SERVER_CONFIG=/home/coder/.config/code-server2/config.yaml \ 87 | --restart=always \ 88 | --privileged \ 89 | -p 8443:8080 \ 90 | -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 91 | # docker logs -f vscode 92 | 93 | echo Password for UI: $pass 94 | echo URL for UI: https://$IP:8443 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # workshop-vscode 2 | 3 | OpenFaaS Workshop with in-browser version of VSCode from [coder.com](https://coder.com) 4 | 5 | All tools are pre-installed with OpenFaaS on Kubernetes with k3s available in the browser terminal. 6 | 7 | ## How it works 8 | 9 | 1) A Virtual Machine will be provisioned with a cloud hosting provider using cloudinit 10 | 2) [Kubernetes](https://kubernetes.io/) with [k3s](https://k3s.io/) will be installed on the VM 11 | 3) [OpenFaaS](https://www.openfaas.com/) will be installed into the k3s cluster 12 | 4) A Docker image will be run which provides [VSCode](https://k3s.io/) via a web-browser 13 | 5) The login password for VSCode will be obtained via `ssh` 14 | 6) VSCode can now be used in web-browser via your VM's IP. The self-signed certificate will provide encryption and the login password will protect against tampering. 15 | 16 | ## Why do we need this? 17 | 18 | This project provides a pre-installed Kubernetes environment within a VM so that your students can focus on your workshop. 19 | 20 | The example in this repository is for [The OpenFaaS Workshop](https://github.com/openfaas/workshop). It is estimated that it would save students 1.5-2 hours of set-up time. Instructors could also pre-provision a set amount of VMs ahead of time and then give out IP address and password combinations. 21 | 22 | ## Quick-start 23 | 24 | You can run the instructions above on any cloud that supports cloudinit, or if you have a VM platform that does not allow, or support cloudinit, you can simply run the contents of "cloudinit.txt" as root on the VM after it has booted up. 25 | 26 | ### Provision on DigitalOcean 27 | 28 | * [Get 100 USD free credit for 60 days](https://m.do.co/c/8d4e75e9886f) 29 | * Create a DigitalOcean VM size 4GB RAM in your local region 30 | * Add "user data" from `cloudinit.txt` 31 | * Pick "ssh" login or via root password over email 32 | * Deploy the VM 33 | 34 | Skip to "After the deployment" 35 | 36 | ### Provision on Civo 37 | 38 | * [Get 50 USD credits for new sign-ups](https://bit.ly/2Lx9d2o) 39 | * Create a Medium sized VM and get your login details 40 | * `cloudinit` is not available on Civo at this time, but you can log in after the VM is ready and run the script manually instead 41 | * Use `ssh` to connect to the instance, now paste in the content from `cloudinit.txt` into your terminal 42 | 43 | Skip to "After the deployment" 44 | 45 | ### After the deployment 46 | 47 | * Locate the public IP given and navigate to `https://IP:8443` in a web-browser. This will open VSCode. 48 | * You will need to accept the self-signed certificate, which will display as "insecure". Despite the warning, it will provide encryption for your connection. 49 | * You may have to wait for several minutes before the endpoint to comes up. See the second on Debugging if you want to check the logs. 50 | * Open a Terminal within VSCode and run through the files in ~/project/openfaas/ 51 | * Next start the workshop from [Lab 2](https://github.com/openfaas/workshop) 52 | 53 | ## Get your password 54 | 55 | Get the container's logs with: 56 | 57 | ```sh 58 | export IP="" 59 | ssh root@$IP "docker logs vscode | grep Password" 60 | 61 | INFO Password: 7d6ae6958e8d7e882ba08f57 62 | ``` 63 | 64 | > Note: the password shown is an example, you will have your own password. 65 | 66 | ## Debug / get the cloudinit logs 67 | 68 | * Log into instance `ssh root@IP` 69 | * View the logs for cloudinit 70 | 71 | Either run `/root/logs.sh` or `tail -f /var/log/cloud-init-output.log` 72 | 73 | ## Automation 74 | 75 | Setup a VM using a script in the London region: 76 | 77 | ```sh 78 | # ./provision-digitalocean.sh 79 | 80 | Creating: of-workshop-ebddfcaf 81 | ============================== 82 | Droplet: of-workshop-ebddfcaf has been created 83 | IP: 178.128.42.184 84 | URL: https://178.128.42.184:8443 85 | Login: ssh root@178.128.42.184 86 | ============================== 87 | To destroy this droplet run: doctl compute droplet delete -f 150218836 88 | 89 | ``` 90 | 91 | You'll be emailed the root password, which you can use to log in and get the VSCode password. 92 | 93 | ## Customize for your own workshops and training sessions 94 | 95 | There are two parts you can customize: 96 | 97 | * The Docker image: `alexellis2/coder:2021-03-22`, which is built from [Dockerfile](./Dockerfile) 98 | 99 | The Docker image provides the VSCode hosting _and_ the CLI tools within the built-in terminal. The Docker image is derrived from [coder.com](https://coder.com). 100 | 101 | * The [./cloudinit.txt](./cloudinit.txt) which configures the VM 102 | 103 | For instance, if you wanted to run a workshop on *How to design helm charts* - you may comment out the references to OpenFaaS and install helm/tiller into the Docker image. 104 | 105 | 106 | --------------------------------------------------------------------------------