JS5 student free servers design doc

JS5 student servers design doc

Unfinished design doc

Goals

  • After a student completes JS4, a server should be created for them which they'll use to practice the content of JS5 in it.

Action items

  1. Get the student SSH key
  2. Create a server through DigitalOcean API
  3. Link the server IP to the student data in the DB
  4. Display the reward and how it could be redeemed

Get the student SSH key

After the student completes JS4, The student will input their SSH key into a page under /[username]/server, this SSH will be used in the next action item to ensure that the student will have access to the server (and the admins).

Create a server (droplet) through DigitalOcean API

After getting the student SSH key, an action will auto be run that will send a POST request to the API endpoint https://api.digitalocean.com/v2/droplets to create a droplet with the following payload including the student SSH key:

{
"name": "student.id.c0d3",
"region": "student_chosen_region",
"size": "s-1vcpu-1gb",
"image": "ubuntu-20-04-x64",
"ssh_keys": [
289794,
"3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45",
// Student SSH key and the admins
]
}

Example code:

try {
const input = {
name: 'example.com', // string
region: 'nyc3', // string
size: 's-1vcpu-1gb', // string
image: 'ubuntu-16-04-x64', // string
ssh_keys: ['Student_SSH_key', ...AdminSSHKeys],
}
const {
data: { droplet },
} = await dots.droplet.createDroplet(input)
console.log(droplet)
} catch (error) {
console.log(error)
}

Example response:

{
"droplet": {
"id": 3164444,
"name": "example.com",
"memory": 1024,
"vcpus": 1,
"disk": 25,
"locked": false,
"status": "new",
"kernel": null,
"created_at": "2020-07-21T18:37:44Z",
"features": [],
"backup_ids": [ ],
"next_backup_window": null,
"snapshot_ids": [ ],
"image": {},
"volume_ids": [ ],
"size": {},
"size_slug": "s-1vcpu-1gb",
"networks": {},
"region": {},
"tags": []
},
"links": {
"actions": []
}
}

To get the Droplet IP and link it to the student, we could get it from the response's droplet.networks.v4. The droplet.networks is an object that has two properties: 1. v4 array of IPs 2. v6 array of IPs

Example:

"networks": {
"v4": [
{
"ip_address": "104.131.186.241",
"netmask": "255.255.240.0",
"gateway": "104.131.176.1",
"type": "public"
}
],
"v6": [
{
"ip_address": "2604:A880:0800:0010:0000:0000:031D:2001",
"netmask": 64,
"gateway": "2604:A880:0800:0010:0000:0000:0000:0001",
"type": "public"
}
]
},

After getting the IP, we can set the user record in the db user.serverIp to networks.v4[0].ip_address

Display the reward and how it could be redeemed

The student can either redeem the reward from the lesson challenges page OR through the notification that'll appear on their profile page.

From the challenge page:

Many students don't make it to JS4. For your hard efforts, here's your own free c0d3 server
<BUTTON> -> Once clicked, it'll create a server on DigitalOcean
<SECTION> -> FAQ
E.g, What will happens if I stopped using the server?

Issues

How to monitor student access to their servers

  1. The server will expire after the student finish JS5
    • Remove the server once they finish JS5
  2. The server will exist as long as they use it
    • "using it" means resources. They might have a server running that will use some of the resources. Monitoring their usage based on this metric won't work
    • A better way is to monitor the most recent times they SSH-ed into the server. If the last time they accessed it is x days old, remove the server. To achieve this, we must create a custom image that'll have the SSH access monitoring system.

References