StefanScherer / windows-docker-machine

Work with Windows containers and LCOW on Mac/Linux/Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

packer build reduce disk size

fmontaldo opened this issue · comments

Hi Stefan,

I want to deploy a dev environment for the developers that works in the project. All got mac and this tutorials fits perfectly but I wan to know if there is a way to recue the size of the build of windows server.By the other hand I want to know if there is a change that you caa explain to me the difference of the two container images:

1709 - Windows Server, version 1709 (10.0.16299) Semi annual channel
1803 - Windows Server, version 1803 (10.0.17134) Semi annual channel

There is a way to run in mac only the containers insted off the vm and container?. Sorry if I ask too many thing but I never touch a windows server in my life.

Thanks in advance.

Federico

Hi,

you can reduce the size of the VM with the packer variable disk_size that is used in many of the packer templates here.

I recommend to use Fusion Pro because that allows you to use linked clones when you run vagrant up. The disk size of the base VM image is used only once on the Mac.

You can read more about the semi annual channel releases eg. here https://cloudblogs.microsoft.com/windowsserver/2018/03/29/windows-server-semi-annual-channel-update/

To run Windows containers you need a Windows host operating system. That's what the Windows VM templates are for. Similarly you need a Linux VM to run Linux containers (Docker for Mac, or docker-machine, ...)

Hi Stefan,

Thanks for your respond. Now I need to build a windows 10 vm and I want to know if there's a way to deploy the same build for windows 2016 into windows 10?. I need to start a dev environment with the eval features that you describerd for 2016. Please tell me if that can be done.

Regards

Federico

Hi Frederico,

If you want similar provisioned Windows 10 and Windows Server 20xx boxes then you should have a look at Matt's blog post https://hodgkins.io/best-practices-with-packer-and-windows

Building the empty base boxes for 10 + 2016 and then run a customizable Packer build with the provision scripts you want might be a better approach than running everything from ISO again and again.

Hi Stefan,

I made again the build but now I got an issu with the .bat that call the installation of chocolatery. Therefore I included the one that you include in another publish.

$env:chocolateyUseWindowsCompression = 'true'

Write-Output 'Install Chocolatey'
Invoke-WebRequest 'https://chocolatey.org/install.ps1' -UseBasicParsing | Invoke-Expression

Write-Output 'Install editors'
choco install -y visualstudio2017community --params="'--add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --add Component.GitHub.VisualStudio'"

Write-Output 'Install Git'
choco install -y git

Write-Output 'Install dotnet'
choco install -y dotnet4.7.2

Write-Output 'Install dotnetsdk'
choco install -y dotnetcore-sdk

I included this path $env:chocolateyUseWindowsCompression = 'true'

because the original .bat fails with the following:

