cake-build / resources

Contains different kind of resources such as bootstrappers and configuration files.
MIT License
55 stars 78 forks source link

Bootstrapper templates for Cake dotnet tool #95

Closed augustoproiete closed 3 years ago

augustoproiete commented 3 years ago

I'm interested in helping on the bootstrapper templates/example for Cake using the dotnet tool, so opening this issue to discuss how they should look like.

:white_check_mark: Things that come to mind of what the example bootstrapper should do (probably in this order):

  1. Ensure the bootstrapper stops in case of errors and forwards the exit code of the process that failed

  2. Change the working directory to the folder where the bootstrapper is located

    This is to make sure commands inside the bootstrapper are run in the expected directory relative to the bootstrapper. e.g.

  3. Disable the default caching of NuGet packages (a.k.a. "First Time Experience")

    This makes sense when running on temporary build nodes that are provisioned for each build (as the cache will be destroyed, so no point in having it enabled). For permanent build nodes on a self-hosted environment it might make sense to leave this enabled. I'd suggest a short comment with a link to a URL on the Cake website that explains more details and when it makes sense to disable or not

  4. Disable the .NET SDK telemetry feature

  5. Disable the .NET SDK welcome message

  6. Restore dotnet local tools (in case Cake is installed as a local tool)

    dotnet tool restore returns exit code 0 if a manifest is not found, so it's a safe call. If no manifest is found, the user just sees a warning message

  7. Run the dotnet-cake tool forwarding any arguments passed to the bootstrapper


:x: Things that come to mind of what the example bootstrapper shoud not do:

  1. Install .NET 5 or .NET Core

    Why not:

    • Devs using cloud-managed build servers that provision a temporary build node can usually rely on a ready-to-use image with .NET, Visual Studio, etc. already installed
    • Devs using self-hosted build servers usually have a dedicated team/person to manage the servers and perform one-time installs of .NET SDK, etc. as needed and build agents run with a low-privileged account that can't do much outside of the working folder (though I understand installing .NET in the local folder is a possibility, just don't think it's necessary).
  2. Install the Cake dotnet tool

    Why not:

    • I think most devs will be using dotnet-cake as a local tool through the tool-manifest and use that to pin the cake version they want to use for a project, store in source control, etc.
    • For devs that prefer to use dotnet-cake as a global tool, but are using a self-hosted build server, I don't think it's reasonable for one project to install (or update) a global tool that can affect other projects building on the same server. I think it's reasonable for the bootstrapper to expect the dotnet-cake tool to be pre-installed as a global tool if that's what the dev wants to use

Examples of the above (without comments, to simplify):

build.ps1

$ErrorActionPreference = 'Stop'

Set-Location -LiteralPath $PSScriptRoot

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
$env:DOTNET_NOLOGO = '1'

dotnet tool restore
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

dotnet cake @args
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

build.sh

#!/usr/bin/env bash
set -euox pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_NOLOGO=1

dotnet tool restore

dotnet cake $@
gep13 commented 3 years ago

@augustoproiete thanks for kicking off the discussion on this!

Everything here makes sense to me, with one exception...

Install .NET 5 or .NET Core

As a local dev, I work on a number of different projects, and as such, I may require different version of .NET installed. To facilitate this, as an example in the Cake repository itself, the bootstrapper installs the required version of .NET by pinning to the version that is defined in the global.json file. By doing this, I know that the build will always work locally, without having to do anything else.

Ideally, the bootstrapper would check to see if the required version of .Net is installed, and if not, take appropriate actions.

I understand that not everyone is sold on this idea though, so I would be happy to start with what you have suggested here. Did you want to send in a PR to add what you have, and we can go from there?

augustoproiete commented 3 years ago

As a local dev, I work on a number of different projects, and as such, I may require different version of .NET installed. To facilitate this

That makes sense to me and I have a similar situation in some of my projects as well. In this scenario my (personal) preference is to have a separate setup.ps1 / setup.sh that performs these kind of one-time setup to get the local dev environment ready and leave the build bootstrappers to do the minimum necessary to run Cake - but that's me.

I'll send a PR with the example scripts above just to get something going.


One other idea would be to put together a little "bootstrapper builder" UI where users can cherry-pick things they want and download a more customized boostrapper based on their preferences. Something along those lines:

image

pascalberger commented 3 years ago

One other idea would be to put together a little "bootstrap builder" UI where users can cherry-pick things they want and download a more customized boostrapper based on their preferences. Something along those lines:

@augustoproiete This is something I like 😄 Can you create an issue for this in the https://github.com/cake-build/website repo to discuss further there?

augustoproiete commented 3 years ago

@pascalberger https://github.com/cake-build/website/issues/1297

gep13 commented 3 years ago

@augustoproiete I like the idea of the Bootstrapper Builder 👍

We would still need to have a final version, which can be downloaded via the known URL's in things like the VSCode extension, but I love the idea of being able to cherry pick something for your own needs.

pascalberger commented 3 years ago

We would still need to have a final version, which can be downloaded via the known URL's in things like the VSCode extension, but I love the idea of being able to cherry pick something for your own needs.

Not if we provide an API to it: https://github.com/cake-build/website/issues/1297#issuecomment-737960188 😄

gep13 commented 3 years ago

@pascalberger what I meant was, in the version of the VSCode extension that we have literally just shipped, there is an expectation that you can download one of 6 bootstrappers. I think we need to provide those bootstrappers, and then, going forward, we can look to provide something else.

pascalberger commented 3 years ago

Yes, but we can provide a REST API to download them, which allows to pass parameters what should be in the bootstrapper instead of just a full final version. Existing URLs can redirect to the API using some default values. But this is a discussion for https://github.com/cake-build/website/issues/1297 (or maybe even an issue on top of https://github.com/cake-build/website/issues/1297).

I'm absolutely OK to have a bootstrapper in here. My comment was more that, if once we have an API we no longer need bootstrappers stored in a repo.

gep13 commented 3 years ago

@pascalberger said.. I'm absolutely OK to have a bootstrapper in here. My comment was more that, if once we have an API we no longer need bootstrappers stored in a repo.

Understood. Fairly sure that we are on the same page 😄