diff --git a/README.md b/README.md index 555234c61..73bf858cd 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,32 @@ powershell -ExecutionPolicy bypass # switch to powershell if you are not on pow .\build-and-publish-docker-image.ps1 -image /: # trigger build code and image and publish docker hub or acr ``` +##### Developer Build optimizations +If you do not want to build the image from scratch every time you make changes during development,you can choose to build the docker images that are separated out by +* Base image and dependencies including agent bootstrap(setup.ps1) +* Agent conf and plugin changes + +To do this, the very first time you start developing you would need to execute below instructions in elevated command prompt of powershell. +This builds the base image(omsagent-win-base) with all the package dependencies +``` +cd %userprofile%\Docker-Provider\kubernetes\windows\dockerbuild # based on your repo path +docker login # if you want to publish the image to acr then login to acr via `docker login ` +powershell -ExecutionPolicy bypass # switch to powershell if you are not on powershell already +.\build-dev-base-image.ps1 # builds base image and dependencies +``` + +And then run the script to build the image consisting of code and conf changes. +``` +.\build-and-publish-dev-docker-image.ps1 -image /: # trigger build code and image and publish docker hub or acr +``` + +For the subsequent builds, you can just run - + +``` +.\build-and-publish-dev-docker-image.ps1 -image /: # trigger build code and image and publish docker hub or acr +``` +###### Note - If you have changes in setup.ps1 and want to test those changes, uncomment the section consisting of setup.ps1 in the Dockerfile-dev-image file. + #### Option 2 - Using WSL2 to Build the Windows agent ##### On WSL2, Build Certificate Generator Source code and Out OMS Go plugin code diff --git a/kubernetes/windows/Dockerfile-dev-base-image b/kubernetes/windows/Dockerfile-dev-base-image new file mode 100644 index 000000000..9c6ae8db8 --- /dev/null +++ b/kubernetes/windows/Dockerfile-dev-base-image @@ -0,0 +1,43 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2019 +MAINTAINER OMSContainers@microsoft.com +LABEL vendor=Microsoft\ Corp \ + com.microsoft.product="Azure Monitor for containers" + +# Do not split this into multiple RUN! +# Docker creates a layer for every RUN-Statement +RUN powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" +# Fluentd depends on cool.io whose fat gem is only available for Ruby < 2.5, so need to specify --platform ruby when install Ruby > 2.5 and install msys2 to get dev tools +RUN choco install -y ruby --version 2.6.5.1 --params "'/InstallDir:C:\ruby26'" \ +&& choco install -y msys2 --version 20200903.0.0 --params "'/NoPath /NoUpdate /InstallDir:C:\ruby26\msys64'" \ +&& choco install -y vim + +# gangams - optional MSYS2 update via ridk failing in merged docker file so skipping that since we dont need optional update +RUN refreshenv \ +&& ridk install 3 \ +&& echo gem: --no-document >> C:\ProgramData\gemrc \ +&& gem install cool.io -v 1.5.4 --platform ruby \ +&& gem install oj -v 3.3.10 \ +&& gem install json -v 2.2.0 \ +&& gem install fluentd -v 1.12.2 \ +&& gem install win32-service -v 1.0.1 \ +&& gem install win32-ipc -v 0.7.0 \ +&& gem install win32-event -v 0.6.3 \ +&& gem install windows-pr -v 1.2.6 \ +&& gem install tomlrb -v 1.3.0 \ +&& gem install gyoku -v 1.3.1 \ +&& gem sources --clear-all + +# Remove gem cache and chocolatey +RUN powershell -Command "Remove-Item -Force C:\ruby26\lib\ruby\gems\2.6.0\cache\*.gem; Remove-Item -Recurse -Force 'C:\ProgramData\chocolatey'" + +SHELL ["powershell"] + +ENV tmpdir /opt/omsagentwindows/scripts/powershell + +WORKDIR /opt/omsagentwindows/scripts/powershell + +# copy certificate generator binaries zip +COPY ./omsagentwindows/*.zip /opt/omsagentwindows/ + +COPY setup.ps1 /opt/omsagentwindows/scripts/powershell +RUN ./setup.ps1 \ No newline at end of file diff --git a/kubernetes/windows/Dockerfile-dev-image b/kubernetes/windows/Dockerfile-dev-image new file mode 100644 index 000000000..6764ef8c4 --- /dev/null +++ b/kubernetes/windows/Dockerfile-dev-image @@ -0,0 +1,45 @@ +FROM omsagent-win-base +MAINTAINER OMSContainers@microsoft.com +LABEL vendor=Microsoft\ Corp \ + com.microsoft.product="Azure Monitor for containers" + +#Uncomment below to test setup.ps1 changes +#COPY setup.ps1 /opt/omsagentwindows/scripts/powershell +#RUN ./setup.ps1 +COPY main.ps1 /opt/omsagentwindows/scripts/powershell +COPY ./omsagentwindows/installer/scripts/filesystemwatcher.ps1 /opt/omsagentwindows/scripts/powershell +COPY ./omsagentwindows/installer/scripts/livenessprobe.cmd /opt/omsagentwindows/scripts/cmd/ +COPY setdefaulttelegrafenvvariables.ps1 /opt/omsagentwindows/scripts/powershell + +# copy ruby scripts to /opt folder +COPY ./omsagentwindows/installer/scripts/*.rb /opt/omsagentwindows/scripts/ruby/ + +# copy out_oms.so file +COPY ./omsagentwindows/out_oms.so /opt/omsagentwindows/out_oms.so + +# copy fluent, fluent-bit and out_oms conf files +COPY ./omsagentwindows/installer/conf/fluent.conf /etc/fluent/ +# copy fluent docker and cri parser conf files +COPY ./omsagentwindows/installer/conf/fluent-cri-parser.conf /etc/fluent/ +COPY ./omsagentwindows/installer/conf/fluent-docker-parser.conf /etc/fluent/ +COPY ./omsagentwindows/installer/conf/fluent-bit.conf /etc/fluent-bit +COPY ./omsagentwindows/installer/conf/out_oms.conf /etc/omsagentwindows + +# copy telegraf conf file +COPY ./omsagentwindows/installer/conf/telegraf.conf /etc/telegraf/ + +# copy keepcert alive ruby scripts +COPY ./omsagentwindows/installer/scripts/rubyKeepCertificateAlive/*.rb /etc/fluent/plugin/ + +#Copy fluentd ruby plugins +COPY ./omsagentwindows/ruby/ /etc/fluent/plugin/ +COPY ./omsagentwindows/utils/*.rb /etc/fluent/plugin/ + +ENV AGENT_VERSION ${IMAGE_TAG} +ENV OS_TYPE "windows" +ENV APPLICATIONINSIGHTS_AUTH "NzAwZGM5OGYtYTdhZC00NThkLWI5NWMtMjA3ZjM3NmM3YmRi" +ENV AZMON_COLLECT_ENV False +ENV CI_CERT_LOCATION "C://oms.crt" +ENV CI_KEY_LOCATION "C://oms.key" + +ENTRYPOINT ["powershell", "C:\\opt\\omsagentwindows\\scripts\\powershell\\main.ps1"] diff --git a/kubernetes/windows/dockerbuild/build-and-publish-dev-docker-image.ps1 b/kubernetes/windows/dockerbuild/build-and-publish-dev-docker-image.ps1 new file mode 100644 index 000000000..0fde7f379 --- /dev/null +++ b/kubernetes/windows/dockerbuild/build-and-publish-dev-docker-image.ps1 @@ -0,0 +1,64 @@ +<# + .DESCRIPTION + Builds the Windows Agent code and Docker Image and pushes the docker image to specified repo + + .PARAMETER image + docker image. format should be /: +#> +param( + [Parameter(mandatory = $true)] + [string]$image +) + +$currentdir = $PSScriptRoot +Write-Host("current script dir : " + $currentdir + " ") + +if ($false -eq (Test-Path -Path $currentdir)) { + Write-Host("Invalid current dir : " + $currentdir + " ") -ForegroundColor Red + exit +} + +if ([string]::IsNullOrEmpty($image)) { + Write-Host "Image parameter shouldnt be null or empty" -ForegroundColor Red + exit +} + +$imageparts = $image.split(":") +if (($imageparts.Length -ne 2)){ + Write-Host "Image not in valid format. Expected format should be /:" -ForegroundColor Red + exit +} + +$imagetag = $imageparts[1].ToLower() +$imagerepo = $imageparts[0] + +if ($imagetag.StartsWith("win-") -eq $false) +{ + Write-Host "adding win- prefix image tag since its not provided" + $imagetag = "win-$imagetag" +} + +Write-Host "image tag used is :$imagetag" + +Write-Host "start:Building the cert generator and out oms code via Makefile.ps1" +..\..\..\build\windows\Makefile.ps1 +Write-Host "end:Building the cert generator and out oms code via Makefile.ps1" + +$dockerFileDir = Split-Path -Path $currentdir +Write-Host("builddir dir : " + $dockerFileDir + " ") +if ($false -eq (Test-Path -Path $dockerFileDir)) { + Write-Host("Invalid dockerFile Dir : " + $dockerFileDir + " ") -ForegroundColor Red + exit +} + +Write-Host "changing directory to DockerFile dir: $dockerFileDir" +Set-Location -Path $dockerFileDir + +$updateImage = ${imagerepo} + ":" + ${imageTag} +Write-Host "STAT:Triggering docker image build: $image" +docker build -t $updateImage --build-arg IMAGE_TAG=$imageTag -f Dockerfile-dev-image . +Write-Host "END:Triggering docker image build: $updateImage" + +Write-Host "STAT:pushing docker image : $updateImage" +docker push $updateImage +Write-Host "EnD:pushing docker image : $updateImage" diff --git a/kubernetes/windows/dockerbuild/build-dev-base-image.ps1 b/kubernetes/windows/dockerbuild/build-dev-base-image.ps1 new file mode 100644 index 000000000..142e20c3f --- /dev/null +++ b/kubernetes/windows/dockerbuild/build-dev-base-image.ps1 @@ -0,0 +1,32 @@ +<# + .DESCRIPTION + Builds the Docker Image locally for the server core ltsc base and installs dependencies + +#> + +$currentdir = $PSScriptRoot +Write-Host("current script dir : " + $currentdir + " ") + +if ($false -eq (Test-Path -Path $currentdir)) { + Write-Host("Invalid current dir : " + $currentdir + " ") -ForegroundColor Red + exit +} + +Write-Host "start:Building the cert generator and out oms code via Makefile.ps1" +..\..\..\build\windows\Makefile.ps1 +Write-Host "end:Building the cert generator and out oms code via Makefile.ps1" + +$dockerFileDir = Split-Path -Path $currentdir +Write-Host("builddir dir : " + $dockerFileDir + " ") +if ($false -eq (Test-Path -Path $dockerFileDir)) { + Write-Host("Invalid dockerFile Dir : " + $dockerFileDir + " ") -ForegroundColor Red + exit +} + +Write-Host "changing directory to DockerFile dir: $dockerFileDir" +Set-Location -Path $dockerFileDir + +$updateImage = "omsagent-win-base" +Write-Host "STAT:Triggering base docker image build: $updateImage" +docker build -t $updateImage -f Dockerfile-dev-base-image . +Write-Host "END:Triggering docker image build: $updateImage" \ No newline at end of file