Skip to content

Commit

Permalink
Merge pull request #6 from RaaLabs/modernize
Browse files Browse the repository at this point in the history
Modernize
  • Loading branch information
rafaelschlatter committed Apr 24, 2023
2 parents b8bf05b + ffa6b45 commit e846752
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 283 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: .NET 5.0
name: .NET

env:
PRERELEASE_BRANCHES: experimental,alpha,beta,rc
DOCKER_HUB_REPO: raaedge.azurecr.io/connectors-opcua
DOCKER_HUB_REPO: ${{ secrets.RAAEDGE_LOGIN_SERVER }}/connectors-opcua
COVERAGE_FOLDER: Coverage

on:
Expand All @@ -23,13 +23,13 @@ jobs:
cascading-release: ${{ steps.context.outputs.cascading-release }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '5.0.x'
dotnet-version: '7.0.x'
- name: Install dependencies
run: dotnet restore --no-cache --verbosity normal
- name: Build
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
docker push ${{ env.DOCKER_HUB_REPO }}:latest
- name: Create GitHub Release
uses: dolittle/github-release-action@v1
uses: dolittle/github-release-action@v2
if: ${{ steps.context.outputs.should-publish == 'true' }}
with:
cascading-release: ${{ steps.context.outputs.cascading-release }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
cascading-release: ${{ steps.context.outputs.cascading-release }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '5.0.x'
dotnet-version: '7.0.x'
- name: Install dependencies
run: dotnet restore --no-cache --verbosity normal
- name: Build
Expand All @@ -36,10 +36,10 @@ jobs:
run: dotnet test --configuration Release --no-build /p:CollectCoverage=true /p:CoverletOutput=${{ github.workspace }}/${{ env.COVERAGE_FOLDER }}/ /p:MergeWith=${{ github.workspace }}/${{ env.COVERAGE_FOLDER }}/coverage/ /p:CoverletOutputFormat=opencover

- name: SonarScanner for .NET Core with pull request decoration support
uses: highbyte/sonarscan-dotnet@2.0
uses: highbyte/sonarscan-dotnet@v2.2.1
with:
sonarProjectKey: RaaLabs_${{ github.event.repository.name }}
sonarProjectName: ${{ github.event.repository.name }}
sonarProjectName: ${{ github.event.repository.name }}
sonarOrganization: raalabs
dotnetTestArguments: --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
sonarBeginArguments: /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" -d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx"
sonarBeginArguments: /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" -d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx"
23 changes: 23 additions & 0 deletions Source/BatchConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) RaaLabs. All rights reserved.
// Licensed under the GPLv2 License. See LICENSE file in the project root for full license information.

using System;
using System.Globalization;
using RaaLabs.Edge.Modules.EdgeHub;

namespace RaaLabs.Edge.Connectors.OPCUA;

/// <summary>
/// Config class for batching settings.
/// </summary>
public class BatchConfiguration : IEdgeHubOutgoingEventBatchConfiguration
{
/// <summary>
/// The batch size.
/// </summary>
public int BatchSize { get; set; } = int.Parse(Environment.GetEnvironmentVariable("EDGEHUB_BATCH_SIZE") ?? "250", CultureInfo.CurrentCulture);
/// <summary>
/// The batch interval in milliseconds.
/// </summary>
public int Interval { get; set; } = int.Parse(Environment.GetEnvironmentVariable("EDGEHUB_BATCH_INTERVAL") ?? "5000", CultureInfo.CurrentCulture);
}
13 changes: 9 additions & 4 deletions Source/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine3.13 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine3.17 AS build-env
WORKDIR /app

VOLUME [ "/app/config" ]
Expand All @@ -9,14 +9,19 @@ WORKDIR /app/Source

RUN dotnet restore --runtime alpine-x64

RUN dotnet publish -c Release -o out --no-restore
RUN dotnet publish -c Release -o out --no-restore \
--runtime alpine-x64 \
--self-contained true \
/p:PublishTrimmed=true \
/p:PublishSingleFile=true

FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine3.17 AS final

FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine3.13
WORKDIR /app
COPY --from=build-env /app/Source/out ./
COPY --from=build-env /app/Source/config ./config

RUN adduser -Ds /bin/sh moduleuser
USER moduleuser

ENTRYPOINT ["dotnet", "RaaLabs.Edge.Connectors.OPCUA.dll"]
ENTRYPOINT ["./RaaLabs.Edge.Connectors.OPCUA"]
36 changes: 36 additions & 0 deletions Source/IMetricsHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) RaaLabs. All rights reserved.
// Licensed under the GPLv2 License. See LICENSE file in the project root for full license information.

using System;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using RaaLabs.Edge.Modules.Diagnostics.Metrics;
using RaaLabs.Edge.Modules.EventHandling.RequestHandling;


namespace RaaLabs.Edge.Connectors.OPCUA;

/// <summary>
/// Interface for registering metrics
/// </summary>
#pragma warning disable CS1591
[Metrics(Prefix = "raaedge")]
[Labels("iothub", "{IOTEDGE_IOTHUBHOSTNAME:env}", "edge_device", "{IOTEDGE_DEVICEID:env}", "edge_module", "{IOTEDGE_MODULEID:env}", "module", "{IOTEDGE_MODULEID:env}", "instance_number", "{InstanceNumber}")]
public interface IMetricsHandler : IMetricsClient, IWithStateFrom<MetricsHandlerState>
{

[Counter(Name = "messages_received_total", Unit = "count", Description = "The total number of messages received", Exported = true)]
public void NumberOfMessagesReceived(long value);

[Counter(Name = "messages_sent_total", Unit = "count", Description = "The total number of messages sent", Exported = true)]
public void NumberOfMessagesSent(long value);
}

[ExcludeFromCodeCoverage]
public class MetricsHandlerState
{
/// <summary>
/// The instance number.
/// </summary>
public string InstanceNumber { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString("x", CultureInfo.InvariantCulture);
}
27 changes: 15 additions & 12 deletions Source/OPCUA.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<TrimMode>partial</TrimMode>
<AssemblyName>RaaLabs.Edge.Connectors.OPCUA</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="AzureIoTEdgeModule" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="RaaLabs.Edge" Version="1.7.2" />
<PackageReference Include="RaaLabs.Edge.Modules.EventHandling" Version="1.7.2" />
<PackageReference Include="RaaLabs.Edge.Modules.Configuration" Version="1.7.2" />
<PackageReference Include="RaaLabs.Edge.Modules.EdgeHub" Version="1.7.2" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua" Version="1.4.368.58" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.4.368.58" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Configuration" Version="1.4.368.58" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Core" Version="1.4.368.58" />
<PackageReference Include="Polly" Version="7.2.2" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="morelinq" Version="3.3.2" />
<TrimmerRootAssembly Include="RaaLabs.Edge.Connectors.OPCUA" preserve="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="RaaLabs.Edge" Version="1.13.6" />
<PackageReference Include="RaaLabs.Edge.Modules.EventHandling" Version="1.13.6" />
<PackageReference Include="RaaLabs.Edge.Modules.Configuration" Version="1.13.6" />
<PackageReference Include="RaaLabs.Edge.Modules.EdgeHub" Version="1.13.6" />
<PackageReference Include="RaaLabs.Edge.Modules.Diagnostics" Version="1.13.6" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua" Version="1.4.371.60" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.4.371.60" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Configuration" Version="1.4.371.60" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Core" Version="1.4.371.60" />
<PackageReference Include="Polly" Version="7.2.3" />
</ItemGroup>
</Project>
Loading

0 comments on commit e846752

Please sign in to comment.