Skip to content

Workspace

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.

  1. Create a folder where you want to create your workspace, I will be using C:\heim_workspace for this guide:

    PowerShell
    PS C:\> New-Item -ItemType Directory -Name "heim_workspace"; Set-Location "heim_workspace"
  2. Next, we are going to create a new heim template with the addition of the -w flag which will create your application template and a heim.toml file.
    Take note of the -w flag as that is crucial for creating a workspace or adding a new application to your workspace. If you omit -w it will create an application that is not added to your workspace.
    Run the following command:

    PowerShell
    PS C:\heim_workspace> heim new -w

    When 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) · GET

    If 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
  3. Open up heim.toml and 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.

  4. 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.toml file 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) · GET
    PS 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) · GET

    The first command used the -p flag 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
  5. 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.

  6. 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 start

    This 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 -w

    If 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/first
    curl http://127.0.0.1:3000/second
    curl http://127.0.0.1:3000/third

    All of these should return 200 and Hello world as the message.

  7. 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.rs and 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 -c flag. Run the following command:

    PowerShell
    PS C:\heim_workspace> heim deploy -c third

    Note: The -c flag targets by name, not path. The name is corresponds to the name found in your component.toml


    If everything went well and you run:

    PowerShell
    curl http://127.0.0.1:3000/third

    You should receive the response Hello third application.