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

Build MSI For Integration Test (#388) #389

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 92 additions & 1 deletion .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,103 @@ jobs:

- name: Build Binaries
if: steps.cached_binaries.outputs.cache-hit != 'true'
run: make build package-rpm package-deb
run: make build package-rpm package-deb package-win

- name: Upload to s3
if: steps.cached_binaries.outputs.cache-hit != 'true'
run: aws s3 cp build/bin s3://cloudwatch-agent-integration-bucket/integration-test/binary/${{ github.sha }} --recursive

MakeMSIZip:
name: 'MakeMSIZip'
runs-on: ubuntu-latest
needs: [MakeBinary]
steps:
- uses: actions/checkout@v2

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2

- name: Cache win zip
id: cached_win_zip
uses: actions/cache@v2
with:
key: "cached_win_zip_${{ github.sha }}"
path: buildMSI.zip

- name: Copy binary
if: steps.cached_win_zip.outputs.cache-hit != 'true'
run: |
aws s3 cp s3://cloudwatch-agent-integration-bucket/integration-test/binary/${{ github.sha }} . --recursive

- uses: montudor/action-zip@v1
with:
args: unzip -qq windows/amd64/amazon-cloudwatch-agent.zip -d windows-agent

- name: Create msi dep folder and copy deps
run: |
export version=$(cat CWAGENT_VERSION)
echo cw agent version $version
mkdir msi_dep
cp -r integration/msi/tools/. msi_dep/
cp -r windows-agent/amazon-cloudwatch-agent/. msi_dep/
go run integration/msi/tools/msiversion/msiversionconverter.go $version msi_dep/amazon-cloudwatch-agent.wxs '<version>' --tags=integration
go run integration/msi/tools/msiversion/msiversionconverter.go $version msi_dep/manifest.json __VERSION__ --tags=integration

- uses: papeloto/action-zip@v1
if: steps.cached_win_zip.outputs.cache-hit != 'true'
with:
files: msi_dep/
dest: buildMSI.zip

- name: Upload zip
if: steps.cached_win_zip.outputs.cache-hit != 'true'
run: aws s3 cp buildMSI.zip s3://cloudwatch-agent-integration-bucket/integration-test/packaging/${{ github.sha }}/buildMSI.zip

BuildMSI:
name: 'BuildMSI'
runs-on: windows-latest
needs: [MakeMSIZip]
steps:
- uses: actions/checkout@v2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2

- name: Cache msi
id: cached_msi
uses: actions/cache@v2
with:
key: "cached_msi_${{ github.sha }}"
path: buildMSI/amazon-cloudwatch-agent.msi

- name: Copy msi
if: steps.cached_msi.outputs.cache-hit != 'true'
run: aws s3 cp s3://cloudwatch-agent-integration-bucket/integration-test/packaging/${{ github.sha }}/buildMSI.zip .

- name: Create msi
if: steps.cached_msi.outputs.cache-hit != 'true'
run : |
sethAmazon marked this conversation as resolved.
Show resolved Hide resolved
curl -OLS https://github.com/wixtoolset/wix3/releases/download/wix3111rtm/wix311.exe
.\wix311.exe /install /quiet /norestart
$wixToolsetBinPath = ";C:\Program Files (x86)\WiX Toolset v3.11\bin;"
$env:PATH = $env:PATH + $wixToolsetBinPath
Expand-Archive buildMSI.zip -Force
cd buildMSI
.\create_msi.ps1 ${{ github.sha }}

StartLocalStack:
name: 'StartLocalStack'
runs-on: ubuntu-latest
Expand Down
212 changes: 212 additions & 0 deletions integration/msi/tools/amazon-cloudwatch-agent.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?xml version='1.0' encoding='UTF-8'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'
xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>

<?define FixPermissionScriptAction=""powershell.exe" -ExecutionPolicy Bypass -File "[INSTALLDIR]permission.ps1"?>

<Product Id='*'
Name='Amazon CloudWatch Agent'
UpgradeCode='c537c936-91b3-4270-94d7-e128acfc3e86'
Language='1033'
Codepage='1252'
Version='<version>'
Manufacturer='Amazon.com, Inc.'>

<Package Id='*'
Keywords='Installer'
Description="Amazon CloudWatch Agent Installer"
Comments='Copyright 2018 Amazon.com, Inc. and its affiliates. All Rights Reserved.'
Manufacturer='Amazon.com, Inc.'
InstallerVersion='200'
Languages='1033'
Compressed='yes'
SummaryCodepage='1252'
InstallScope="perMachine"
Platform="x64"
/>

<MediaTemplate EmbedCab='yes' />

<Feature Id='ProductFeature' Title="Amazon CloudWatch Agent" Level='1'>
<ComponentRef Id='StarterEXE' />
<ComponentRef Id='AgentEXE' />
<ComponentRef Id='WizardEXE' />
<ComponentRef Id='Ctl' />
<ComponentRef Id='SchemaJSON' />
<ComponentRef Id='DownloaderEXE' />
<ComponentRef Id='TranslatorEXE' />
<ComponentRef Id='CWAGENT_VERSION' />
<ComponentRef Id='LICENSE' />
<ComponentRef Id='NOTICE' />
<ComponentRef Id='RELEASE_NOTES' />
<ComponentRef Id='THIRD_PARTY_LICENSES' />
<ComponentRef Id='CommonConfigTOML' />
<ComponentRef Id='CreateLogsFolder' />
<ComponentRef Id='CreateConfigsFolder' />
<ComponentRef Id='CreateCWOCConfigsFolder' />
<ComponentRef Id='CreateCWOCLogsFolder' />
<ComponentRef Id='CWOCEXE' />
<ComponentRef Id='PredefinedConfigData' />
<ComponentRef Id='FIX_PERMISSION' />
</Feature>

<Directory Id='TARGETDIR' Name='SourceDir'>

<Directory Id='ProgramFiles64Folder'>
<Directory Id='PFilesAmazon' Name='Amazon'>
<Directory Id='INSTALLDIR' Name='AmazonCloudWatchAgent'/>
</Directory>
</Directory>

<Directory Id='CommonAppDataFolder' Name='AppDataFolder'>
<Directory Id='AppDataFolderAmazon' Name='Amazon'>
<Directory Id='Config' Name='AmazonCloudWatchAgent'>
<Directory Id="Configs" Name="Configs"/>
<Directory Id='Logs' Name='Logs'/>
<Directory Id='CWOCConfig' Name='CWAgentOtelCollector'>
<Directory Id='CWOCConfigs' Name='Configs'/>
<Directory Id='CWOCLogs' Name='Logs'/>
</Directory>
</Directory>
</Directory>
</Directory>

</Directory>

<DirectoryRef Id="INSTALLDIR">
<Component Id='StarterEXE' Guid='5f344c26-c8f5-4a10-83c0-0651399fb8ff' Win64='yes'>
<File Source='start-amazon-cloudwatch-agent.exe' KeyPath='yes' Checksum='yes'/>
<ServiceInstall
Id="ServiceInstaller"
Type="ownProcess"
Name="AmazonCloudWatchAgent"
DisplayName="Amazon CloudWatch Agent"
Description="Amazon CloudWatch Agent"
Start="auto"
Account="LocalSystem"
Interactive="no"
ErrorControl="normal"
Vital="yes"
>
<ServiceDependency Id="LanmanServer"/>
<ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="restart" ResetPeriodInDays="1" RestartServiceDelayInSeconds="2" xmlns="http://schemas.microsoft.com/wix/UtilExtension"/>
<ServiceConfig OnInstall="yes" OnReinstall="yes" FailureActionsWhen="failedToStopOrReturnedError"/>
</ServiceInstall>
<ServiceControl
Id="StartService"
Stop="both"
Remove="uninstall"
Name="AmazonCloudWatchAgent"
Wait="yes"
/>
</Component>
<Component Id='CWOCEXE' Guid='3afd22e7-3f83-413f-9861-e1ac923a15c4' Win64='yes'>
<File Source='cwagent-otel-collector.exe' KeyPath='yes' Checksum='yes'/>
<ServiceInstall
Id="CWOCServiceInstaller"
Type="ownProcess"
Name="CWAgentOtelCollector"
DisplayName="CWAgent Otel Collector"
Description="CWAgent Otel Collector"
Start="demand"
Account="LocalSystem"
Interactive="no"
ErrorControl="normal"
Arguments=" --config=&quot;[CWOCConfig]cwagent-otel-collector.yaml&quot;"
Vital="yes"
>
<ServiceDependency Id="LanmanServer"/>
<ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="restart" ResetPeriodInDays="1" RestartServiceDelayInSeconds="2" xmlns="http://schemas.microsoft.com/wix/UtilExtension"/>
<ServiceConfig OnInstall="yes" OnReinstall="yes" FailureActionsWhen="failedToStopOrReturnedError"/>
</ServiceInstall>
<ServiceControl
Id="CWOCStartService"
Stop="both"
Remove="uninstall"
Name="CWAgentOtelCollector"
Wait="yes"
/>
</Component>
<Component Id='AgentEXE' Guid='d98c86be-b6c8-4f24-84a5-03b08bd6e7f2' Win64='yes'>
<File Source='amazon-cloudwatch-agent.exe' KeyPath='yes' Checksum='yes'/>
</Component>
<Component Id='WizardEXE' Guid='e8c20fcf-94c7-4097-97ed-ef4cc5c867b2' Win64='yes'>
<File Source='amazon-cloudwatch-agent-config-wizard.exe' KeyPath='yes' Checksum='yes'/>
</Component>
<Component Id='Ctl' Guid='f95f122b-aa48-4f6e-beab-05380b8ce99d' Win64='yes'>
<File Source='amazon-cloudwatch-agent-ctl.ps1' KeyPath='yes'/>
</Component>
<Component Id='SchemaJSON' Guid='80a1bfcc-8a0f-46e2-8e84-c2023d10fdf3' Win64='yes'>
<File Source='amazon-cloudwatch-agent-schema.json' KeyPath='yes'/>
</Component>
<Component Id='DownloaderEXE' Guid='727f4d1b-76bd-4cde-969a-02f16e4425ac' Win64='yes'>
<File Source='config-downloader.exe' KeyPath='yes' Checksum='yes'/>
</Component>
<Component Id='TranslatorEXE' Guid='f4527006-edcb-4271-a971-039848bc8bb7' Win64='yes'>
<File Source='config-translator.exe' KeyPath='yes' Checksum='yes'/>
</Component>
<Component Id='CWAGENT_VERSION' Guid='f4ddf7bf-48fc-41f6-a914-4153a7cf0afc' Win64='yes'>
<File Source='CWAGENT_VERSION' KeyPath='yes'/>
</Component>
<Component Id='LICENSE' Guid='ac70ef6c-8ec4-4a91-8059-2c18543df863' Win64='yes'>
<File Source='LICENSE' KeyPath='yes'/>
</Component>
<Component Id='NOTICE' Guid='d490c48d-eed1-445d-8eac-99769c472ec7' Win64='yes'>
<File Source='NOTICE' KeyPath='yes'/>
</Component>
<Component Id='RELEASE_NOTES' Guid='5bb03e58-44e1-4acc-a827-ad91e25025b9' Win64='yes'>
<File Source='RELEASE_NOTES' KeyPath='yes'/>
</Component>
<Component Id='THIRD_PARTY_LICENSES' Guid='ca4ac31e-8c1d-482f-9724-27f8857caca5' Win64='yes'>
<File Source='THIRD-PARTY-LICENSES' KeyPath='yes'/>
</Component>
<Component Id='FIX_PERMISSION' Guid='6ea35ac1-b8cc-492b-b62f-312c30395110' Win64='yes'>
<File Source='permission.ps1' KeyPath='yes'/>
</Component>
</DirectoryRef>

<DirectoryRef Id="Config">
<Component Id='CommonConfigTOML' Guid='293f73c5-1f51-4e65-86e3-97425ec75c94' Win64='yes' NeverOverwrite='yes' Permanent='yes'>
<File Source='common-config.toml' KeyPath='yes'/>
</Component>
</DirectoryRef>

<DirectoryRef Id="Configs">
<Component Id='CreateConfigsFolder' Guid='c860d000-ed10-11e8-8eb2-f2801f1b9fd1' Win64='yes'>
<CreateFolder />
</Component>
</DirectoryRef>

<DirectoryRef Id="CWOCConfig">
<Component Id='PredefinedConfigData' Guid='b0543a32-51e2-4f89-8375-4924e46095f4' Win64='yes' NeverOverwrite='yes' Permanent='yes'>
<File Source='predefined-config-data' KeyPath='yes'/>
</Component>
</DirectoryRef>

<DirectoryRef Id="CWOCConfigs">
<Component Id='CreateCWOCConfigsFolder' Guid='8c7cb53c-9b56-47b7-8a06-7c164a0b574a' Win64='yes'>
<CreateFolder />
</Component>
</DirectoryRef>

<DirectoryRef Id="CWOCLogs">
<Component Id='CreateCWOCLogsFolder' Guid='bfbfaece-1a9a-489b-bf1c-1039a7f70803' Win64='yes'>
<CreateFolder />
</Component>
</DirectoryRef>

<DirectoryRef Id="Logs">
<Component Id='CreateLogsFolder' Guid='fe9042cb-a4fa-4b8e-9852-685a342338b5' Win64='yes'>
<CreateFolder />
</Component>
</DirectoryRef>

<CustomAction Id="UpdateConfigPermission" Directory="INSTALLDIR" ExeCommand="$(var.FixPermissionScriptAction)" Execute="deferred" Return="check" Impersonate="no" />

<InstallExecuteSequence>
<Custom Action="UpdateConfigPermission" After="InstallFiles">NOT UPGRADINGPRODUCTCODE AND NOT (REMOVE~="ALL")</Custom>
</InstallExecuteSequence>

<MajorUpgrade AllowDowngrades="yes"/>
</Product>
</Wix>
10 changes: 10 additions & 0 deletions integration/msi/tools/create_msi.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# get the version
$version=$args[0]

# create msi
candle.exe -ext WixUtilExtension.dll ./amazon-cloudwatch-agent.wxs
light.exe -ext WixUtilExtension.dll ./amazon-cloudwatch-agent.wixobj

# upload to s3
aws s3 cp ./amazon-cloudwatch-agent.msi "s3://cloudwatch-agent-integration-bucket/integration-test/packaging/$version/amazon-cloudwatch-agent.msi"
Write-Host "s3 for msi is s3://cloudwatch-agent-integration-bucket/integration-test/packaging/$version/amazon-cloudwatch-agent.msi"
6 changes: 6 additions & 0 deletions integration/msi/tools/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "AmazonCloudWatchAgent",
"platform": "windows",
"architecture": "amd64",
"version": "__VERSION__"
}
41 changes: 41 additions & 0 deletions integration/msi/tools/msiversion/msiversionconverter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build linux && integration
// +build linux,integration

