forked from criticalmanufacturing/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Maia
authored and
Jonas Maia
committed
May 2, 2024
1 parent
6eddbb5
commit 254633f
Showing
14 changed files
with
351 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions; | ||
using Cmf.CLI.Core.Attributes; | ||
using Cmf.CLI.Core.Enums; | ||
using Cmf.CLI.Core.Objects; | ||
using Cmf.CLI.Utilities; | ||
|
||
namespace Cmf.CLI.Commands.New | ||
{ | ||
/// <summary> | ||
/// Generates the Grafana folder structure | ||
/// </summary> | ||
[CmfCommand(Name = "grafana", Id = "new_grafana", ParentId = "new")] | ||
public class GrafanaCommand : LayerTemplateCommand | ||
{ | ||
/// <summary> | ||
/// constructor | ||
/// </summary> | ||
public GrafanaCommand() : base("grafana", PackageType.Grafana) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// constructor | ||
/// </summary> | ||
/// <param name="fileSystem"></param> | ||
public GrafanaCommand(IFileSystem fileSystem) : base("grafana", PackageType.Grafana, fileSystem) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override List<string> GenerateArgs(IDirectoryInfo projectRoot, IDirectoryInfo workingDir, List<string> args) | ||
{ | ||
if (ExecutionContext.Instance.ProjectConfig.MESVersion.Major < 10) | ||
{ | ||
throw new CliException("Version unsupported, available in MES >= 10"); | ||
} | ||
|
||
var isRepositoryType = ExecutionContext.Instance.ProjectConfig.RepositoryType == RepositoryType.App; | ||
|
||
args.AddRange(new[] | ||
{ | ||
"--app", isRepositoryType.ToString(), | ||
}); | ||
return args; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions; | ||
using System.Linq; | ||
using Cmf.CLI.Builders; | ||
using Cmf.CLI.Core.Enums; | ||
using Cmf.CLI.Core.Objects; | ||
|
||
namespace Cmf.CLI.Handlers | ||
{ | ||
/// <summary> | ||
/// Grafana package type handler. | ||
/// </summary> | ||
/// <seealso cref="PackageTypeHandler" /> | ||
public class GrafanaPackageTypeHandler : PackageTypeHandler | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GrafanaPackageTypeHandler" /> class. | ||
/// </summary> | ||
/// <param name="cmfPackage">The CMF package.</param> | ||
public GrafanaPackageTypeHandler(CmfPackage cmfPackage) : base(cmfPackage) | ||
{ | ||
cmfPackage.SetDefaultValues | ||
( | ||
targetLayer: "Grafana", | ||
isInstallable: true, | ||
isUniqueInstall: true, | ||
steps: new List<Step>() | ||
{ | ||
new(StepType.DeployFiles) | ||
{ | ||
ContentPath = "**/**" | ||
}, | ||
} | ||
); | ||
|
||
IEnumerable<IBuildCommand> buildSteps = cmfPackage.BuildSteps?.Select(pbs => new SingleStepCommand() { BuildStep = pbs } as IBuildCommand); | ||
|
||
if (buildSteps != null && buildSteps.Any()) { | ||
BuildSteps = buildSteps.ToArray(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Pack a Data package | ||
/// </summary> | ||
/// <param name="packageOutputDir">source directory</param> | ||
/// <param name="outputDir">output directory</param> | ||
public override void Pack(IDirectoryInfo packageOutputDir, IDirectoryInfo outputDir) | ||
{ | ||
const string readmeFilename = "README.md"; | ||
|
||
if (outputDir.FileSystem.File.Exists(readmeFilename)) | ||
{ | ||
outputDir.FileSystem.File.Delete(readmeFilename); | ||
} | ||
|
||
base.Pack(packageOutputDir, outputDir); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
cmf-cli/resources/template_feed/grafana/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Critical Manufacturing", | ||
"classifications": [ | ||
"cli" | ||
], | ||
"description": "Generate a new Grafana package", | ||
"name": "Grafana Package", | ||
"identity": "cmf-cli.new.grafana", | ||
"groupIdentity": "cmf-cli.new.grafana", | ||
"shortName": "grafana", | ||
"tags": { | ||
"language": "C#", | ||
// Specify that this template is in C#. | ||
"type": "project" | ||
}, | ||
"sourceName": "Grafana.Package", | ||
"preferNameDirectory": true, | ||
"symbols": { | ||
"name": { | ||
"type": "parameter", | ||
"datatype": "string", | ||
"description": "The custom package name", | ||
"displayName": "Package Name", | ||
"replaces": "<%= $CLI_PARAM_CustomPackageName %>" | ||
}, | ||
"packageVersion": { | ||
"type": "parameter", | ||
"datatype": "string", | ||
"description": "The custom package version", | ||
"displayName": "Package Version", | ||
"replaces": "<%= $CLI_PARAM_CustomPackageVersion %>", | ||
"fileRename": "%version%" | ||
}, | ||
"Tenant": { | ||
"type": "parameter", | ||
"datatype": "string", | ||
"replaces": "<%= $CLI_PARAM_Tenant %>", | ||
"fileRename": "%Tenant%" | ||
}, | ||
"app": { | ||
"type": "parameter", | ||
"datatype": "bool", | ||
"defaultValue": "False", | ||
"description": "Indicates that repository type is app if true" | ||
} | ||
} | ||
} |
Empty file.
9 changes: 9 additions & 0 deletions
9
cmf-cli/resources/template_feed/grafana/Grafana.Package/%version%/dashboards/dashboards.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: 1 | ||
|
||
providers: | ||
- name: Default | ||
folder: <%= $CLI_PARAM_Tenant %> | ||
type: file | ||
options: | ||
path: /etc/grafana/provisioning/dashboards | ||
foldersFromFilesStructure: true |
11 changes: 11 additions & 0 deletions
11
...li/resources/template_feed/grafana/Grafana.Package/%version%/datasources/datasources.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: 1 | ||
|
||
datasources: | ||
#if (app) | ||
- name: CMF gRPC Datasource | ||
type: criticalmanufacturing-grpc-datasource | ||
jsonData: | ||
endpoint: #container-name:port# | ||
#else | ||
~ | ||
#endif |
31 changes: 31 additions & 0 deletions
31
cmf-cli/resources/template_feed/grafana/Grafana.Package/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Grafana custom Package Datasources | ||
|
||
If you want to know more about data sources in general [Official Documentation here!](https://grafana.com/docs/grafana/latest/datasources/) | ||
|
||
This information is for local development only! | ||
|
||
In order to create custom data sources or dashboards you should put them in the respective folders. | ||
|
||
If you are building an app and want to use the gRPC Data Manager data source you can import the following configuration into your local grafana instance: | ||
|
||
``` json | ||
{ | ||
"id": 1, | ||
"uid": "KHanA1bVk", | ||
"orgId": 1, | ||
"name": "CMF gRPC Datasource", | ||
"type": "criticalmanufacturing-grpc-datasource", | ||
"typeName": "CMF gRPC Datasource", | ||
"typeLogoUrl": "public/plugins/criticalmanufacturing-grpc-datasource/img/logo.svg", | ||
"access": "proxy", | ||
"url": "", | ||
"user": "", | ||
"database": "", | ||
"basicAuth": false, | ||
"isDefault": false, | ||
"jsonData": { | ||
"endpoint": "datamanager.resourcemonitordevos1.apps.vmrhosdsclt1.cmf.criticalmanufacturing.com:80" | ||
}, | ||
"readOnly": false | ||
} | ||
``` |
15 changes: 15 additions & 0 deletions
15
cmf-cli/resources/template_feed/grafana/Grafana.Package/cmfpackage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"packageId": "<%= $CLI_PARAM_CustomPackageName %>", | ||
"version": "<%= $CLI_PARAM_CustomPackageVersion %>", | ||
"description": "Cmf Custom <%= $CLI_PARAM_Tenant %> <%= $CLI_PARAM_CustomPackageName %> Package", | ||
"packageType": "Grafana", | ||
"contentToPack": [ | ||
{ | ||
"source": "$(version)/*", | ||
"target": "", | ||
"ignoreFiles": [ | ||
"../.cmfpackageignore" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.