From c11d8e8180748c77d75f81cef1afd6998017b5fa Mon Sep 17 00:00:00 2001 From: phil-harmoniq Date: Tue, 5 Sep 2017 17:24:55 -0400 Subject: [PATCH 1/8] Fixed error checking for csproj --- Program.cs | 127 ++++++++++++++++++++++----------------------- README.md | 4 +- netpkg-tool.csproj | 2 +- 3 files changed, 65 insertions(+), 68 deletions(-) diff --git a/Program.cs b/Program.cs index ea38f6e..22873ba 100644 --- a/Program.cs +++ b/Program.cs @@ -4,25 +4,23 @@ using System.Xml; using System.Reflection; using System.Diagnostics; -using System.Runtime.InteropServices; -using Shell.NET; using ConsoleColors; class Program { static Assembly tool = Assembly.GetExecutingAssembly(); - static string toolName = tool.GetName().Name; - static string toolVersion = FileVersionInfo.GetVersionInfo(tool.Location).ProductVersion; - static string home = Environment.GetEnvironmentVariable("HOME"); - static string configDir = $"{home}/.netpkg-tool"; - static int width = 64; - static Bash bash = new Bash(); - static string csproj; - static string projectDir; - static string destination; + static string ToolName = tool.GetName().Name; + static string ToolVersion = FileVersionInfo.GetVersionInfo(tool.Location).ProductVersion; + static string Home = Environment.GetEnvironmentVariable("HOME"); + static string configDir = $"{Home}/.netpkg-tool"; + static int Width = 64; + static Shell.NET.Bash Bash = new Shell.NET.Bash(); + static string Csproj; + static string ProjectDir; + static string Destination; static string DllName; static string AppName; - static string dotNetVersion; + static string DotNetVersion; static string Here = AppDomain.CurrentDomain.BaseDirectory; static string[] Args; @@ -31,7 +29,6 @@ class Program static bool CustomAppName = false; static bool SelfContainedDeployment = false; static bool KeepTempFiles = false; - static void Main(string[] args) { @@ -39,27 +36,27 @@ static void Main(string[] args) ParseArgs(args); CheckPaths(args); FindCsproj(args[0]); - SayTask(projectDir, $"{destination}/{AppName}"); + SayTask(ProjectDir, $"{Destination}/{AppName}"); if (!SkipRestore) RestoreProject(); ComileProject(); TransferFiles(); RunAppImageTool(); if (!KeepTempFiles) DeleteTempFiles(); - SayFinished($"New AppImage created at {destination}/{AppName}"); + SayFinished($"New AppImage created at {Destination}/{AppName}"); SayBye(); } static void CheckPaths(string[] args) { if (args.Length < 2 || !Directory.Exists(args[0]) && !Directory.Exists(args[1])) - ExitWithError("You must specify a valid .NET project AND destination folder.\n", 1); + ExitWithError("You must specify a valid .NET project AND Destination folder.", 6); if (Directory.Exists(args[0]) && !Directory.Exists(args[1])) - ExitWithError($"{args[1]} is not a valid folder\n", 2); + ExitWithError($"{args[1]} is not a valid folder", 7); if (!Directory.Exists(args[0]) && Directory.Exists(args[1])) - ExitWithError($"{args[0]} is not a valid folder\n", 3); + ExitWithError($"{args[0]} is not a valid folder", 8); - projectDir = GetRelativePath(args[0]); - destination = GetRelativePath(args[1]); + ProjectDir = GetRelativePath(args[0]); + Destination = GetRelativePath(args[1]); } static void ParseArgs(string[] args) @@ -104,18 +101,18 @@ static void ParseArgs(string[] args) static void FindCsproj(string project) { - var location = bash.Command($"find {project} -maxdepth 1 -name '*.csproj'", redirect: true).Lines; + var location = Bash.Command($"find {project} -maxdepth 1 -name '*.csproj'", redirect: true).Lines; - if (location.Length < 1) - ExitWithError($"No .csproj found in {GetRelativePath(project)}\n", 10); + if (location == null || location[0] == "") + ExitWithError($"No .csproj found in {GetRelativePath(project)}", 10); if (location.Length > 1) - ExitWithError($"More than one .csproj found in {GetRelativePath(project)}\n", 11); + ExitWithError($"More than one .csproj found in {GetRelativePath(project)}", 11); var folderSplit = location[0].Split('/'); - csproj = folderSplit[folderSplit.Length - 1]; - projectDir = GetRelativePath(project); - dotNetVersion = GetCoreVersion(); - var nameSplit = csproj.Split('.'); + Csproj = folderSplit[folderSplit.Length - 1]; + ProjectDir = GetRelativePath(project); + DotNetVersion = GetCoreVersion(); + var nameSplit = Csproj.Split('.'); DllName = string.Join('.', nameSplit.Take(nameSplit.Length - 1)); if (!CustomAppName) @@ -131,7 +128,7 @@ static void FindCsproj(string project) static string GetCoreVersion() { - var path = GetAbsolutePath($"{projectDir}/{csproj}"); + var path = GetAbsolutePath($"{ProjectDir}/{Csproj}"); var node = "/Project/PropertyGroup/TargetFramework"; var xml = new XmlDocument(); xml.LoadXml(File.ReadAllText(path)); @@ -140,7 +137,7 @@ static string GetCoreVersion() static bool SingleRuntimeIdentifier() { - var path = GetAbsolutePath($"{projectDir}/{csproj}"); + var path = GetAbsolutePath($"{ProjectDir}/{Csproj}"); var node = "/Project/PropertyGroup/RuntimeIdentifier"; var xml = new XmlDocument(); xml.LoadXml(File.ReadAllText(path)); @@ -152,12 +149,12 @@ static void RestoreProject() if (Verbose) { Console.WriteLine("Restoring .NET Core project dependencies..."); - bash.Command($"cd {projectDir} && dotnet restore", redirect: false); + Bash.Command($"cd {ProjectDir} && dotnet restore", redirect: false); } else { Console.Write("Restoring .NET Core project dependencies..."); - bash.Command($"cd {projectDir} && dotnet restore", redirect: true); + Bash.Command($"cd {ProjectDir} && dotnet restore", redirect: true); } CheckCommandOutput(errorCode: 20); @@ -168,19 +165,19 @@ static void ComileProject() string cmd; if (SelfContainedDeployment) - cmd = $"cd {projectDir} && dotnet publish -c Release -r linux-x64 --no-restore"; + cmd = $"cd {ProjectDir} && dotnet publish -c Release -r linux-x64 --no-restore"; else - cmd = $"cd {projectDir} && dotnet publish -c Release --no-restore"; + cmd = $"cd {ProjectDir} && dotnet publish -c Release --no-restore"; if (Verbose) { Console.WriteLine("Compiling .NET Core project..."); - bash.Command(cmd, redirect: false); + Bash.Command(cmd, redirect: false); } else { Console.Write("Compiling .NET Core project..."); - bash.Command(cmd, redirect: true); + Bash.Command(cmd, redirect: true); } CheckCommandOutput(errorCode: 21); @@ -192,29 +189,29 @@ static void TransferFiles() string cmd; if (SelfContainedDeployment) - cmd = $"{path} {projectDir} {DllName} {AppName} {dotNetVersion} {toolVersion} true"; + cmd = $"{path} {ProjectDir} {DllName} {AppName} {DotNetVersion} {ToolVersion} true"; else - cmd = $"{path} {projectDir} {DllName} {AppName} {dotNetVersion} {toolVersion}"; + cmd = $"{path} {ProjectDir} {DllName} {AppName} {DotNetVersion} {ToolVersion}"; Console.Write($"Creating app directory at /tmp/{AppName}.temp..."); - bash.Command(cmd, redirect: true); + Bash.Command(cmd, redirect: true); CheckCommandOutput(errorCode: 22); } static void RunAppImageTool() { var appimgtool = $"{Here}/appimagetool/AppRun"; - var cmd = $"{appimgtool} -n /tmp/{AppName}.temp {destination}/{AppName}"; + var cmd = $"{appimgtool} -n /tmp/{AppName}.temp {Destination}/{AppName}"; if (Verbose) { Console.WriteLine($"Compressing app directory into an AppImage..."); - bash.Command(cmd, redirect: false); + Bash.Command(cmd, redirect: false); } else { Console.Write($"Compressing app directory into an AppImage..."); - bash.Command(cmd, redirect: true); + Bash.Command(cmd, redirect: true); } CheckCommandOutput(errorCode: 23); @@ -223,14 +220,14 @@ static void RunAppImageTool() static void DeleteTempFiles() { Console.Write("Deleting temporary files..."); - bash.Rm($"/tmp/{DllName}.temp", "-rf"); + Bash.Rm($"/tmp/{DllName}.temp", "-rf"); CheckCommandOutput(24); } static void SayHello() { - var title = $" {toolName} v{toolVersion} "; - var newWidth = width - title.Length; + var title = $" {ToolName} v{ToolVersion} "; + var newWidth = Width - title.Length; var leftBar = new String('-', newWidth / 2); string rightBar; @@ -251,15 +248,15 @@ static void HelpMenu() + $"[{Frmt.Underline}Destination{Reset.Code}] " + $"[{Frmt.Underline}Flags{Reset.Code}]\n\n" + $" {Frmt.Bold}{Clr.Cyan}Flags:{Reset.Code}\n" - + $" --verbose or -v: Verbose output\n" - + $" --compile or -c: Skip restoring dependencies\n" - + $" --name or -n: Set ouput file to a custom name\n" - + $" --scd or -s: Self-Contained Deployment (SCD)\n" + + @" --verbose or -v: Verbose output\n" + + @" --compile or -c: Skip restoring dependencies\n" + + @" --name or -n: Set ouput file to a custom name\n" + + @" --scd or -s: Self-Contained Deployment (SCD)\n" + @" --keep or -k: Keep /tmp/{AppName}.temp directory\n" - + $" --help or -h: Help menu (this page)\n\n" - + $" More information & source code available on github:\n" - + $" https://github.com/phil-harmoniq/netpkg-tool\n" - + $" Copyright (c) 2017 - MIT License\n" + + @" --help or -h: Help menu (this page)\n\n" + + @" More information & source code available on github:\n" + + @" https://github.com/phil-harmoniq/netpkg-tool\n" + + @" Copyright (c) 2017 - MIT License\n" ); SayBye(); Environment.Exit(0); @@ -268,7 +265,7 @@ static void HelpMenu() static void ClearLogs() { Console.Write($"Clear log at {GetRelativePath(configDir)}/error.log"); - bash.Rm($"{configDir}/error.log", "-f"); + Bash.Rm($"{configDir}/error.log", "-f"); CheckCommandOutput(errorCode: 5); SayBye(); Environment.Exit(0); @@ -299,39 +296,39 @@ static void WriteToErrorLog(string message, int code) var now = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); var dir = Directory.GetCurrentDirectory(); - tw.WriteLine($"{new string('-', width)}"); + tw.WriteLine($"{new string('-', Width)}"); tw.WriteLine($"{GetRelativePath(dir)}$ netpkg-tool {string.Join(' ', Args)}"); tw.WriteLine($"Errored with code {code} - ({now}):\n"); tw.WriteLine(message.TrimEnd('\n')); - tw.WriteLine($"{new string('-', width)}"); + tw.WriteLine($"{new string('-', Width)}"); } } /// Desired error code if the command didn't run properly static void CheckCommandOutput(int errorCode = 1) { - if (bash.ExitCode != 0) + if (Bash.ExitCode != 0) { SayFail(); - if (string.IsNullOrEmpty(bash.ErrorMsg)) - ExitWithError(bash.Output, errorCode); + if (string.IsNullOrEmpty(Bash.ErrorMsg)) + ExitWithError(Bash.Output, errorCode); else - ExitWithError(bash.ErrorMsg, errorCode); + ExitWithError(Bash.ErrorMsg, errorCode); } SayPass(); } static string GetRelativePath(string path) => - bash.Command($"cd {path} && dirs -0", redirect: true).Lines[0]; + Bash.Command($"cd {path} && dirs -0", redirect: true).Output; static string GetAbsolutePath(string path) => - bash.Command($"readlink -f {path}", redirect: true).Lines[0]; + Bash.Command($"readlink -f {path}", redirect: true).Output; static void SayBye() => - Console.WriteLine(new String('-', width) + "\n"); + Console.WriteLine(new String('-', Width) + "\n"); - static void SayTask(string project, string destination) => - Printer.WriteLine($"{Clr.Cyan}{project} => {destination}{Clr.Default}"); + static void SayTask(string project, string Destination) => + Printer.WriteLine($"{Clr.Cyan}{project} => {Destination}{Clr.Default}"); static void SayFinished(string message) => Printer.WriteLine($"{Clr.Green}{message}{Clr.Default}"); diff --git a/README.md b/README.md index fe32b7b..2ba5dea 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Pre-packaged versions of *netpkg-tool* are available from the [releases tab](https://github.com/phil-harmoniq/netpkg-tool/releases): ```bash -# Github releases are tagged with their version (ex: 0.3.6) -wget https://github.com/phil-harmoniq/netpkg-tool/releases/download/0.3.6/netpkg-tool +# Github releases are tagged with their version (ex: 0.3.8) +wget https://github.com/phil-harmoniq/netpkg-tool/releases/download/0.3.8/netpkg-tool chmod a+x ./netpkg-tool # Place netpkg-tool somewhere on your $PATH (Optional) diff --git a/netpkg-tool.csproj b/netpkg-tool.csproj index e0d4d79..8eb84ac 100644 --- a/netpkg-tool.csproj +++ b/netpkg-tool.csproj @@ -7,7 +7,7 @@ Phil Hawkins Exe netcoreapp2.0 - 0.3.7 + 0.3.8 alpha Bundle .NET Core applications into convenient Linux binaries using appimagetool MIT From 7d49a70370b0648b7a22d901f5aade6761a3abb3 Mon Sep 17 00:00:00 2001 From: phil-harmoniq Date: Tue, 5 Sep 2017 18:10:02 -0400 Subject: [PATCH 2/8] See if autmoated build is properly tagged now --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ba5dea..802fa50 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Pre-packaged versions of *netpkg-tool* are available from the [releases tab](https://github.com/phil-harmoniq/netpkg-tool/releases): ```bash -# Github releases are tagged with their version (ex: 0.3.8) -wget https://github.com/phil-harmoniq/netpkg-tool/releases/download/0.3.8/netpkg-tool +# Github releases are tagged with their version (ex: 0.3.7) +wget https://github.com/phil-harmoniq/netpkg-tool/releases/download/0.3.7/netpkg-tool chmod a+x ./netpkg-tool # Place netpkg-tool somewhere on your $PATH (Optional) From be68f6bf76fdaa1b89b6d17d86c6185f594d47f9 Mon Sep 17 00:00:00 2001 From: phil-harmoniq Date: Tue, 5 Sep 2017 18:32:52 -0400 Subject: [PATCH 3/8] Where are the files? --- docker/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index ab5de5e..3d5e96e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,6 +13,8 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ libglib2.0-0 +RUN ls -lhaF + WORKDIR /dotnetapp # Make use of Docker layering: cached layer COPY netpkg-tool.csproj . From a90fc2ae58ede2b004c0e74e492c166c6ab02288 Mon Sep 17 00:00:00 2001 From: phil-harmoniq Date: Tue, 5 Sep 2017 18:47:24 -0400 Subject: [PATCH 4/8] Wtf... --- docker/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 3d5e96e..079de74 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -16,8 +16,10 @@ RUN apt-get update \ RUN ls -lhaF WORKDIR /dotnetapp +RUN ls -lhaF # Make use of Docker layering: cached layer -COPY netpkg-tool.csproj . +COPY ./netpkg-tool.csproj . +RUN ls -lhaF RUN dotnet restore netpkg-tool.csproj # Make use of Docker layering: new layer COPY . . From edbf5ec8f44c21b88221033ba83ad30c17d6976b Mon Sep 17 00:00:00 2001 From: phil-harmoniq Date: Tue, 5 Sep 2017 19:13:15 -0400 Subject: [PATCH 5/8] Restore Dockerfile back to normal --- docker/Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 079de74..5aee150 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,13 +13,9 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ libglib2.0-0 -RUN ls -lhaF - WORKDIR /dotnetapp -RUN ls -lhaF # Make use of Docker layering: cached layer COPY ./netpkg-tool.csproj . -RUN ls -lhaF RUN dotnet restore netpkg-tool.csproj # Make use of Docker layering: new layer COPY . . From cd8a489a0c9961fb565a1a71f5b941df6cfc3ba3 Mon Sep 17 00:00:00 2001 From: phil-harmoniq Date: Tue, 5 Sep 2017 19:13:42 -0400 Subject: [PATCH 6/8] Restore Dockerfile back to normal --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5aee150..ab5de5e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,7 +15,7 @@ RUN apt-get update \ WORKDIR /dotnetapp # Make use of Docker layering: cached layer -COPY ./netpkg-tool.csproj . +COPY netpkg-tool.csproj . RUN dotnet restore netpkg-tool.csproj # Make use of Docker layering: new layer COPY . . From 264c262936c61f224b8419675f7fe07d926abdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Gill=C3=A9?= Date: Wed, 6 Sep 2017 21:17:14 +0200 Subject: [PATCH 7/8] Improve Docker image description - Removed *pull* section, because `docker run` implies `docker pull` - Added links to Dockerfiles, just like most Docker image descriptions on the Docker Hub have - Fixed repository in example commands See https://github.com/phil-harmoniq/netpkg-tool/issues/47#issuecomment-325447252 --- docker/README.md | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/docker/README.md b/docker/README.md index b1bb85e..8fd8e99 100644 --- a/docker/README.md +++ b/docker/README.md @@ -3,18 +3,11 @@ netpkg-tool Docker Image This Docker image contains the [*netpkg-tool*](https://github.com/phil-harmoniq/netpkg-tool) binary and is based on the [microsoft/dotnet](https://hub.docker.com/r/microsoft/dotnet/) 2.0-sdk image. Using this Docker image allows you to use *netpkg-tool* without installing the .NET Core SDK. -Pull ------ - -Docker images are automatically built using the latest source files. Use the `latest` tag for the most recent master build or the `unstable` tag for the most recent development build: +Supported tags and respective `Dockerfile` links +------------------------------------------------ -```bash -# Latest master image -docker pull philharmoniq/netpkg-tool - -# Latest development image -docker pull philhamroniq/netpkg-tool:unstable -``` +- [`latest` (docker/Dockerfile)](https://github.com/phil-harmoniq/netpkg-tool/blob/master/docker/Dockerfile) +- [`develop` (docker/Dockerfile)](https://github.com/phil-harmoniq/netpkg-tool/blob/develop/docker/Dockerfile) Usage ----- @@ -24,7 +17,7 @@ Usage ```bash # Assuming the working directory contains your .NET Core project. # Note: ${PWD}/out doesn't have to exist - Docker creates the directory if necessary -docker run --rm -v ${PWD}:/root/src -v ${PWD}/out:/root/out local/netpkg-tool +docker run --rm -v ${PWD}:/root/src -v ${PWD}/out:/root/out philhamroniq/netpkg-tool ``` You can also supply parameters like `-n MyApp` or `--scd` to the container. **Full example**: @@ -32,7 +25,7 @@ You can also supply parameters like `-n MyApp` or `--scd` to the container. **Fu ```bash git clone https://github.com/phil-harmoniq/Hello cd Hello -docker run --rm -v ${PWD}:/root/src -v ${PWD}/out:/root/out local/netpkg-tool -n MyApp +docker run --rm -v ${PWD}:/root/src -v ${PWD}/out:/root/out philhamroniq/netpkg-tool -n MyApp ./out/MyApp ``` From 21c1ecc6acac690566dc233a6f4a3046f9bda80f Mon Sep 17 00:00:00 2001 From: phil-harmoniq Date: Thu, 7 Sep 2017 13:14:46 -0400 Subject: [PATCH 8/8] Increment version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5612999..2d22338 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Pre-packaged versions of *netpkg-tool* are available from the [releases tab](https://github.com/phil-harmoniq/netpkg-tool/releases): ```bash -# Github releases are tagged with their version (ex: 0.3.7) -wget https://github.com/phil-harmoniq/netpkg-tool/releases/download/0.3.7/netpkg-tool +# Github releases are tagged with their version (ex: 0.3.8) +wget https://github.com/phil-harmoniq/netpkg-tool/releases/download/0.3.8/netpkg-tool chmod a+x ./netpkg-tool # Place netpkg-tool somewhere on your $PATH (Optional)