package main

/* We can't use the standard cw agent version for the windows msi due to limitations in the wix tools builder for msi
msi version is different from the agent original version because of the msi limit Product version must have a major version less than 256,
a minor version less than 256, and a build version less than 65536
*/
func main() {
sethAmazon marked this conversation as resolved.
Show resolved Hide resolved
log.Printf("Input %v", os.Args)
agentVersion := os.Args[1]
replaceFilePath := os.Args[2]
msiVersionKey := os.Args[3]
split := strings.Split(agentVersion, ".")
major := split[0]
minor, err := strconv.ParseInt(split[1], 10, 64)
if err != nil {
log.Fatalf("Failed to parse agentVersion %v", err)
}
minor = minor / 65536
patch, err := strconv.ParseInt(split[1], 10, 64)
if err != nil {
log.Fatalf("Failed to parse agentVersion %v", err)
}
patch = patch % 65536
msiVersion := major + "." + strconv.FormatInt(minor, 10) + "." + strconv.FormatInt(patch, 10)
log.Printf("Msi version is %v", msiVersion)
replaceValue(replaceFilePath, msiVersionKey, msiVersion)
}

func replaceValue(pathIn string, key string, value string) {
out, err := exec.Command("bash", "-c", "sed -i 's/"+key+"/'"+value+"'/g' "+pathIn).Output()

if err != nil {
log.Fatal(fmt.Sprint(err) + string(out))
}
}
7 changes: 7 additions & 0 deletions integration/msi/tools/permission.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$wrongsddl="D:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIIOID;GA;;;CO)(A;OICIID;0x1200a9;;;BU)(A;CIID;DCLCRPCR;;;BU)"
sethAmazon marked this conversation as resolved.
Show resolved Hide resolved
$output=& cacls.exe "${env:ProgramData}\Amazon\AmazonCloudWatchAgent" /S
$currsddl=$output.Split('"')[1]

If ($currsddl -eq $wrongsddl) {
& echo Y| cacls "${env:ProgramData}\Amazon\AmazonCloudWatchAgent" /S:"D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;FA;;;CO)(A;OICI;GR;;;BU)"
}