Skip to content

windows native dockerfile #1396

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docker-for-windows/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
40 changes: 40 additions & 0 deletions docker-for-windows/README.md
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions docker-for-windows/build.ps1
Original file line number Diff line number Diff line change
@@ -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
}