Workspace
Prerequisites
Section titled “Prerequisites”- Language-specific tools - Install Heim Prerequisites
- Heim cli and runtime - Install Heim
- Text Editor - VsCode is a great option with language-specific plugins
- Terminal - Heim is accessed through its command-line interface
Workspace in Heim
Section titled “Workspace in Heim”A workspace is a convenience function in Heim that gives you the ability to deploy multiple applications in one
command instead of deploying them all one by one.
In a normal workflow you create a new application, make your desired changes and deploy the application. If you
intend to make multiple applications were each is a single function in a function as a service way you would need
to deploy each application individually to deploy your entire system which can get tedious and this is were a
workspace can help you. Below we will create a workspace consisting of 3 applications
For this guide I’m using PowerShell. If you are using a different commdand shell you will have to update the commands accordingly.
Create workspace folder
Section titled “Create workspace folder”Create a folder where you want to create your workspace, I will be using
C:\heim_workspacefor this guide:PowerShell PS C:\> New-Item -ItemType Directory -Name "heim_workspace"; Set-Location "heim_workspace"Creating an application and the workspace
Section titled “Creating an application and the workspace”Next, we are going to create a new heim template with the addition of the
-wflag which will create your application template and aheim.tomlfile.
Take note of the-wflag as that is crucial for creating a workspace or adding a new application to your workspace. If you omit-wit will create an application that is not added to your workspace.
Run the following command:PowerShell PS C:\heim_workspace> heim new -wWhen prompted I made the following choices:
PowerShell ✔ Select template: · rust-http✔ Package name, (Required) · first✔ Http trigger path /??? , Default · /first✔ Http trigger method POST/GET, (Required) · GETIf you made the same choices as me, you should see the following in your workspace folder:
Directoryfirst/
Directorysrc/
- lib.rs
- .gitignore
- application.toml
- Cargo.toml
- component.toml
- heim.toml
Inspect the workspace file
Section titled “Inspect the workspace file”Open up
heim.tomland inspect it:heim.toml components = ["first"]As you can see there is not a whole lot going on in here. In fact all this does is let the Heim CLI know that there is an application in this location thats a part of the workspace.
Adding more applications to your workspace
Section titled “Adding more applications to your workspace”Lets add a couple of more applications to our workspace, for demonstration purposes I will put one application in a subfolder to show that you can add applications in a nested structure. Applications can be added next to the
heim.tomlfile and nested below it in the file structure:PowerShell PS C:\heim_workspace> heim new -p "subfolder" -w✔ Select template: · rust-http✔ Package name, (Required) · second✔ Http trigger path /??? , Default · /second✔ Http trigger method POST/GET, (Required) · GETPS C:\heim_workspace> heim new -w✔ Select template: · rust-http✔ Package name, (Required) · third✔ Http trigger path /??? , Default · /third✔ Http trigger method POST/GET, (Required) · GETThe first command used the
-pflag to specify a path to create the second application. The second command created the third application next to heim.toml and the first application. If you followed the guide you should now have this file structure:Directoryfirst/
Directorysrc/
- lib.rs
- .gitignore
- application.toml
- Cargo.toml
- component.toml
Directorysubfolder/
Directorysecond/
Directorysrc/
- lib.rs
- .gitignore
- application.toml
- Cargo.toml
- component.toml
Directorythird/
Directorysrc/
- lib.rs
- .gitignore
- application.toml
- Cargo.toml
- component.toml
- heim.toml
Inspect heim.toml again
Section titled “Inspect heim.toml again”If we inspect heim.toml again it should now look like this:
heim.toml components = ["first",'subfolder\second',"third",]As you can see our other two applications have been added with their path relative to the heim.toml file.
Deploying the workspace
Section titled “Deploying the workspace”At this point we have a workspace consisting of three applications. Now lets assume we have made the changes we want to the applications and are ready to deploy all of our applications. First make sure that Heim is running by running the following command:
PowerShell PS C:\heim_workspace> heim startThis starts the runtime to where we are going to deploy our workspace. To deploy the workspace run the following command:
PowerShell PS C:\heim_workspace> heim deploy -wIf everything goes well you should see your three applications being built and deployed to the runtime. If you followed the guide and used the same paths as I did you should now be able to test your applications:
PowerShell curl http://127.0.0.1:3000/firstcurl http://127.0.0.1:3000/secondcurl http://127.0.0.1:3000/thirdAll of these should return 200 and Hello world as the message.
Updating and deploying a single application in your workspace
Section titled “Updating and deploying a single application in your workspace”Lets say you want to update what the third application returns. Open up
C:\heim_workspace\third\src\lib.rsand make the following adjustments:use waki::{handler, ErrorCode, Request, Response};#[handler]fn hello(req: Request) -> Result<Response, ErrorCode> {Response::builder().status_code(200).body("Hello World").body("Hello third application").build()}Now lets deploy just the third application in the workspace by using the
-cflag. Run the following command:PowerShell PS C:\heim_workspace> heim deploy -c thirdNote: The
-cflag targets by name, not path. The name is corresponds to the name found in your component.tomlIf everything went well and you run:
PowerShell curl http://127.0.0.1:3000/thirdYou should receive the response
Hello third application.