Skip to content

Commit

Permalink
Update devenv script (DataDog#8677)
Browse files Browse the repository at this point in the history
* Update devenv script

* Cleanup devenv script

Remove things not needed to build an agent binary

* Fix environment on devenv

- When appending to PATH, fetch previous value from the registry, instead of
  using $Env:PATH. This prevents the script from clobbering paths that were
  added by chocolatey install.
- Add rtloader\bin directory to the path, so that agent.exe can find our rtloader.dll.
- Add gopath\bin to the path, so we can run tools installed by go get.

* Add gcloud devenv image builder
  • Loading branch information
vickenty authored and julianosk committed Jul 26, 2022
1 parent 1d2763a commit 2cb9c47
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 32 deletions.
45 changes: 45 additions & 0 deletions devenv/gcloud.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Packer script to build devenv image on GCP.
#
# Usage:
# packer init gcloud.pkr.hcl
# packer build gcloud.pkr.hcl

packer {
required_plugins {
googlecompute = {
version = ">= 0.0.1"
source = "github.com/hashicorp/googlecompute"
}
}
}

source "googlecompute" "datadog-agent-windows-dev" {
project_id =
network =
subnetwork =

source_image_family = "windows-2019"
zone = "europe-west1-b"
disk_size = 50
machine_type = "e2-standard-4"
communicator = "winrm"
winrm_username = "packer_user"
winrm_insecure = true
winrm_use_ssl = true
image_name = "agent-windows-dev-{{timestamp}}"
image_family = "agent-windows-dev"
metadata = {
windows-startup-script-cmd = "winrm quickconfig -quiet & net user /add packer_user & net localgroup administrators packer_user /add & winrm set winrm/config/service/auth @{Basic=\"true\"}"
}
}

build {
sources = ["sources.googlecompute.datadog-agent-windows-dev"]
provisioner "powershell" {
scripts = [
"scripts/Install-DevEnv.ps1",
"scripts/Disable-WinRM.ps1"
]
}
}

52 changes: 20 additions & 32 deletions devenv/scripts/Install-DevEnv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ cinst -y git
Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Getting 7zip'
cinst -y 7zip

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Visual Studio build tools'
cinst -y visualstudio2017buildtools --params "--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81"

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Visual C++ Workload'
cinst -y visualstudio2017-workload-vctools

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installinc VC Tools for Python 2.7'l
cinst -y vcpython27

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Wix'
cinst -y wixtoolset --version 3.11
[Environment]::SetEnvironmentVariable(
"Path",
[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";${env:ProgramFiles}\WiX Toolset v3.11\bin",
[System.EnvironmentVariableTarget]::Machine)

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing CMake'
cinst -y cmake
[Environment]::SetEnvironmentVariable(
Expand Down Expand Up @@ -76,30 +60,34 @@ Start-Process "7z" -ArgumentList 'x -oc:\ c:\go.zip' -Wait
Write-Host -ForegroundColor Green "Removing temporary file $out"
Remove-Item 'c:\go.zip'

setx GOROOT c:\go
$Env:GOROOT="c:\go"
setx PATH "$Env:Path;c:\go\bin;"
$Env:Path="$Env:Path;c:\go\bin;"
[Environment]::SetEnvironmentVariable(
"Path",
[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";C:\go\bin",
[System.EnvironmentVariableTarget]::Machine)

setx /m GOROOT c:\go
# End Go workaround

Write-Host -ForegroundColor Green "Installed go $ENV:GO_VERSION"

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Python 2'
cinst -y python2
Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Python 3'
cinst -y python3

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Ruby'
cinst -y ruby --version 2.4.3.1
Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing MINGW'
cinst -y mingw

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing MSYS'
cinst -y msys2 --params "/NoUpdate" # install msys2 without system update
Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Make'
cinst -y make

# Reload environment to get ruby in path
Update-SessionEnvironment
$GoPath="C:\gopath"
$AgentPath="$GoPath\src\github.com\datadog\datadog-agent"
mkdir -Force $AgentPath

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Toolchain'
ridk install 2 3 # use ruby's ridk to update the system and install development toolchain
[Environment]::SetEnvironmentVariable(
"Path",
[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";$GoPath\bin;$AgentPath\rtloader\bin",
[System.EnvironmentVariableTarget]::Machine)

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen '- Installing Bundler'
gem install bundler
setx /m GOPATH "$GoPath"

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen ' * DONE *'

0 comments on commit 2cb9c47

Please sign in to comment.