Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OctoPack doesn't work with OctopusTools v7.0.0 and higher #2828

Closed
ghost opened this issue Jul 9, 2020 · 10 comments
Closed

OctoPack doesn't work with OctopusTools v7.0.0 and higher #2828

ghost opened this issue Jul 9, 2020 · 10 comments

Comments

@ghost
Copy link

ghost commented Jul 9, 2020

What You Are Seeing?

OctoPack() fails when targeting version OctopusTools 7.0.0 and above. It works using the last v6, 6.17.6.

What is Expected?

Using v6.17.6:

Resolved tool to path /usr/bin/mono
/workspaces/repo/build/tools/OctopusTools.6.17.6/tools/Octo.exe is a .NET Framework executable, will try execute using Mono.
Executing: /usr/bin/mono "/workspaces/repo/build/tools/OctopusTools.6.17.6/tools/Octo.exe" pack --id Project.Name --basePath "/workspaces/repo/_dist/Project.Name" --title "Title"
Packing Title version "2020.7.9.204519"...
Saving "Title.2020.7.9.204519.nupkg" to "/workspaces/repo"...

What version of Cake are you using?

0.38.4

Are you running on a 32 or 64 bit system?

64-bit

What environment are you running on? Windows? Linux? Mac?

Windows 10, 1809 hosting a Linux Docker image:

mcr.microsoft.com/dotnet/core/sdk:3.1, Debian 10 with Mono installed

Are you running on a CI Server? If so, which one?

N/A, local build

Output Log

#tool "nuget:?package=OctopusTools&version=7.0.0":

Executing: /workspaces/repo/build/tools/OctopusTools.7.0.0/tools/octo.exe pack --id Project.Name --basePath "/workspaces/repo/_dist/Project.Name" --title "Title"
An error occurred when executing task 'Dist'.
Error: System.AggregateException: One or more errors occurred. (Exec format error)
 ---> System.ComponentModel.Win32Exception (8): Exec format error
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Cake.Core.IO.ProcessRunner.Start(FilePath filePath, ProcessSettings settings) in C:\projects\cake\src\Cake.Core\IO\ProcessRunner.cs:line 67
   at Cake.Core.Tooling.Tool`1.RunProcess(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 210
   at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 101
   at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 81
   at Cake.Common.Tools.OctopusDeploy.OctopusDeployPacker.Pack(String id, OctopusPackSettings settings) in C:\projects\cake\src\Cake.Common\Tools\OctopusDeploy\OctopusDeployPacker.cs:line 46
   at Cake.Common.Tools.OctopusDeploy.OctopusDeployAliases.OctoPack(ICakeContext context, String id, OctopusPackSettings settings) in C:\projects\cake\src\Cake.Common\Tools\OctopusDeploy\OctopusDeployAliases.cs:line 157
   at Submission#0.OctoPack(String id, OctopusPackSettings settings) in :line 1586
   at Submission#0.<<Initialize>>b__0_13() in /workspaces/repo/build/build.cake:line 323
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass29_0.<Does>b__0(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 26
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass32_0.<Does>b__0(ICakeContext x) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 83
   at Cake.Core.CakeTask.Execute(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTask.cs:line 125
   at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context) in C:\projects\cake\src\Cake.Core\DefaultExecutionStrategy.cs:line 87
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 336
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 361
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 369
   at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 284
   at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 240
   at Cake.Scripting.BuildScriptHost.RunTargetAsync(String target) in C:\projects\cake\src\Cake\Scripting\BuildScriptHost.cs:line 47
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target) in C:\projects\cake\src\Cake.Core\Scripting\ScriptHost.cs:line 191
   at Submission#0.<<Initialize>>d__0.MoveNext() in /workspaces/repo/build/build.cake:line 329
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Cake.Scripting.Roslyn.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Scripting\Roslyn\RoslynScriptSession.cs:line 136
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 219
   at Cake.Commands.BuildCommand.Execute(CakeOptions options) in C:\projects\cake\src\Cake\Commands\BuildCommand.cs:line 41
   at Cake.CakeApplication.Run(CakeOptions options) in C:\projects\cake\src\Cake\CakeApplication.cs:line 45
   at Cake.Program.Main() in C:\projects\cake\src\Cake\Program.cs:line 81
@devlead
Copy link
Member

devlead commented Jul 9, 2020

From Version 7 and up OctopusTools is now a .NET Core 3.1 self-contained single-file Windows-only executable won't run under Mono.

@devlead
Copy link
Member

devlead commented Jul 9, 2020

If you've got .NET Core on the Linux "Machine" you could switch to their global tool Octopus.DotNet.Cli.

You can use the Cake.DotNetTool Module to install

Example script:

// Install modules
#module nuget:?package=Cake.DotNetTool.Module&version=0.4.0

// Install .NET Core Global tools.
#tool "dotnet:https://api.nuget.org/v3/index.json?package=Octopus.DotNet.Cli&version=7.4.1"

OctoPack("MyPackage",
     new OctopusPackSettings {
                    Version = "1.0.0",
                    BasePath = "./bin",
                    OutFolder = "./out",
                    Overwrite = true
});

Example usage

dotnet cake .\build.cake --bootstrap
dotnet cake .\build.cake

--bootstrap is to install the Cake.DotNetTool.Module ( --bootstrap will be implicit in Cake 1.0)

@ghost
Copy link
Author

ghost commented Jul 10, 2020

I can't get this to work on Linux because I'm running into this issue:

docker/for-win#5822

I tried this on Windows, and it seems that it's trying to resolve octo.exe using my PATH, but Cake and all of its tools are installed locally in our repo in the /build/tools folder, they get installed when our build script is run for the first time.

@devlead
Copy link
Member

devlead commented Jul 10, 2020

Yes it'll resolve in the order

  1. octo.exe
  2. dotnet-octo
  3. dotnet-octo.exe

All Cake tools have a ToolPath on their "ToolSettingsso you could always override to change order i.e. excludeocto.exe`.

// Install modules
#module nuget:?package=Cake.DotNetTool.Module&version=0.4.0

// Install .NET Core Global tools.
#tool "dotnet:https://api.nuget.org/v3/index.json?package=Octopus.DotNet.Cli&version=7.4.1"

OctoPack("MyPackage",
     new OctopusPackSettings {
                    Version = "1.0.0",
                    BasePath = "./bin",
                    OutFolder = "./out",
                    Overwrite = true,
                    ToolPath = Context.Tools.Resolve("dotnet-octo")
                                ?? Context.Tools.Resolve("dotnet-octo.exe")
});

When running Cake.Tool I generally use dotnet tool manifest with repo so version of Cake is pinned in repo.

You create a tool manifest by in repo root typing

dotnet new tool-manifest

Then install Cake

dotnet tool install Cake.Tool

This will create an .config/dotnet-tools.json file.

Commit that to repo, then after one clone the repo usage is

  1. dotnet tool restore
  2. dotnet cake build.cake --bootstrap
  3. dotnet cake build.cake

Created a sample repo tried on Mac, Windows and docker.
https://github.com/devlead/OctoPackDotNetToolExample

Example when I ran it in docker standard SDK container

  1. docker run -it --rm mcr.microsoft.com/dotnet/core/sdk bash
  2. git clone https://github.com/devlead/OctoPackDotNetToolExample.git
  3. cd OctoPackDotNetToolExample
  4. dotnet tool restore
  5. dotnet cake build.cake --bootstrap
  6. dotnet cake build.cake

image

@ghost
Copy link
Author

ghost commented Jul 10, 2020

Ok this is great information.

I think what I was trying to do was mix our "old Cake build" (using build.ps1/build.sh) with the NEW way of running a Cake build (what you just described). I ran through the tutorial on the Cake website for setting up a brand new build.

What's the difference between registering a tool in the "dotnet tool manifest" (.config/dotnet-tools.json) and using the Cake.DotNetTool.Module package? Is it essentially the same thing?

@devlead
Copy link
Member

devlead commented Jul 10, 2020

.config/dotnet-tools.json is the .NET tool manifest, in this case used to bootstrap cake, so essentially an alternative to build.ps1/build.sh but could also be used in build.ps1/build.sh so you've instead of NuGet install have an dotnet tool restore.

The Cake.DotNetTool.Module extends Cake tool directive with dotnet: protocol allowing to install tools in the tools folder so they can be resolved by Cake and versioned with your script, i.e.
#tool "dotnet:https://api.nuget.org/v3/index.json?package=Octopus.DotNet.Cli&version=7.4.1"

@devlead
Copy link
Member

devlead commented Jul 10, 2020

One key difference with tool manifest is that no shims are created so tool needs to be invoked using dotnet command i.e. dotnet cake. Whereas tools installed globally or into a specific path (like Cake.DotNetTool.Module does) will create a shim. The shims are native Windows/Mac/Linux Commands that wraps dotnet path to command.

@ghost
Copy link
Author

ghost commented Jul 10, 2020

Ok that makes sense, thanks!

This is tangentially related, but the Cake.DotNetTool.Module says that there's a framework parameter that you can use to specify which framework the tool should use. It seems that GitVersion.Tool is defaulting to netcoreapp2.1, when I want it to use netcoreapp3.1 (both are bundled in the nuget package).

https://www.gep13.co.uk/blog/introducing-cake.dotnettool.module

Am I using this right?

#tool "dotnet:?package=GitVersion.Tool&version=5.3.7&global&framework=netcoreapp3.1"

@ghost
Copy link
Author

ghost commented Jul 10, 2020

Disregard! It looks like I'm encountering this problem instead:

GitTools/GitVersion#2308

Thanks for all of the information @devlead!

@ghost ghost closed this as completed Jul 10, 2020
@devlead
Copy link
Member

devlead commented Jul 10, 2020

Great that you got it sorted👍

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant