0
votes

I am trying to create a Docker image for a Windows container with a VSTS build agent. I have the following Dockerfile:

# escape=`
FROM microsoft/aspnetcore-build:2.0-nanoserver-sac2016

# Set up environment
ENV AGENT_VERSION 2.129.1
ENV AGENT_TYPE build

# Download/extract the VSTS agent software
RUN Invoke-WebRequest -UseBasicParsing 
https://vstsagentpackage.azureedge.net/agent/${env:AGENT_VERSION}/vsts-agent-win-x64-${env:AGENT_VERSION}.zip -outfile agent.zip; `
    Expand-Archive agent.zip; `
    Remove-Item -Force agent.zip;
WORKDIR C:\agent

# Configure the agent and run it as a Windows service
# Users can pass "--deploymentGroup" to the "docker run" command if they want to run the agent as a deployment group (release) agent.
SHELL ["cmd", "/S", "/C"]
ENTRYPOINT C:\agent\config.cmd --unattended --auth pat --runAsService --addDeploymentGroupTags

And I'm getting this very confusing error from the ENTRYPOINT line:

-Sta : The term '-Sta' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Comman ...
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (-Sta:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
An error occurred: PowerShell is not installed. Minimum required version: 3.0

I've taken a look at the config.cmd script that gets downloaded, and it has the following nasty statement on line 26:

powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "$VerbosePreference = %VERBOSE_ARG% ; Get-ChildItem -LiteralPath '%~dp0' | ForEach-Object { Write-Verbose ('Unblock: {0}' -f $_.FullName) ; $_ } | Unblock-File | Out-Null ; Get-ChildItem -Recurse -LiteralPath '%~dp0bin', '%~dp0externals' | Where-Object { $_ -match '\.(ps1|psd1|psm1)$' } | ForEach-Object { Write-Verbose ('Unblock: {0}' -f $_.FullName) ; $_ } | Unblock-File | Out-Null ; Get-ChildItem -LiteralPath '%~dp0externals\vstsom', '%~dp0externals\vstshost' | Where-Object { $_ -match '\.(dll|exe)$' } | ForEach-Object { Write-Verbose ('Unblock: {0}' -f $_.FullName) ; $_ } | Unblock-File | Out-Null"

So that line appears to be the line that is failing in my container, but I have no idea why. The aspnetcore-build image (Dockerfile) that I'm deriving from is itself derived from a microsoft/dotnet image (Dockerfile), which sets the SHELL to powershell, so I know for a fact that PowerShell is installed in the container. Is there some kind of syntax error occurring as a result of calling this .cmd script from Docker? Any help would be much appreciated!

1
Are you aware that Microsoft already publishes a Dockerfile for Windows build agents? github.com/Microsoft/vsts-agent-docker - Daniel Mann
Yes I am aware, but according to Microsoft: Ubuntu 14.04 and 16.04 are the currently supported OSes, but there are plans for Windows support. I need Windows for a particular build task to succeed, but apparently Microsoft doesn't even support its own OS... - Rabadash8820

1 Answers

2
votes

There is Windows image file: vsts-agent-docker/windows/servercore/10.0.14393

It run agent as this:

& .\bin\Agent.Listener.exe configure --unattended `
    --agent "$env:VSTS_AGENT" `
    --url "https://$env:VSTS_ACCOUNT.visualstudio.com" `
    --auth PAT `
    --token "$env:VSTS_TOKEN" `
    --pool "$env:VSTS_POOL" `
    --work "$env:VSTS_WORK" `
    --replace

& .\bin\Agent.Listener.exe run

About how to use this image: https://github.com/Microsoft/vsts-agent-docker/blob/master/README.md#how-to-use-these-images