Customize sandbox hosts
Now that you've got the hang of creating and publishing tracks, you can configure your containers and VMs using setup scripts. Things you might want to do include:
  • Install your own packages and configure them
  • Add files to the host
  • Start additional services
In this guide you'll learn how to:
  1. 1.
    Create a track_scripts directory and track setup script for a host.
  2. 2.
    Create a setup script for an individual challenge.

Create a track setup script

Instruqt tracks can have an optional track_scripts directory for setting up your hosts before the learner has access to the first challenge. You can read more about track scripts in the docs.
  • Open your track in your terminal or favorite text editor and create a new directory called track_scripts in the root of your track.
  • If you've been following the Getting Started guide, you'll have a single host named container. Setup scripts always follow the naming format: setup-<hostname>. Create a new file in the track_scripts directory called setup-container.
  • Edit the setup-container file and insert the following code. Save the file once you've copied in the code.
1
#!/bin/bash
2
# This set line ensures that all failures will cause the script to error and exit
3
set -euxo pipefail
4
5
# Here we are installing the nginx package. The noninteractive setting ensures
6
# that the apt command won't stop and ask for user input.
7
apt -y update
8
DEBIAN_FRONTEND=noninteractive apt -y install nginx
9
10
# Remove the default nginx page and replace it with our own
11
rm /var/www/html/index.nginx-debian.html
12
13
# This cat/EOF trick renders a new index file. This code creates really simple
14
# website that shows pictures of cats. Everything between the EOF markers will
15
# end up in the /var/www/html/index.html file
16
cat >> /var/www/html/index.html <<-EOF
17
<html>
18
<head><title>Meow!</title></head>
19
<body>
20
<div style="width:800px;margin: 0 auto">
21
<!-- BEGIN -->
22
<center><img src="http://placekitten.com/640/480"></img></center>
23
<center><h2>Meow World!</h2></center>
24
<center>Welcome to the Meow World application. Meow! =^._.^=</center>
25
<!-- END -->
26
27
</div>
28
</body>
29
</html>
30
EOF
31
32
# Start up nginx
33
service nginx start
Copied!
  • Publish your changes with the instruqt track push command.
  • Run instruqt track logs and start up your track. Observe the logs and notice how the setup script runs before you're able to start the first challenge.
Installing software with setup scripts is not recommended for production tracks. Instead, you should build an image which ensures fast track startup and fewer runtime dependencies. Setup scripts are best used for final configuration steps and not installing bulky software.

Create a challenge setup script

Challenge scripts run right before a challenge becomes available. This is useful when other steps must be completed before the setup script runs. For example, you might need a user to create a file or install some software before the setup script can run.
If you've been following the Getting Started tutorial, you should have a challenge called 02-second-challenge.
Open the track in your terminal or favorite text editor and look inside the 02-second-challenge directory:
1
my-first-track
2
└── 02-second-challenge
3
├── assignment.md
4
├── check-container
5
├── cleanup-container
6
├── setup-container
7
└── solve-container
Copied!
Notice how the Instruqt CLI has created some sample lifecycle scripts for you. Edit the setup-container script and replace it with the following code:
1
#!/bin/bash
2
set -euxo pipefail
3
4
echo "This script runs when a challenge is launched."
Copied!
Save the file and push your changes as before. Run instruqt track logs and launch the track. Proceed through the track while watching the log stream. You will see the echo command when you finish the first challenge and move to the second one.
Last modified 15d ago