Skip to content
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

Run Builds in Docker Container Locally #328

Closed
wants to merge 13 commits into from
Closed

Run Builds in Docker Container Locally #328

wants to merge 13 commits into from

Conversation

SebastianSchuetze
Copy link
Collaborator

@SebastianSchuetze SebastianSchuetze commented May 27, 2020

I have been playing around to run the builds with Pester 5 in container locally for the following configurations

  • Windows server core with PS 7
  • Windows server core with PS 5.1
  • ubuntu-18.04 with PS 7

It uses docker and I have created 2 images with our modules preinstalled. There were some problems to run PS5.1, but I managed to have this run. I think it still needs some minor changes, but 95% I feel it is good enough to have it for developers to use.

They all seem to work. IN between build the daemon switches from windows to linux since linux based containers cannot run with windows containers in parallel.

Tell me what you think and if it works for you @DarqueWarrior

@SebastianSchuetze SebastianSchuetze added the enhancement Improvements that do not include new features label May 27, 2020
@DarqueWarrior
Copy link
Collaborator

$PSVersionTable.Platform on my machine (Windows 10, PowerShell 5.1) returns nothing because it was not supported then. and causes the following errors:

WARNING: Platform is not Win32NT based but ''. Windows container do not work on linux based systems. Ignoring windows containers...
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/images/json?filters=%7B%22reference%22%3A%7B%22vsteam%2Flinux%22%3Atrue%7D%7D: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
unable to prepare context: unable to evaluate symlinks in Dockerfile path: CreateFile R:\repos\vsteam\build\docker: The system cannot find the file specified.
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/json?all=1&filters=%7B%22name%22%3A%7B%22vsteam_linux_ps7_tests%22%3Atrue%7D%7D: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/json?filters=%7B%22name%22%3A%7B%22vsteam_linux_ps7_tests%22%3Atrue%7D%7D: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
C:\Program Files\Docker\Docker\resources\bin\docker.exe: error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/create?name=vsteam_linux_ps7_tests: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
See 'C:\Program Files\Docker\Docker\resources\bin\docker.exe run --help'.
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/vsteam_linux_ps7_tests/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero.
Parameter name: startIndex"
At R:\repos\vsteam\tools\docker\Run-ContainerTests.ps1:157 char:10
+          $versiontable = $output.Substring($outputFirst, $ouputLast+1 ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/vsteam_linux_ps7_tests/wait?condition=: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

Get-OperatingSystem works everywhere and is a better way to check OS.

I changed it locally but still getting different errors. I will keep playing with it.

@DarqueWarrior
Copy link
Collaborator

I tried to push my change but got an error

Permission to razorspoint/vsteam.git denied to Darquewarrior.

$scriptPath = $PSScriptRoot
$rootDir = (Resolve-Path -Path "$scriptPath\..\..\").ToString().trim('\')
$containerFolder = "c:/vsteam"
$containerFilePath = "$rootDir/build/docker"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be "$rootDir/Tools/docker" not build/docker.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixed the dir. I moved it before.

@DarqueWarrior
Copy link
Collaborator

I am getting close. I have the Linux version working on Windows. But the Windows images are failing to build.

$output = (docker exec -it $Container $Shell -c '$PSVersionTable | ConvertTo-Json -Compress;') -join ''
$outputFirst = $output.IndexOf('{')
$ouputLast = $output.LastIndexOf('}')
$versiontable = $output.Substring($outputFirst, $ouputLast+1-$outputFirst) | ConvertFrom-Json -Depth 50
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConvertFrom-Json does not have a -Depth. Only ConvertTo-Json has that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it. Didnt get an error before and VSCode seems to suggest that as a parameter.

@DarqueWarrior
Copy link
Collaborator

I can't seen to get my Windows containers access to the internet so all the module installs are failing. Did you have to do anything special to get your Window containers to see the internet?

@DarqueWarrior
Copy link
Collaborator

I got internet in my Windows VMS but following this docker/for-win#2760

@DarqueWarrior
Copy link
Collaborator

Now that I have it working this is pretty cool! I wonder if we should just add a -UseDocker switch to the build-module.ps1 and roll this into that script.

@SebastianSchuetze
Copy link
Collaborator Author

It is strange. I don't see the PR checkbox to give you write access. I just gave you maintainer access to my fork repo!

I hope you can commit now to it.

@SebastianSchuetze
Copy link
Collaborator Author

About integrating it into the build script. I was thinking to refactor some of the build files we use into an extra folder!

I would suggest something like "tools/XYZ". There we put an extra structure for everything.

@DarqueWarrior
Copy link
Collaborator

We can discuss during our meeting. I will try to have it this week.

@DarqueWarrior
Copy link
Collaborator

Testing on my Linux machine now. Looks to be working. I will move to Mac to test next.

@DarqueWarrior
Copy link
Collaborator

Still having issues pushing my changes to this PR. So I will create a new one with my changes. I have tested it on all three platforms. This is a really cool idea! Thanks.

@DarqueWarrior
Copy link
Collaborator

Merged in a different PR.

@SebastianSchuetze SebastianSchuetze deleted the topic/VsCodeRemoteMultiContainerBuild branch June 13, 2020 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements that do not include new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants