Skip to content

Commit

Permalink
Creating ChocolateyPackage Class-based DSC Resource (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelcolas committed Mar 24, 2023
1 parent 9d97cd6 commit fd0f607
Show file tree
Hide file tree
Showing 41 changed files with 741 additions and 1,348 deletions.
89 changes: 62 additions & 27 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,73 @@
---
# Check this doc: https://github.com/test-kitchen/kitchen-azurerm
# you may set the following environment variables:
# AZURE_CLIENT_ID="your-azure-client-id-here"
# AZURE_CLIENT_SECRET="your-client-secret-here"
# AZURE_TENANT_ID="your-azure-tenant-id-here"
# (check doc https://github.com/test-kitchen/kitchen-azurerm for more details)

driver:
name: azurerm
subscription_id: <%= ENV['AZ_SUBSCRIPTION_ID'] %>
location: 'uksouth'
machine_size: 'Standard_D2s_v3'
username: azure
password: <%=
require "securerandom"
if File.exists?("./.kitchen/pwd.txt")
ENV['MACHINE_PASS'] = File.read("./.kitchen/pwd.txt")
else
ENV['MACHINE_PASS'] = SecureRandom.base64(24)
File.open("./.kitchen/pwd.txt", "w") { |f| f.write ENV['MACHINE_PASS'] }
end
ENV['MACHINE_PASS']
%>

provisioner:
name: dsc
dsc_local_configuration_manager_version: wmf5
dsc_local_configuration_manager:
reboot_if_needed: true
configuration_mode_frequency_mins: 15
debug_mode: none
configuration_script_folder: Chocolatey/examples
configuration_script: dsc_configuration.ps1
modules_path: BuildOutput/Artefact
retry_on_exit_code:
- 35
configuration_data_variable: configurationData
modules_from_gallery:
- xPSDesiredStateConfiguration
- name: Pester
requiredversion: 4.0.3
repository: PSGallery
#- PackageManagementProviderResource
name: shell # defaults to bash on linux, so the shebang is important!
script: 'tests/kitchen/provisioning.ps1'

verifier:
name: pester
test_folder: Chocolatey/tests/integration/
shell: powershell
bootstrap: # installs modules from nuget feed by download and unzip.
repository_url: "https://www.powershellgallery.com/api/v2"
modules:
- PackageManagement
- PowerShellGet
test_folder: ./tests/kitchen/
copy_folders:
- output/module/Chocolatey
downloads:
"./PesterTestResults.xml": "./output/testResults/"
# kitchen_cmd.ps1: "./output/testResults/"
# ./coverage.xml: "./output/testResults/"
# # : ./testresults

platforms:
- name: win2012r2_PPB
- name: winCore2022
driver:
# image_urn: MicrosoftWindowsServer:microsoftserveroperatingsystems-previews:windows-server-2022-azure-edition-preview-core:20348.11.2105262137
image_urn: MicrosoftWindowsServer:WindowsServer:2022-datacenter-core:latest #20348.288.2110071044
# use_ephemeral_osdisk: true
os_type: windows
shell: powershell
lifecycle:
post_create:
- remote: |
$null = Install-PackageProvider -Name NuGet -Confirm:$false -Force
Install-Module PowerShellGet -Force -SkipPublisherCheck -Confirm:$false -Scope AllUsers
Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Trusted'
Remove-Module -Name PowerShellGet
transport:
name: winrm

suites:
- name: chocolatey
provisioner:
configuration_script_folder: Chocolatey/examples
configuration_script: chocolateyConfig.ps1
- name: Default
- name: Remove

- name: GCPackages
verifier:
copy_folders:
- output/GCPackages/
- output/module/Chocolatey # This is only used when troubleshooting interactively.
install_modules:
- Name: GuestConfiguration
AllowPrerelease: true
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Modified project with new Sampler template.
- Invoking choco commands now always add `--no-progress` & `--limit-output`
- Changed `ChocolateySoftware` to be class-based DSC Resource.
- Changed `ChocolateyPackage` to be class-based DSC Resource.

### Added

- Added the `ChocolateyIsInstalled` Azure Automanage Machine Configuration package that validates that Chocolatey is installed.

### Removed

Expand Down
7 changes: 7 additions & 0 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'DscResource.AnalyzerRules' = 'latest'
xDscResourceDesigner = 'latest'
'DscResource.DocGenerator' = 'latest'

'GuestConfiguration' = @{
version = 'latest'
Parameters = @{
AllowPrerelease = $true
}
}
}
5 changes: 5 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ BuildWorkflow:
# - Set_PSModulePath
- Invoke_HQRM_Tests_Stop_On_Fail

gcpol:
- build_guestconfiguration_packages

# Defining test task to be run when invoking `./build.ps1 -Tasks test`
test:
# - Set_PSModulePath
Expand Down Expand Up @@ -152,6 +155,8 @@ TaskHeader: |
GitHubConfig:
GitHubFilesToAdd:
- 'CHANGELOG.md'
ReleaseAssets:
- output/GCPackages/ChocoIsInstalled*.zip
GitHubConfigUserName: dscbot
GitHubConfigUserEmail: [email protected]
UpdateChangelogOnPrerelease: false
Expand Down
8 changes: 8 additions & 0 deletions source/Classes/001.ChocolateyReason.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ChocolateyReason
{
[DscProperty(NotConfigurable)]
[string] $Code

[DscProperty(NotConfigurable)]
[string] $Phrase
}
Loading

0 comments on commit fd0f607

Please sign in to comment.