Skip to content

Prepare the machine

The shared disk has Ubuntu and Docker. A lesson that needs something else adds it while the disk is built, so the learner finds it already there.

The nginx example is that kind of lab. Its lesson expects a web server to be running when the page opens.

A script that runs during the build

setup.sh is a shell script in the lab directory. It runs once, as root, while the disk is being built. It has the network. It does not run again when a learner opens the lab.

nginx/setup.sh installs nginx. It also adds one line to nginx's welcome page, so the page is easy to recognize. The file in the pack is the copy to read.

Files the lesson needs

A data directory in the lab is copied to /root/data/ on the machine during the build. Put files there when the lesson should find them already on disk. An empty data directory adds nothing. nginx does not use one.

A lab with setup.sh, or with a file under data, gets its own disk. The disk's name is the lab's name.

The lab's disk

The first sudo ./trylab nginx says nginx's disk is missing and asks Build it now?. Press Enter to build it. That writes a disk named nginx. The shared disk is left as it is.

A snapshot

Opening a lab starts the machine from its disk. That start includes a boot. A snapshot is a save of the machine after it has booted and your software is running. The next open resumes the save. The learner does not wait for the boot, and the program is already listening.

snapshot: true asks for that save. The first time you open the lab, trylab boots the machine, waits until it can log in, and writes the snapshot. That takes a while. The next open resumes it.

The save is taken when the pack can log in. nginx/setup.sh makes that login wait until nginx is running, so the saved machine already has the server listening. The file in the pack is the one to copy when another program has to be up before the save.

A service

A service is a link on the lab page, in the bar above the lesson. The link opens in a new tab. It points at a port on the lab's machine.

name is the word on the link. port is the port on the machine. path is the path on that port. A path starts with /. Leaving it out uses /.

nginx serves its welcome page on port 80 at /.

The whole file

nginx/config.yaml puts the new pieces together:

title: Nginx basics
description: An example of a lesson with a memory snapshot - nginx running, plus a service link.
snapshot: true
services:
  - name: nginx
    port: 80
    path: /

Open it

sudo ./trylab nginx

The first run builds the disk if it is missing, saves the snapshot, then prints the page address. Click nginx in the bar. The tab is nginx's welcome page, including the line the setup script added. In the shell, curl http://127.0.0.1/ fetches that same page, because 127.0.0.1 is the machine you are logged into.