Skip to content

Commit

Permalink
Merge pull request #57 from simongdavies/bindle-template
Browse files Browse the repository at this point in the history
Bindle template
  • Loading branch information
simongdavies authored Sep 22, 2021
2 parents 9f59c27 + ff763ac commit 9db5af0
Show file tree
Hide file tree
Showing 13 changed files with 730 additions and 13 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ To create a ASP.Net Core web application that host a demo WAGI Module:
***Note: nuget.org only contains (pre-)released versions of the packages, to install the latest versions follow the instructions [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry) to set up GitHub packages registry as a source for nuget packages.***

``` Console
dotnet new -i Deislabs.WAGI.Templates::0.8.0-preview
dotnet new -i Deislabs.WAGI.Templates::0.9.0-preview
```

This will add the dotnet wagi templates. To install pre-release versions of the templates the version of the template package must be provided as a suffix to the package name as show above `::0.8.0-preview`.

This will add the dotnet wagi templates. To install pre-release versions of the templates the version of the template package must be provided as a suffix to the package name as show above `::0.9.0-preview`.

``` Console
dotnet new wagi -n hello-wagi
Expand Down
30 changes: 22 additions & 8 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotnet add package Deislabs.WAGI --prerelease
info : Adding PackageReference for package 'Deislabs.WAGI' into project '/tmp/wagiproj/WagiTest.csproj'.
info : Restoring packages for /tmp/wagiproj/WagiTest.csproj...
info : Package 'Deislabs.WAGI' is compatible with all the specified frameworks in project '/tmp/wagiproj/WagiTest.csproj'.
info : PackageReference for package 'Deislabs.WAGI' version '0.8.0-preview' updated in file '/tmp/wagiproj/WagiTest.csproj'.
info : PackageReference for package 'Deislabs.WAGI' version '0.9.0-preview' updated in file '/tmp/wagiproj/WagiTest.csproj'.
info : Committing restore...
info : Writing assets file to disk. Path: /tmp/wagiproj/obj/project.assets.json
log : Restored /tmp/wagiproj/WagiTest.csproj (in 155 ms).
Expand All @@ -28,14 +28,31 @@ Only released versions of the WAGI extension are availble from nuget.org, more r
```console
dotnet add package Deislabs.WAGI --prerelease -s https://nuget.pkg.github.com/deislabs/index.json
```
## Use the wagi-dotnet templates

## Create a new ASP.Net application without using the wagi-donet templates.
### Create a project using a locally available WAGI module

To create a new, run the following command:
```
$ dotnet new wagi
The template "ASP.NET WAGI Web App" was created successfully.
```

This will create an applciation configured to use a sample WAGI module. Run `dotnet new wagi --help` to see the available options for the template.

### Create a project using a WAGI Module stored in a [bindle server](https://github.com/deislabs/bindle).

```
$ dotnet new wagi-bindle --bindle-server-url <url of the bindle server> --bindle-name <name of the bindle>
The template "ASP.NET WAGI Bindle Web App" was created successfully.
```

## Use an ASP.Net application without using the wagi-dotnet templates.

To create a new application, run the following command:

```console
$ dotnet new web
The template "ASP.NET Core Empty" was created successfully.
$ dotnet new wagi
The template "ASP.NET WAGI Web App" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /tmp/wagitest/wagitest.csproj...
Expand All @@ -44,8 +61,6 @@ Running 'dotnet restore' on /tmp/wagitest/wagitest.csproj...
Restore succeeded.
```

## Add Wagi endpoint configuration to your ASP.Net application

### Modify `Startup.cs` to configure endpoints for WAGI modules.

Add a constructor and property to your `Startup.cs` file:
Expand Down Expand Up @@ -91,7 +106,6 @@ to this:

Calling `MapWagiModules()` maps all configured wagi modules.


## What's Next?

Continue on to [Configuring and Running WAGI Modules](configuring_and_running.md) to learn about configuring the application.
2 changes: 1 addition & 1 deletion source/dotnettemplates/template.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Title>Deislabs.WAGI Templates</Title>
<Authors>Simon Davies</Authors>
<Description>Templates to use when creating a WASM/WAGI Applications using Deislabs.WAGI.</Description>
<PackageTags>dotnet-new;templates;WASM;WAGI;WASI;WebAssembly;wasmtime;</PackageTags>
<PackageTags>dotnet-new;templates;WASM;WAGI;WASI;WebAssembly;wasmtime;Bindle</PackageTags>
<TargetFramework>net5.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>CA1014;NU5105;NU5128;0419,0649</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Simon Davies",
"classifications": [
"Web",
"ASP.NET",
"WASM",
"WAGI",
"Bindle"
],
"identity": "Deislabs.WAGI.Templates.BindleWebApp",
"name": "ASP.NET WAGI Bindle Web App",
"shortName": "wagi-bindle",
"description": "Creates a new C# dotnet web app configured with the Deislabs wagi-dotnet extension configured to serve modules hosted in a bindle server.",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "Wagi.Project",
"preferNameDirectory": true,
"symbols": {
"os": {
"type": "bind",
"binding": "OS"
},
"bindle-server-url": {
"type": "parameter",
"isRequired": true,
"replaces": "bindle_server_url",
"description": "This is URL that the bindle server is listening on"
},
"base-path": {
"type": "parameter",
"defaultValue": "/",
"description": "This is the base path in that the server will prepend to the routes defined in the bindle",
"replaces":"base_route"
},
"bindle-name": {
"type": "parameter",
"isRequired": true,
"replaces": "bindle_name",
"description": "This is name of the bindle to deploy."
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net5.0/Wagi.Project.dll",
"args": [ ],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"env":{
"WASMTIME_BACKTRACE_DETAILS":"1",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
{
"name": ".NET Core Launch (listen)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"env":{
"WASMTIME_BACKTRACE_DETAILS":"1",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"program": "${workspaceFolder}/bin/Debug/net5.0/Wagi.Project.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Wagi.Project.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Wagi.Project.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/Wagi.Project.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
26 changes: 26 additions & 0 deletions source/dotnettemplates/templates/wagi_bindle_project/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Wagi.Project
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"profiles": {
"wagi.project": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"WASMTIME_BACKTRACE_DETAILS":1
}
}
}
}
48 changes: 48 additions & 0 deletions source/dotnettemplates/templates/wagi_bindle_project/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Deislabs.Wagi.Extensions;

namespace Wagi.Project
{
public class Startup
{

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{

// HTTP Client is required for wasi_experimentatl_http support.
services.AddHttpClient();
// This adds the services required for using WAGI Modules, by default configuration is expected to be found in a section named Wagi, if the section is renamed then the name should be passed as the second argument.
services.AddWagi(Configuration);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseEndpoints(endpoints =>
{
// This builds the routes defined by Wagi Modules, if configuration changes the endpoint routing will be automatically updated.
endpoints.MapWagiModules();
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Deislabs.WAGI" Version="0.9.0-preview" />
</ItemGroup>

<ItemGroup>
<Content Include=".\modules\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Deislabs.WAGI": "Trace"
}
},
"Wagi": {
"ModulePath": "modules",
"BindleServer": "bindle_server_url",
"Bindles": {
"BindleModule": {
"Name": "bindle_name",
"Route": "base_route"
}
}
}
}
Loading

0 comments on commit 9db5af0

Please sign in to comment.