Create a computer, serve a page from it over HTTPS, pass it a secret and branch it
You will create a computer, serve a page from it over HTTPS, pass it a secret and branch it. The branch gets its own copy of the files, so you can change it while the source keeps running.
Prerequisites
You need:
- The
neviaCLI, installed and signed in. - The admin or editor role in your workspace, with the names
helloandhello-branchfree. The workspace from your first sign-in works.
Create a computer
Create a computer named hello from the platform default image. It publishes
port 8080 on HTTPS port 443, and the command waits until the computer is
ready:
nevia new hello -p 443:8080 --wait
nevia status helloThe state is ready and url shows an address that looks like
https://<host>. Copy it. The URL is set when the computer first becomes
ready and never changes.
Run a web server
Write a page to the home directory. Commands start there, and sync flushes
the file to disk so that a branch taken later includes it:
nevia exec hello -- sh -c 'echo "<h1>Hello from Nevia</h1>" > index.html && sync'Start a web server on port 8080 in the background. nohup and the redirects
keep it running after the command returns:
nevia exec hello -- sh -c 'nohup python3 -m http.server 8080 >/dev/null 2>&1 &'If either command fails, see Handle a failed command.
Open the URL
Request the URL from step 1:
curl https://<host>You should see:
<h1>Hello from Nevia</h1>Your browser shows the same page. Until something listens on port 8080, the
URL returns 503.
Pass it a secret
Store a value in the workspace once. At a terminal, --file - prompts for
one hidden line, so the value stays out of your shell history:
nevia secrets API_TOKEN --file -Pass it to a command by name. This prints only the length of the value:
nevia exec hello -e secrets.API_TOKEN -- sh -c 'echo "${#API_TOKEN} characters"'Every command on any computer in the workspace can take the secret the same
way. Give computers secrets and variables
covers variables, .env imports and rotation.
Branch the computer
Branch hello as hello-branch and read the page on the branch:
nevia branch hello-branch --source hello --wait
nevia exec hello-branch -- cat index.htmlThe branch starts from the same image with its own copy of the home directory, so it prints the page you wrote. Change it on the branch, then read both:
nevia exec hello-branch -- sh -c 'echo "<h1>Hello from the branch</h1>" > index.html'
nevia exec hello-branch -- cat index.html
nevia exec hello -- cat index.htmlThe branch prints the new page. The source still prints Hello from Nevia
and kept serving it the whole time. A branch copies disks and starts fresh,
so the web server is not running on it. To restore memory as well as disks,
save and restore a checkpoint.
Clean up
Delete both computers and the secret:
nevia rm hello-branch --yes --wait
nevia rm hello --yes --wait
nevia secrets unset API_TOKEN
nevia lsNeither computer appears in the list.
Next steps
- Give computers secrets and variables stores configuration and credentials for every computer in a workspace.
- Use Git on a computer clones a repository, including a private one.
- Run a coding agent on a computer installs an agent and gives it a task.
- Create and restore checkpoints saves a computer's memory and disks.
- Group work in projects shows how to keep related computers and databases together, if you want to.