Skip to content

Commit

Permalink
Run examples in Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-litvinchik committed Dec 23, 2021
1 parent c2fbecc commit dcb789a
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 5 deletions.
25 changes: 25 additions & 0 deletions Examples/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
49 changes: 49 additions & 0 deletions Examples/GroupDocs.Viewer.Examples.CSharp.Core/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Navigate to 'Examples' folder
# Build container image with `docker build -f "GroupDocs.Viewer.Examples.CSharp.Core\Dockerfile" -t groupdocs-viewer:examples .`
# Run container `docker run -it --rm -v ${pwd}/Output:/app/Output groupdocs-viewer:examples`
# Or run 'Docker' profile in Visual Studio

FROM mcr.microsoft.com/dotnet/runtime:3.1-bionic AS base
WORKDIR /app

# begin install libgdiplus and dependencies
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
dirmngr \
gnupg \
ca-certificates

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
&& echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" >> /etc/apt/sources.list.d/mono-official-stable.list

RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev

# begin ttf-mscorefonts-installer
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections \
&& apt-get update \
&& apt-get install -y \
libfontconfig1 \
xfonts-utils \
ttf-mscorefonts-installer
# end ttf-mscorefonts-installer

FROM mcr.microsoft.com/dotnet/sdk:3.1-bionic AS build
WORKDIR /src
COPY ["GroupDocs.Viewer.Examples.CSharp.Core/GroupDocs.Viewer.Examples.CSharp.Core.csproj", "GroupDocs.Viewer.Examples.CSharp.Core/"]
RUN dotnet restore "GroupDocs.Viewer.Examples.CSharp.Core/GroupDocs.Viewer.Examples.CSharp.Core.csproj"
COPY . .
WORKDIR "/src/GroupDocs.Viewer.Examples.CSharp.Core"
RUN dotnet build "GroupDocs.Viewer.Examples.CSharp.Core.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "GroupDocs.Viewer.Examples.CSharp.Core.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "GroupDocs.Viewer.Examples.CSharp.Core.dll"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<Import Project="..\GroupDocs.Viewer.Examples.CSharp\GroupDocs.Viewer.Examples.CSharp.projitems" Label="Shared" />

<ItemGroup>
<PackageReference Include="GroupDocs.Viewer" Version="21.12.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"GroupDocs.Viewer.Examples.CSharp.Core": {
"commandName": "Project"
},
"Docker": {
"commandName": "Docker"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ static void Main()

Console.WriteLine();
Console.WriteLine("All done.");
Console.ReadKey();
}
}
}
15 changes: 12 additions & 3 deletions Examples/GroupDocs.Viewer.Examples.CSharp/TestFiles.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.IO;
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace GroupDocs.Viewer.Examples.CSharp
{
Expand Down Expand Up @@ -151,7 +153,14 @@ public static class TestFiles
public static string SAMPLE_CHM =>
GetSampleFilePath("sample.chm");

private static string GetSampleFilePath(string filePath) =>
Path.Combine(Utils.SamplesPath, filePath);
private static string GetSampleFilePath(string filePath)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return Path.Combine(Utils.SamplesPath, filePath);

var assembly = System.Reflection.Assembly.GetEntryAssembly();
var entryAssemblyDirectory = Path.GetDirectoryName(assembly.Location);
return Path.Combine(entryAssemblyDirectory, Utils.SamplesPath, filePath);
}
}
}

0 comments on commit dcb789a

Please sign in to comment.