forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitTools#2742 - update dockerhub readme on stable releases
- Loading branch information
Showing
9 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="DockerHub Readme Publish" type="DotNetProject" factoryName=".NET Project" folderName="Docker"> | ||
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/docker.exe" /> | ||
<option name="PROGRAM_PARAMETERS" value="--target=DockerHubReadmePublish" /> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." /> | ||
<option name="PASS_PARENT_ENVS" value="1" /> | ||
<envs> | ||
<env name="DOCKER_USERNAME" value="" /> | ||
<env name="DOCKER_PASSWORD" value="" /> | ||
</envs> | ||
<option name="USE_EXTERNAL_CONSOLE" value="0" /> | ||
<option name="USE_MONO" value="0" /> | ||
<option name="RUNTIME_ARGUMENTS" value="" /> | ||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/docker/docker.csproj" /> | ||
<option name="PROJECT_EXE_PATH_TRACKING" value="1" /> | ||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" /> | ||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" /> | ||
<option name="PROJECT_KIND" value="DotNetCore" /> | ||
<option name="PROJECT_TFM" value="net7.0" /> | ||
<method v="2"> | ||
<option name="Build" /> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Cake.Http; | ||
using Cake.Json; | ||
using Common.Utilities; | ||
|
||
namespace Docker.Tasks; | ||
|
||
[TaskName(nameof(DockerHubReadmePublish))] | ||
[TaskDescription("Publish the DockerHub updated README.md")] | ||
public class DockerHubReadmePublish : FrostingTask<BuildContext> | ||
{ | ||
public override bool ShouldRun(BuildContext context) | ||
{ | ||
var shouldRun = false; | ||
if (context.DockerRegistry == DockerRegistry.DockerHub) | ||
{ | ||
shouldRun &= context.ShouldRun(context.IsStableRelease, $"{nameof(DockerHubReadmePublish)} works only for tagged releases."); | ||
} | ||
|
||
return shouldRun; | ||
} | ||
|
||
public override void Run(BuildContext context) | ||
{ | ||
var readme = GetReadmeContent(context); | ||
|
||
var response = context.HttpPost("https://hub.docker.com/v2/users/login", settings => | ||
{ | ||
var credentials = context.Credentials!.DockerHub!; | ||
settings | ||
.SetContentType("application/json") | ||
.SetJsonRequestBody(new { username = credentials.Username, password = credentials.Password }); | ||
}); | ||
|
||
|
||
context.HttpPatch("https://hub.docker.com/v2/repositories/gittools/gitversion", settings => | ||
{ | ||
var token = context.ParseJson(response).Value<string>("token"); | ||
settings | ||
.SetContentType("application/json") | ||
.SetAuthorization($"JWT", token) | ||
.SetJsonRequestBody(new { full_description = readme }); | ||
}); | ||
} | ||
|
||
private static string GetReadmeContent(BuildContextBase context) | ||
{ | ||
var version = context.Version!.GitVersion.MajorMinorPatch; | ||
const string distro = Constants.AlpineLatest; | ||
const string dotnetVersion = Constants.VersionLatest; | ||
var tag = $"{version}-{distro}-{dotnetVersion}"; | ||
// language=markdown | ||
var readme = $""" | ||
# GitVersion | ||
This repository contains the Docker images for [GitVersion](https://gitversion.net). | ||
## 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: | ||
```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. | ||
### 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 | ||
``` | ||
"""; | ||
return readme; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Common.Utilities; | ||
|
||
namespace Docker.Utilities; | ||
|
||
public class Credentials | ||
{ | ||
public DockerHubCredentials? DockerHub { get; private init; } | ||
|
||
public static Credentials GetCredentials(ICakeContext context) => new() | ||
{ | ||
DockerHub = new DockerHubCredentials( | ||
context.EnvironmentVariable("DOCKER_USERNAME"), | ||
context.EnvironmentVariable("DOCKER_PASSWORD")), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters