Skip to content

Commit

Permalink
Personal/sowu/update oras tool (#178)
Browse files Browse the repository at this point in the history
* delete build in oras tool

* update nuspec

* update csproj

Co-authored-by: Qiwei Jin <[email protected]>
  • Loading branch information
sowu880 and qiwjin authored Jan 13, 2021
1 parent 65fc48f commit 3376786
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 60 deletions.
9 changes: 7 additions & 2 deletions release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ stages:
includeRootFolder: false
archiveType: 'tar'
tarCompression: 'gz'
archiveFile: '$(Build.SourcesDirectory)/data/Templates/DefaultTemplates.tar.gz'
archiveFile: '$(Build.SourcesDirectory)/data/Templates/Hl7v2DefaultTemplates.tar.gz'

- task: CopyFiles@2
displayName: 'copy DefaultTemplates to artifacts'
Expand Down Expand Up @@ -171,6 +171,11 @@ stages:
artifactName: FhirConverterBuild
downloadPath: $(System.DefaultWorkingDirectory)
- script: |
curl -LO https://github.com/deislabs/oras/releases/download/v0.8.1/oras_0.8.1_linux_amd64.tar.gz
mkdir -p oras-install/
tar -zxf oras_0.8.1_*.tar.gz -C oras-install/
mv oras-install/oras /usr/local/bin/
rm -rf oras_0.8.1_*.tar.gz oras-install/
docker run --rm -d -p 5000:5000 --name registry registry:2
displayName: start registry
- script: |
Expand Down Expand Up @@ -207,7 +212,7 @@ stages:
tag: v$(major).$(minor).$(bulidnum)
assets: |
$(System.DefaultWorkingDirectory)/FhirConverterBuild/bin/**
$(System.DefaultWorkingDirectory)/FhirConverterBuild/data/Templates/DefaultTemplates.tar.gz
$(System.DefaultWorkingDirectory)/FhirConverterBuild/data/Templates/Hl7v2DefaultTemplates.tar.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using EnsureThat;
using Microsoft.Health.Fhir.TemplateManagement.Exceptions;
Expand Down Expand Up @@ -57,24 +56,9 @@ public static async Task OrasExecutionAsync(string command, string orasWorkingDi
{
TaskCompletionSource<bool> eventHandled = new TaskCompletionSource<bool>();

string orasFileName;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
orasFileName = Constants.OrasFileForWindows;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
orasFileName = Constants.OrasFileForLinux;
AddOrasFileExecutionPermission();
}
else
{
throw new TemplateManagementException("Operation system is not supported");
}

Process process = new Process
{
StartInfo = new ProcessStartInfo(orasFileName),
StartInfo = new ProcessStartInfo(Constants.OrasFile),
};

process.StartInfo.Arguments = command;
Expand Down Expand Up @@ -108,26 +92,5 @@ public static async Task OrasExecutionAsync(string command, string orasWorkingDi
throw new OrasException(TemplateManagementErrorCode.OrasTimeOut, "Oras request timeout");
}
}

public static void AddOrasFileExecutionPermission()
{
var command = $"chmod +x {Constants.OrasFileForLinux}";

using var process = new Process
{
StartInfo = new ProcessStartInfo
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "/bin/bash",
Arguments = $"-c \"{command}\"",
},
};

process.Start();
process.WaitForExit();
}
}
}
6 changes: 2 additions & 4 deletions src/Microsoft.Health.Fhir.TemplateManagement/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Health.Fhir.TemplateManagement
{
internal static class Constants
{
internal const string DefaultTemplatePath = "DefaultTemplates.tar.gz";
internal const string DefaultTemplatePath = "Hl7v2DefaultTemplates.tar.gz";

// Accept meidia type for manifest.
internal const string MediatypeV2Manifest = "application/vnd.docker.distribution.manifest.v2+json";
Expand All @@ -28,8 +28,6 @@ internal static class Constants

internal const int TimeOutMilliseconds = 30000;

internal const string OrasFileForWindows = "oras.exe";

internal const string OrasFileForLinux = "oras-linux";
internal const string OrasFile = "oras";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
</group>
</dependencies>
<contentFiles>
<files include="any/netcoreapp3.1/DefaultTemplates.tar.gz" buildAction="EmbeddedResource"/>
<files include="any/netcoreapp3.1/Hl7v2DefaultTemplates.tar.gz" buildAction="EmbeddedResource"/>
</contentFiles>
</metadata>
<files>
<file src="bin\Release\netcoreapp3.1\Microsoft.Health.Fhir.Liquid.Converter.dll" target="lib\netcoreapp3.1" />
<file src="bin\Release\netcoreapp3.1\Microsoft.Health.Fhir.TemplateManagement.dll" target="lib\netcoreapp3.1" />
<file src="..\..\data\Templates\DefaultTemplates.tar.gz" target="contentFiles\any\netcoreapp3.1" />
<file src="..\..\data\Templates\Hl7v2DefaultTemplates.tar.gz" target="contentFiles\any\netcoreapp3.1" />
</files>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>true</IsPackable>
<NuspecFile>Microsoft.Health.Fhir.Liquid.Converter.nuspec</NuspecFile>
<OrasWinUrl>https://github.com/deislabs/oras/releases/download/v0.8.1/oras_0.8.1_windows_amd64.tar.gz</OrasWinUrl>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\tool\oras-linux" Link="oras-linux">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\tool\oras.exe" Link="oras.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Ensure.That" Version="9.2.0" />
Expand All @@ -35,19 +27,25 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="../../bin/DefaultTemplates.tar.gz">
<Link>DefaultTemplates.tar.gz</Link>
<EmbeddedResource Include="../../bin/Hl7v2DefaultTemplates.tar.gz">
<Link>Hl7v2DefaultTemplates.tar.gz</Link>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<None Update="oras-linux">
<None Update="oras.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="mkdir ..\..\bin &amp; tar -zcvf ../../bin/DefaultTemplates.tar.gz -C ../../data/Templates/Hl7v2 ." />
<Exec Command="mkdir ..\..\bin &amp; tar -zcvf ../../bin/Hl7v2DefaultTemplates.tar.gz -C ../../data/Templates/Hl7v2 ." />
</Target>

<Target Name="DownloadOrasFile" BeforeTargets="Build">
<DownloadFile SourceUrl="$(OrasWinUrl)" DestinationFolder="../../bin">
<Output TaskParameter="DownloadedFile" ItemName="Content" />
</DownloadFile>
<Exec Command="tar -xvf ..\..\bin\oras_0.8.1_windows_amd64.tar.gz -C ..\..\bin &amp; copy ..\..\bin\oras.exe ." />
</Target>

</Project>
Binary file removed tool/oras-linux
Binary file not shown.
Binary file removed tool/oras.exe
Binary file not shown.

0 comments on commit 3376786

Please sign in to comment.