2018/10/11 18:08:56 ui: virtualbox-iso:
2018/10/11 18:08:56 ui: virtualbox-iso: ERROR: The system cannot find the file specified.
2018/10/11 18:08:56 ui: virtualbox-iso: C:\Users\vagrant\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip
2018/10/11 18:08:56 ui: virtualbox-iso:
2018/10/11 18:08:56 ui: virtualbox-iso:
2018/10/11 18:08:56 ui: virtualbox-iso:
2018/10/11 18:08:56 ui: virtualbox-iso: System ERROR:
2018/10/11 18:08:56 ui: virtualbox-iso: The system cannot find the file specified.
2018/10/11 18:08:56 ui: virtualbox-iso: Unable to unzip package using 7zip. Perhaps try setting $env:chocolateyUseWindowsCompression = 'true' and call install
2018/10/11 18:08:56 ui: virtualbox-iso: again. Error: 7-Zip encountered a fatal error while extracting the files
2018/10/11 18:08:56 ui: virtualbox-iso: At line:216 char:9
2018/10/11 18:08:56 ui: virtualbox-iso: + 2 { throw "$errorMessage 7-Zip encountered a fatal error while ex ...
2018/10/11 18:08:56 ui: virtualbox-iso: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2018/10/11 18:08:56 ui: virtualbox-iso: + CategoryInfo : OperationStopped: (Unable to unzip...cting the files:String) [], RuntimeException
2018/10/11 18:08:56 ui: virtualbox-iso: + FullyQualifiedErrorId : Unable to unzip package using 7zip. Perhaps try setting $env:chocolateyUseWindowsCompres
2018/10/11 18:08:56 ui: virtualbox-iso: sion = 'true' and call install again. Error: 7-Zip encountered a fatal error while extracting the files
2018/10/11 18:08:56 ui: virtualbox-iso:
2018/10/11 18:08:56 [INFO] (telemetry) ending windows-shell
2018/10/11 18:08:56 ui error: ==> virtualbox-iso: Script exited with non-zero exit status: 1
2018/10/11 18:08:56 ui: ==> virtualbox-iso: Step "StepProvision" failed
2018/10/11 18:08:56 ui: ask: ==> virtualbox-iso: [c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)?
virtualbox-iso: ERROR: The system cannot find the file specified.
virtualbox-iso: C:\Users\vagrant\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip

I need the following software:

.NET 4.7.2

.NET Core 2.x

Visual Studio Community 2017

Thats why I try choco but it fails. Please tell me the way to complete this build.

this is my packer build

{
"builders": [
{
"type": "virtualbox-iso",
"iso_url": "{{user iso_url}}",
"iso_checksum_type": "{{user iso_checksum_type}}",
"iso_checksum": "{{user iso_checksum}}",
"headless": false,
"guest_additions_mode": "attach",
"boot_wait": "2m",
"communicator": "winrm",
"winrm_username": "vagrant",
"winrm_password": "vagrant",
"winrm_timeout": "5h",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c "Packer Shutdown"",
"shutdown_timeout": "15m",
"guest_os_type": "Windows81_64",
"disk_size": 61440,
"floppy_files": [
"{{user autounattend}}",
"{{user autounattend}}",
"./floppy/WindowsPowershell.lnk",
"./floppy/PinTo10.exe",
"./scripts/fixnetwork.ps1",
"./scripts/disable-screensaver.ps1",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1",
"./scripts/microsoft-updates.bat",
"./scripts/win-updates.ps1"
],
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"2048"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"2"
]
]
}
],
"provisioners": [
{
"scripts": [
"./scripts/docker/10/install-containers-feature.ps1"
],
"type": "powershell"
},
{
"type": "windows-restart"
},
{
"environment_vars": [
"docker_images={{user docker_images}}",
"docker_provider={{user docker_provider}}",
"docker_version={{user docker_version}}"
],
"scripts": [
"./scripts/docker/add-docker-group.ps1",
"./scripts/docker/install-docker.ps1",
"./scripts/docker/docker-pull.ps1",
"./scripts/docker/open-docker-insecure-port.ps1",
"./scripts/docker/open-docker-swarm-ports.ps1",
"./scripts/docker/remove-docker-key-json.ps1",
"./scripts/docker/disable-windows-defender.ps1"
],
"type": "powershell"
},
{
"scripts": [
"./scripts/uac-enable.bat",
"./scripts/set-winrm-automatic.bat",
"./scripts/compact.bat",
"./scripts/chocolatey-and-tools.ps1"
],
"type": "windows-shell"
},
{
"type": "windows-restart"
}
],
"post-processors": [
{
"type": "vagrant",
"keep_input_artifact": false,
"output": "windows_10_docker{{.Provider}}.box",
"vagrantfile_template": "vagrantfile-windows_10.template"
}
],
"variables": {

"iso_url": "https://software-download.microsoft.com/download/pr/17134.1.180410-1804.rs4_release_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso",
"iso_checksum_type": "md5",
"iso_checksum": "89f6b3079b3669560d29f3c4be9cc74d",
 "autounattend": "./answer_files/10/Autounattend.xml"

}
}
Regards

Federico

Oh the chocolatey.bat and others come from the time with Win2008 and Win7 boxes where PowerShell support was poor.

You definitely should use PowerShell provision scripts to have a better experience right now.
I don't know the details why installing some of the Chocolatey packages you have mentioned doesn't work.

it works Stefan. This are the things there I changed:

cat scripts/chocolatey.bat
$env:chocolateyUseWindowsCompression = 'true'
powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" <NUL

cat scripts/chocopacks.bat
:: Ensure C:\Chocolatey\bin is on the path
set /p PATH=<C:\Windows\Temp\PATH
choco feature enable -n allowGlobalConfirmation
:: Install all the things; for example:
cmd /c choco install dotnet4.7.2
cmd /c choco install git.install
cmd /c choco install dotnetcore-sdk
cmd /c choco install visualstudio2017community --params="'--add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --add Component.GitHub.VisualStudio'"

The build complete successfully and when I enter into the vm I got app of VS. I really apreciate your patience and the work for this github project it helps me a lot. Thank you.

You are welcome. I‘m glad you found a solution for your automation task.