add generator and readme
This commit is contained in:
Родитель
dd2faa9a75
Коммит
8b95904d06
|
@ -0,0 +1,6 @@
|
|||
@VSCode
|
||||
.vscode/
|
||||
|
||||
.yo-rc.json
|
||||
.jsbeautifyrc
|
||||
node_modules/
|
|
@ -0,0 +1 @@
|
|||
Qingqing Sun <qisun@microsoft.com>
|
43
README.md
43
README.md
|
@ -1 +1,42 @@
|
|||
# generator-zure-iot-edge-module
|
||||
# generator-azure-iot-edge-module
|
||||
|
||||
> Scaffolding tool to help setup Azure IoT Edge module development environment.
|
||||
|
||||
```
|
||||
yo auzre-iot-edge-module
|
||||
```
|
||||
|
||||
## Getting started
|
||||
|
||||
If this is the first time you hear about YEOMAN, make sure to take a look at the [official homepage](http://yeoman.io/) first to see what it is about.
|
||||
|
||||
- Make sure you have yo installed: npm install -g yo
|
||||
|
||||
- Install the generaotr: npm install -g generator-azure-iot-edge-module
|
||||
|
||||
- Run **yo azure-iot-edge-module**
|
||||
|
||||
## Containerize the module
|
||||
|
||||
azure-iot-edge-module sets up the Azure IoT Edge Module development environment, generating all necessary files for you.
|
||||
|
||||
To containerize the module, there are several extra steps to do.
|
||||
Navigate to the genarated module folder in the first place.
|
||||
|
||||
### Build your module
|
||||
```
|
||||
dotnet build
|
||||
dotnet publish -f netcoreapp2
|
||||
```
|
||||
### Create and run local docker registry
|
||||
```
|
||||
docker run -d -p 5000:5000 --name registry resigtry:2
|
||||
```
|
||||
### Build docker image for your module
|
||||
```
|
||||
docker build --build-arg EXE_DIR=./bin/Debug/netcoreapp2/publish -t localhost:5000/<moduleName>:latest .
|
||||
```
|
||||
### Push the image to local registry
|
||||
```
|
||||
docker push localhost:5000/<moduleName>
|
||||
```
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
var Generator = require('yeoman-generator');
|
||||
var yosay = require('yosay');
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = class extends Generator {
|
||||
constructor(args, opts) {
|
||||
super(args, opts);
|
||||
this.on('end', function() {
|
||||
process.chdir(this.moduleName);
|
||||
this.spawnCommand('dotnet', ['restore']).on('close', () => {
|
||||
this.log('\r\nAll Set!\r\n');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
prompting() {
|
||||
this.log(yosay('Hey You\r\nWelcome to Azure IoT Edge Modudle Generator'));
|
||||
return this.prompt([{
|
||||
type: 'list',
|
||||
name: 'moduleType',
|
||||
choices: [
|
||||
"Custom Module", "Azure Functions", "Azure Stream Analytics", "Azure Machine Learning"
|
||||
],
|
||||
message: "Which kind of IoT Edge Module would you like to create?"
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
default: 'AzureIoTEdgeModule',
|
||||
message: 'What\'s the name of your module'
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
name: 'architectures',
|
||||
message: 'Select the architecture(s) you want to support, your choice will help generate the corresponding dockerfile(s).',
|
||||
choices: [{
|
||||
name: "Windows-x64"
|
||||
},
|
||||
{
|
||||
name: "Linux-x64"
|
||||
},
|
||||
{
|
||||
name: "Windows-x86"
|
||||
},
|
||||
{
|
||||
name: "Linux-x86"
|
||||
},
|
||||
{
|
||||
name: "ARM-x86"
|
||||
},
|
||||
],
|
||||
validate: function(answer) {
|
||||
if (answer.length < 1) {
|
||||
return 'You must select at least one architecture.';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'test',
|
||||
message: 'Would you like to add unit test?'
|
||||
}
|
||||
]).then((answers) => {
|
||||
this.log('Creating files...');
|
||||
this.moduleName = answers.name;
|
||||
if (answers.test) {
|
||||
fs.mkdir(this.destinationPath(answers.name + 'Test'));
|
||||
}
|
||||
this.fs.copyTpl(this.templatePath('Project'), this.destinationPath(answers.name + '/' + answers.name + '.csproj'));
|
||||
this.fs.copyTpl(this.templatePath('Program'), this.destinationPath(answers.name + '/Program.cs'), {
|
||||
ModuleName: answers.name
|
||||
});
|
||||
answers.architectures.forEach((architecture, index) => {
|
||||
this.fs.copyTpl(this.templatePath('DockerFile'), this.destinationPath(answers.name + '/Docker/' + architecture + '/DockerFile'), {
|
||||
DLLName: answers.name + '.dll'
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
FROM microsoft/dotnet:2.0.0-preview2-runtime-stretch
|
||||
ARG EXE_DIR=.
|
||||
WORKDIR /app
|
||||
COPY $EXE_DIR/ ./
|
||||
CMD ["dotnet", "<%= DLLName %>"]
|
|
@ -0,0 +1,21 @@
|
|||
namespace <%= ModuleName %>
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args) {}
|
||||
}
|
||||
/// <summary>
|
||||
/// This class contains the configuration for this module.
|
||||
/// </summary>
|
||||
class ModuleConfig
|
||||
{
|
||||
public ModuleConfig() {}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The class containing the expected schema for the body of the incoming message.
|
||||
/// </summary>
|
||||
class MessageBody
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.4.0-preview.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "generator-azure-iot-edge-module",
|
||||
"version": "1.0.0",
|
||||
"description": "Scaffolding tool to help setup Azure IoT Edge module development environment.",
|
||||
"files": [
|
||||
"app"
|
||||
],
|
||||
"keywords": [
|
||||
"yeoman-generator", "Azure IoT Edge", "IoT", "Azure"
|
||||
],
|
||||
"dependencies": {
|
||||
"fs": "0.0.1-security",
|
||||
"yeoman-generator": "^1.1.1",
|
||||
"yosay": "^2.0.1"
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче