From 9d7452d887a2f1f4c0988616a8064d6314260167 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Mon, 15 Jul 2024 21:58:58 +0200 Subject: [PATCH 1/2] #4078 - update dockerhub README info --- .../Utilities/DockerContextExtensions.cs | 2 +- build/docker/Tasks/DockerHubReadmePublish.cs | 20 +++++++- docs/input/docs/usage/docker.md | 47 ++++++++++++++----- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/build/common/Utilities/DockerContextExtensions.cs b/build/common/Utilities/DockerContextExtensions.cs index ad043b03a1..80eb3b86be 100644 --- a/build/common/Utilities/DockerContextExtensions.cs +++ b/build/common/Utilities/DockerContextExtensions.cs @@ -202,7 +202,7 @@ private static IEnumerable GetDockerTags(this BuildContextBase context, var distro = dockerImage.Distro; var targetFramework = dockerImage.TargetFramework; - if (context.Version == null) return Enumerable.Empty(); + if (context.Version == null) return []; var tags = new List { $"{name}:{context.Version.Version}-{distro}-{targetFramework}", diff --git a/build/docker/Tasks/DockerHubReadmePublish.cs b/build/docker/Tasks/DockerHubReadmePublish.cs index dde53c1a72..f9e1531fd9 100644 --- a/build/docker/Tasks/DockerHubReadmePublish.cs +++ b/build/docker/Tasks/DockerHubReadmePublish.cs @@ -55,6 +55,7 @@ private static string GetReadmeContent(BuildContextBase context) // language=markdown var readme = $""" # GitVersion + ![GitVersion – From git log to SemVer in no time][banner] Versioning when using Git, solved. GitVersion looks at your git history and works out the [Semantic Version][semver] of the commit being built. @@ -63,18 +64,35 @@ private static string GetReadmeContent(BuildContextBase context) ## Usage -The recommended image to run is `alpine`, as they are the smallest Docker images we provide (83 MB). This will execute GitVersion for the current working directory (`$(pwd)`) on Linux and Unix or powershell on Windows: +The recommended image to run is `alpine`, as they are the smallest Docker images we provide. This will execute GitVersion for the current working directory (`$(pwd)`) on Linux and Unix or powershell on Windows: ```sh docker run --rm -v "$(pwd):/repo" gittools/gitversion:{tag} /repo ``` + The following command will execute GitVersion for the current working directory (`%CD%`) on Windows with CMD: ```sh docker run --rm -v "%CD%:/repo" gittools/gitversion:{tag} /repo ``` + Note that the path `/repo` needs to be passed as an argument since the `gitversion` executable within the container is not aware of the fact that it's running inside a container. +### CI Agents + +If you are running GitVersion on a CI agent, you may need to specify environment variables to allow GitVersion to work correctly. +For example, on Azure DevOps you may need to set the following environment variables: + +```sh +docker run --rm -v "$(pwd):/repo" --env TF_BUILD=true --env BUILD_SOURCEBRANCH=$(Build.SourceBranch) gittools/gitversion:{tag} /repo +``` + +On GitHub Actions, you may need to set the following environment variables: + +```sh +docker run --rm -v "$(pwd):/repo" --env GITHUB_ACTIONS=true --env GITHUB_REF=$(GITHUB_REF) gittools/gitversion:{tag} /repo +``` + ### Tags Most of the tags we provide have both arm64 and amd64 variants. If you need to pull a architecture specific tag you can do that like: diff --git a/docs/input/docs/usage/docker.md b/docs/input/docs/usage/docker.md index 5d70058ce1..f7d7c2cb96 100644 --- a/docs/input/docs/usage/docker.md +++ b/docs/input/docs/usage/docker.md @@ -5,22 +5,45 @@ Description: | Use GitVersion through one of its many published Docker containers. --- -GitVersion can be used through one of its many published Docker -containers. The list of available containers can be found on -[Docker Hub][docker-hub]. Once you've found the image you want to use, -you can run it like this: +The recommended image to run is `alpine`, as they are the smallest Docker images we provide. This will execute GitVersion for the current working directory (`$(pwd)`) on Linux and Unix or powershell on Windows: -```shell -docker run --rm --volume "$(pwd):/repo" gittools/gitversion:6.0.0-fedora.36-6.0 /repo +```sh +docker run --rm -v "$(pwd):/repo" gittools/gitversion:{tag} /repo ``` -The above command will run GitVersion with the current directory -mapped to `/repo` inside the container (the `--volume "$(pwd):/repo"` -part). The `/repo` directory is then passed in as the argument -GitVersion should use to calculate the version. +The following command will execute GitVersion for the current working directory (`%CD%`) on Windows with CMD: -The `--rm` flag will remove the container after it has finished -running. +```sh +docker run --rm -v "%CD%:/repo" gittools/gitversion:{tag} /repo +``` + +Note that the path `/repo` needs to be passed as an argument since the `gitversion` executable within the container is not aware of the fact that it's running inside a container. + +### CI Agents + +If you are running GitVersion on a CI agent, you may need to specify environment variables to allow GitVersion to work correctly. +For example, on Azure DevOps you may need to set the following environment variables: + +```sh +docker run --rm -v "$(pwd):/repo" --env TF_BUILD=true --env BUILD_SOURCEBRANCH=$(Build.SourceBranch) gittools/gitversion:{tag} /repo +``` + +On GitHub Actions, you may need to set the following environment variables: + +```sh +docker run --rm -v "$(pwd):/repo" --env GITHUB_ACTIONS=true --env GITHUB_REF=$(GITHUB_REF) gittools/gitversion:{tag} /repo +``` + +### Tags + +Most of the tags we provide have both arm64 and amd64 variants. If you need to pull a architecture specific tag you can do that like: + +```sh +docker run --rm -v "$(pwd):/repo" gittools/gitversion:{tag}-amd64 /repo +docker run --rm -v "$(pwd):/repo" gittools/gitversion:{tag}-arm64 /repo +``` + +The list of available containers can be found on [Docker Hub][docker-hub]. [Explore GitVersion on Docker Hub][docker-hub]{.btn .btn-primary} From 786a159bb82a96882deff05f9e58c63dd5c316fc Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Mon, 15 Jul 2024 22:58:19 +0200 Subject: [PATCH 2/2] #4078 - update publishing docker images publish docker image with MajorMinorPatch only on Stable releases --- build/common/Utilities/DockerContextExtensions.cs | 3 ++- build/common/Utilities/Models.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build/common/Utilities/DockerContextExtensions.cs b/build/common/Utilities/DockerContextExtensions.cs index 80eb3b86be..c20e106994 100644 --- a/build/common/Utilities/DockerContextExtensions.cs +++ b/build/common/Utilities/DockerContextExtensions.cs @@ -211,12 +211,13 @@ private static IEnumerable GetDockerTags(this BuildContextBase context, if (distro == Constants.DockerDistroLatest && targetFramework == Constants.VersionLatest) { - tags.AddRange(new[] { $"{name}:{context.Version.Version}", $"{name}:{context.Version.SemVersion}", }); + tags.Add($"{name}:{context.Version.SemVersion}"); if (context.IsStableRelease) { tags.AddRange( [ + $"{name}:{context.Version.Version}", $"{name}:latest", $"{name}:latest-{targetFramework}", $"{name}:latest-{distro}", diff --git a/build/common/Utilities/Models.cs b/build/common/Utilities/Models.cs index d36317d0a9..a90d493e16 100644 --- a/build/common/Utilities/Models.cs +++ b/build/common/Utilities/Models.cs @@ -40,7 +40,7 @@ public static BuildVersion Calculate(GitVersion gitVersion) nugetVersion += $".{gitVersion.BuildMetaData}"; } - return new BuildVersion( + return new( GitVersion: gitVersion, Version: version, Milestone: semVersion,