Skip to content

Commit

Permalink
Azure Pipelines, Docker, and embedded server data. (#543)
Browse files Browse the repository at this point in the history
* Add Azure Pipelines yml.

* Remove Server Installer.

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update signtool.exe

* Update Release Build.yml

* Update Publish.ps1

* Update pipeline and Dockerfile.

* Move docker files.

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Move files.

* Update Dockerfile

* Update Dockerfile

* Create RewritableStream.

* Finish implementation of rewritable stream and embedded data searcher.

* Remove RelayCode.

* Get branding from default org if orgId is missing.

* Update README.md

* Remove AppConstants.ServerUrl.  Fix main module file path.

* Update submodule.

* Extract embedded data in Program.cs.

* Add logging.  Update submodule.

* Remove size block.  BinaryWriter prefixes size.

* Remove unused async

* Update Immense.RemoteControl

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Use UpgradeService for determining out of date clients.
  • Loading branch information
bitbound authored Jan 1, 2023
1 parent c4720ce commit 3f8d63c
Show file tree
Hide file tree
Showing 74 changed files with 4,743 additions and 2,468 deletions.
216 changes: 216 additions & 0 deletions .azure-pipelines/Release Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
name: Release Build
jobs:
- job: Mac_Build
displayName: Mac Build
timeoutInMinutes: 360
pool:
vmImage: macos-latest
steps:

- task: InstallSSHKey@0
inputs:
knownHostsEntry: |
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
sshKeySecureFile: 'pipelines_rsa'

- checkout: self
submodules: recursive
clean: true
fetchTags: false

- task: PowerShell@2
displayName: Add CurrentVersion Variable
inputs:
targetType: inline
script: |
$VersionString = git show -s --format=%ci $(Build.SourceVersion)
$VersionDate = [DateTimeOffset]::Parse($VersionString)
$Year = $VersionDate.Year.ToString()
$Month = $VersionDate.Month.ToString().PadLeft(2, "0")
$Day = $VersionDate.Day.ToString().PadLeft(2, "0")
$Hour = $VersionDate.Hour.ToString().PadLeft(2, "0")
$Minute = $VersionDate.Minute.ToString().PadLeft(2, "0")
$CurrentVersion = "$Year.$Month.$Day.$Hour$Minute"
[System.Console]::WriteLine("##vso[task.setvariable variable=CurrentVersion]$CurrentVersion")
Write-Host "Setting current version to $CurrentVersion."
- task: UseDotNet@2
displayName: Use .NET Core sdk 6.x
inputs:
version: 6.x

- task: DotNetCoreCLI@2
displayName: dotnet publish x64
inputs:
command: publish
publishWebProjects: false
projects: '**/Agent.csproj'
arguments: -c $(BuildConfiguration) -r osx-x64 -o "$(Build.SourcesDirectory)/Agent/bin/publish" /p:Version=$(CurrentVersion) /p:FileVersion=$(CurrentVersion)
zipAfterPublish: false
modifyOutputPath: false

- task: PowerShell@2
displayName: PowerShell Script
inputs:
targetType: inline
script: |
Compress-Archive -Path "$(Build.SourcesDirectory)/Agent/bin/publish/*" -DestinationPath "$(Build.SourcesDirectory)/Agent/bin/Remotely-MacOS-x64.zip" -Force
- task: PublishPipelineArtifact@1
displayName: Publish macOS x64 Agent
inputs:
path: $(Build.SourcesDirectory)/Agent/bin/Remotely-MacOS-x64.zip
artifactName: Mac-x64-Agent

- job: Windows_Build
displayName: Windows Build
timeoutInMinutes: 360
dependsOn: Mac_Build
pool:
vmImage: windows-latest

steps:
- task: InstallSSHKey@0
inputs:
knownHostsEntry: |
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
sshKeySecureFile: 'pipelines_rsa'

- checkout: self
submodules: recursive
clean: true
fetchTags: false

- task: VisualStudioTestPlatformInstaller@1
displayName: Visual Studio Test Platform Installer

- task: NodeTool@0
inputs:
versionSource: 'spec'
versionSpec: '6.x'
checkLatest: true

- task: DownloadPipelineArtifact@2
displayName: Download macOS x64 Agent
inputs:
artifact: Mac-x64-Agent
path: $(Build.SourcesDirectory)\Server\wwwroot\Content\

- task: PowerShell@2
displayName: Add CurrentVersion Variable
inputs:
targetType: inline
script: |
$VersionString = git show -s --format=%ci $(Build.SourceVersion)
$VersionDate = [DateTimeOffset]::Parse($VersionString)
$Year = $VersionDate.Year.ToString()
$Month = $VersionDate.Month.ToString().PadLeft(2, "0")
$Day = $VersionDate.Day.ToString().PadLeft(2, "0")
$Hour = $VersionDate.Hour.ToString().PadLeft(2, "0")
$Minute = $VersionDate.Minute.ToString().PadLeft(2, "0")
$CurrentVersion = "$Year.$Month.$Day.$Hour$Minute"
[System.Console]::WriteLine("##vso[task.setvariable variable=CurrentVersion]$CurrentVersion")
Write-Host "Setting current version to $CurrentVersion."
- task: NuGetToolInstaller@1
displayName: 'Use NuGet'

- task: NuGetCommand@2
displayName: NuGet restore Agent.Installer.Win
inputs:
solution: Agent.Installer.Win/packages.config
packagesDirectory: $(Build.SourcesDirectory)\packages

- task: UseDotNet@2
displayName: Use .NET Core sdk 6.x
inputs:
version: 6.x

- task: DotNetCoreCLI@2
displayName: dotnet restore
inputs:
command: restore
projects: '**/*.csproj'

- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
projects: Tests\Tests.csproj

- task: PowerShell@2
displayName: Create Code Signing Cert
env:
SigningCertBase64: $(CODE_SIGNING_CERT_BASE64)
inputs:
targetType: inline
script: |
if (!$env:SigningCertBase64) {
Write-Host "CODE_SIGNING_CERT_BASE64 variable is empty. Skipping cert creation."
return
}
$CertBytes = [System.Convert]::FromBase64String($env:SigningCertBase64)
[System.IO.File]::WriteAllBytes("$(Build.SourcesDirectory)\Utilities\CodeSigningCert.pfx", $CertBytes)
- task: PowerShell@2
displayName: Publish.ps1
inputs:
filePath: Utilities/Publish.ps1
arguments: -CertificatePath "$(Build.SourcesDirectory)\Utilities\CodeSigningCert.pfx" -CertificatePassword "$(SIGNING_CERT_PASSWORD)" -CurrentVersion "$(CurrentVersion)"
failOnStderr: true
workingDirectory: Utilities

# The MSBuild TypeScript task doesn't compiled the TS
# files without this build step before publishing.
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '$(Build.SourcesDirectory)/Server/Server.csproj'
arguments: '-r linux-x64 -c Release'

- task: DotNetCoreCLI@2
displayName: dotnet publish linux-x64
inputs:
command: publish
publishWebProjects: false
projects: '$(Build.SourcesDirectory)/Server/Server.csproj'
arguments: /p:Version=$(CurrentVersion) /p:FileVersion=$(CurrentVersion) --configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)\linux-x64 --runtime linux-x64


- task: PowerShell@2
displayName: Write Version File
inputs:
targetType: inline
script: |
Write-Host "Adding Version to File: $(CurrentVersion)"
# This is used in the Release.
New-Item -ItemType File -Value "$(CurrentVersion)" -Path "$(build.artifactstagingdirectory)\Version.txt" -Force
- task: PowerShell@2
displayName: Copy Docker Files
inputs:
targetType: inline
script: |
Copy-Item -Path "$(Build.SourcesDirectory)\Server\Dockerfile" -Destination "$(build.artifactstagingdirectory)\Dockerfile"
Copy-Item -Path "$(Build.SourcesDirectory)\Server\DockerMain.sh" -Destination "$(build.artifactstagingdirectory)\DockerMain.sh"
- task: PublishBuildArtifacts@1
displayName: Publish Artifact
condition: succeededOrFailed()
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
ArtifactName: Server
TargetPath: '\\my\share\$(Build.DefinitionName)\$(Build.BuildNumber)'

- task: PostBuildCleanup@3
displayName: Clean Agent Directories
4 changes: 3 additions & 1 deletion Agent.Installer.Win/Agent.Installer.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@
<Link>Models\DeviceSetupOptions.cs</Link>
</Compile>
<Compile Include="Models\BrandingInfo.cs" />
<Compile Include="Models\EmbeddedServerData.cs" />
<Compile Include="Services\EmbeddedServerDataReader.cs" />
<Compile Include="Utilities\CommandLineParser.cs" />
<Compile Include="Utilities\MessageBoxEx.cs" />
<Compile Include="Services\Executor.cs" />
<Compile Include="Services\RelayCommand.cs" />
<Compile Include="Services\InstallerService.cs" />
<Compile Include="Utilities\Logger.cs" />
<Compile Include="Utilities\ProcessEx.cs" />
Expand Down
30 changes: 30 additions & 0 deletions Agent.Installer.Win/Models/EmbeddedServerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Remotely.Agent.Installer.Models
{
[DataContract]
public class EmbeddedServerData
{
public EmbeddedServerData(Uri serverUrl, string organizationId)
{
ServerUrl = serverUrl;
OrganizationId = organizationId;
}

private EmbeddedServerData() { }

public static EmbeddedServerData Empty { get; } = new EmbeddedServerData();

[DataMember]
public string OrganizationId { get; }

[DataMember]
public Uri ServerUrl { get; }
}
}
4 changes: 2 additions & 2 deletions Agent.Installer.Win/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[assembly: AssemblyTitle("Remotely Installer")]
[assembly: AssemblyDescription("An installer for the Remotely service, which provides unattended remote access and remote scripting.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Translucency Software")]
[assembly: AssemblyCompany("Immense Networks")]
[assembly: AssemblyProduct("Remotely Installer")]
[assembly: AssemblyCopyright("Copyright © 2020 Translucency Software")]
[assembly: AssemblyCopyright("Copyright © 2020 Immense Networks")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
76 changes: 76 additions & 0 deletions Agent.Installer.Win/Services/EmbeddedServerDataReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using Remotely.Agent.Installer.Models;
using Remotely.Agent.Installer.Win.Utilities;
using Remotely.Shared;

namespace Remotely.Agent.Installer.Win.Services
{
internal class EmbeddedServerDataReader
{
private readonly JavaScriptSerializer _serializer = new JavaScriptSerializer();

public Task<EmbeddedServerData> TryGetEmbeddedData(string filePath)
{
try
{
if (!File.Exists(filePath))
{
throw new Exception($"File path does not exist: {filePath}");
}

using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var result = SearchBuffer(fs, AppConstants.EmbeddedImmySignature);
if (result == -1)
{
throw new Exception("Signature not found in file buffer.");
}

fs.Seek(result + AppConstants.EmbeddedImmySignature.Length, SeekOrigin.Begin);
using (var reader = new BinaryReader(fs))
{
var serializedData = reader.ReadString();
return Task.FromResult(_serializer.Deserialize<EmbeddedServerData>(serializedData));
}
}
}
catch (Exception ex)
{
Logger.Write(ex);
return Task.FromResult(EmbeddedServerData.Empty);
}
}

private long SearchBuffer(FileStream fileStream, byte[] matchPattern)
{
var matchSize = matchPattern.Length;
var limit = fileStream.Length - matchSize;

for (var i = 0; i <= limit; i++)
{
var k = 0;

for (; k < matchSize; k++)
{
if (matchPattern[k] != fileStream.ReadByte())
{
break;
}
}

if (k == matchSize)
{
return fileStream.Position - matchSize;
}
}
return -1;
}
}
}
Loading

0 comments on commit 3f8d63c

Please sign in to comment.