diff --git a/docker-for-windows/Dockerfile b/docker-for-windows/Dockerfile new file mode 100644 index 0000000000..70693c6aac --- /dev/null +++ b/docker-for-windows/Dockerfile @@ -0,0 +1,29 @@ +# escape=` +ARG OS_IMAGE_TAG=1709 +FROM microsoft/windowsservercore:$OS_IMAGE_TAG AS downloader +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $InformationPreference = 'Continue'; $ProgressPreference = 'SilentlyContinue';"] + +ARG GV_VERSION=3.6.5 +ARG GV_VERSION_ZIP=$GV_VERSION + +# Download GitVersion from github release url + +RUN $zipFile = 'GitVersion_{0}.zip' -f $env:GV_VERSION_ZIP; ` + $url = 'https://github.com/GitTools/GitVersion/releases/download/v{0}/GitVersion_{1}.zip' -f $env:GV_VERSION, $env:GV_VERSION_ZIP; ` + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ` + Invoke-WebRequest $url -OutFile $zipFile -UseBasicParsing; ` + Expand-Archive $zipFile -DestinationPath C:/GitVersion; + + +# app image +ARG OS_IMAGE_TAG=1709 +FROM microsoft/windowsservercore:$OS_IMAGE_TAG + +COPY --from=downloader C:/GitVersion/ C:/GitVersion/ + +WORKDIR C:/repo + +# Make git repo on host available in container +VOLUME C:/repo + +ENTRYPOINT ["powershell", "C:/GitVersion/GitVersion.exe"] \ No newline at end of file diff --git a/docker-for-windows/README.md b/docker-for-windows/README.md new file mode 100644 index 0000000000..2b6303fdc4 --- /dev/null +++ b/docker-for-windows/README.md @@ -0,0 +1,40 @@ +# Windows native docker image + +## Why? + +A linux docker image is available for GitVersion [here](https://hub.docker.com/r/ilucker/gitversion/) + +This is the preferred docker image to use. However, it's also convenient to have a native windows +docker image available, at least until either: + +* dotnet core build of GitVersion is available +* linux and native windows containers can be run side-by-side (see [--platform flag](https://blog.docker.com/2018/02/docker-for-windows-18-02-with-windows-10-fall-creators-update/#h.kiztgok2bqti)) + +## Use docker image + +``` powershell +docker run --rm -v "$(pwd):C:\repo" gittools/gitversion-win +``` + +The above command is the equivalent to running (assuming you have GitVersion.exe in your `$PATH`): + +``` cmd +GitVersion +``` + +## Build docker image + +1. Open powershell prompt +2. Change directory to the `docker-for-windows` directory + * eg: `cd C:\Git\GitVersion\docker-for-windows` +3. Run build.ps1 with the appropriate arguments + * eg: `.\build.ps1 -Version 4.0.0-beta.13 -VersionZip 4.0.0-beta0013` + +## Publish image + +1. Open powershell prompt +2. Login to docker registry you will be pushing to (see [docker login](https://docs.docker.com/engine/reference/commandline/login/) command) +3. Change directory to the `docker-for-windows` directory + * eg: `cd C:\Git\GitVersion\docker-for-windows` +3. Run build.ps1 with the appropriate arguments + * eg: `.\build.ps1 -Version 4.0.0-beta.13 -VersionZip 4.0.0-beta0013` -Publish \ No newline at end of file diff --git a/docker-for-windows/build.ps1 b/docker-for-windows/build.ps1 new file mode 100644 index 0000000000..ea48d9d194 --- /dev/null +++ b/docker-for-windows/build.ps1 @@ -0,0 +1,28 @@ +param( + [ValidateNotNullOrEmpty()] + [string] $Username = 'gittools', + + [Parameter(Mandatory)] + [string] $Version, + + [string] $VersionZip = $Version, + + [string] $OSImageTag = '1709', + + [switch] $Publish +) + +$ErrorActionPreference = 'Stop' +$InformationPreference = 'Continue' + +$repo = "$Username/gitversion-win" +$repoLatest = "$repo`:latest" +$repoVersion = "$repo`:$Version" +Write-Information "Building $repoVersion" +docker build -t $repoLatest -t $repoVersion --build-arg GV_VERSION=$Version --build-arg GV_VERSION_ZIP=$VersionZip --build-arg OS_IMAGE_TAG=$OSImageTag . + +if ($Publish) { + Write-Information "Pushing $repoVersion (including 'latest' tag)" + docker push $repoVersion + docker push $repoLatest +}