├── .gitignore ├── LICENSE ├── README.md ├── bamboo-server.json ├── notes.md ├── scripts ├── BundleConfig.ps1 ├── EC2Config.ps1 ├── InstallBambooServer.ps1 ├── RunTests.ps1 ├── SetUpDevTools.ps1 └── SetUpWinRM.ps1 └── tests ├── BambooInstalled.Tests.ps1 ├── DevToolsInstalled.Tests.ps1 └── MSBuild14Installed.Tests.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | TestResults.xml 2 | packer-manifest.json 3 | packer-manifest.json.lock 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Skelton Thatcher 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Packer AMI build for Bamboo 6 on Win 2012 R2 & .Net 4.5.2 2 | This script creates an AMI with Bamboo 6 and tools required to build .net 4.5.2 applications on a local Agent. This will enable you to satisfy the requirements for the requirements for the [Starter Licence](https://www.atlassian.com/licensing/bamboo) and so should only be used for demo/experimentation purposes. 3 | For a full licence I'd suggest only using Packer to build the remote agent AMIs for use as Elastic Cloud agents. The server itself can then be whichever operating system you like and can be managed with config tools such as Ansible. 4 | 5 | ## Requirements 6 | * An AWS account with permissions to create EC2 instances and AMIs 7 | * [Packer](https://www.packer.io/) 8 | 9 | ## Usage Instructions 10 | 11 | 1. Ensure your aws credentials have been configured. These scripts expect to use [Automatic Lookup](https://www.packer.io/docs/builders/amazon.html#specifying-amazon-credentials). To use a profile other than default, set the env variable `AWS_PROFILE` to the profile name. 12 | 1. Clone or download this repo 13 | 1. In the repo folder run 14 | ``` 15 | packer build bamboo-server.json 16 | ``` 17 | 1. Go make a cup of coffee 18 | 1. Once finished, check the output for successful test results. 19 | 1. Your AMI is now ready to launch 20 | 1. Amend your instance's [Security Group rules](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_SecurityGroups.html#AddRemoveRules) to allow TCP inbound over port 8085. 21 | 1. Once launched navigate to `http://:8085` to complete the [Bamboo setup wizard](https://confluence.atlassian.com/bamboo/running-the-setup-wizard-289276851.html). 22 | 23 | **Note:** The Bamboo Server is set up as a service but does not have logon credentials. These will need to be set once the Administrator password is known after you've launched your instance. Follow these [instructions for running Bamboo as a Service](https://confluence.atlassian.com/bamkb/running-bamboo-as-a-windows-service-troubleshooting-guide-420973231.html). 24 | -------------------------------------------------------------------------------- /bamboo-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "builders": [ 3 | { 4 | "type": "amazon-ebs", 5 | "region": "eu-west-1", 6 | "instance_type": "t2.micro", 7 | "ami_name": "Bamboo Server 6.1 {{timestamp}}", 8 | "user_data_file": "./scripts/SetUpWinRM.ps1", 9 | "communicator": "winrm", 10 | "winrm_username": "Administrator", 11 | "winrm_use_ssl": true, 12 | "winrm_insecure": true, 13 | "source_ami_filter": { 14 | "filters": { 15 | "name": "Windows_Server-2012-R2_RTM-English-64Bit-Base-*" 16 | }, 17 | "owners": ["801119661308"], 18 | "most_recent": true 19 | } 20 | } 21 | ], 22 | "provisioners": [ 23 | { 24 | "type": "powershell", 25 | "scripts": [ 26 | "./scripts/EC2Config.ps1", 27 | "./scripts/BundleConfig.ps1", 28 | "./scripts/SetUpDevTools.ps1", 29 | "./scripts/InstallBambooServer.ps1" 30 | ] 31 | }, 32 | { 33 | "type": "file", 34 | "source": "./tests", 35 | "destination": "C:/Windows/Temp" 36 | }, 37 | { 38 | "type": "powershell", 39 | "script": "./scripts/RunTests.ps1" 40 | }, 41 | { 42 | "type": "file", 43 | "source": "TestResults.xml", 44 | "destination": "TestResults.xml", 45 | "direction": "download" 46 | } 47 | ], 48 | "post-processors": [ 49 | { 50 | "type": "manifest" 51 | } 52 | ] 53 | } -------------------------------------------------------------------------------- /notes.md: -------------------------------------------------------------------------------- 1 | Enabling WinRM & Creating AMI: 2 | http://blog.petegoo.com/2016/05/10/packer-aws-windows/ 3 | 4 | Setting up EC2Config to Sysprep: 5 | https://gist.github.com/jamiegs/a0be9125cdb668fd19e56127c113a49d 6 | 7 | Testing example: 8 | https://github.com/garethr/packer-serverspec-example/tree/master/tests 9 | -------------------------------------------------------------------------------- /scripts/BundleConfig.ps1: -------------------------------------------------------------------------------- 1 | $EC2SettingsFile="C:\\Program Files\\Amazon\\Ec2ConfigService\\Settings\\BundleConfig.xml" 2 | $xml = [xml](get-content $EC2SettingsFile) 3 | $xmlElement = $xml.get_DocumentElement() 4 | 5 | foreach ($element in $xmlElement.Property) 6 | { 7 | if ($element.Name -eq "AutoSysprep") 8 | { 9 | $element.Value="Yes" 10 | } 11 | } 12 | $xml.Save($EC2SettingsFile) 13 | -------------------------------------------------------------------------------- /scripts/EC2Config.ps1: -------------------------------------------------------------------------------- 1 | $EC2SettingsFile="C:\\Program Files\\Amazon\\Ec2ConfigService\\Settings\\Config.xml" 2 | $xml = [xml](get-content $EC2SettingsFile) 3 | $xmlElement = $xml.get_DocumentElement() 4 | $xmlElementToModify = $xmlElement.Plugins 5 | 6 | $enableElements = "Ec2SetPassword", ` 7 | "Ec2SetComputerName", ` 8 | "Ec2HandleUserData", ` 9 | "Ec2DynamicBootVolumeSize" 10 | 11 | $xmlElementToModify.Plugin | Where-Object {$enableElements -contains $_.name} | Foreach-Object {$_.State="Enabled"} 12 | 13 | $xml.Save($EC2SettingsFile) 14 | -------------------------------------------------------------------------------- /scripts/InstallBambooServer.ps1: -------------------------------------------------------------------------------- 1 | Write-Host "Downloading Bamboo" 2 | Invoke-WebRequest -URI "http://www.atlassian.com/software/bamboo/downloads/binary/atlassian-bamboo-6.1.0-windows-x64.exe" -OutFile "C:\Windows\Temp\atlassian-bamboo-6.1.0-windows-x64.exe" 3 | 4 | Write-Host "Installing Bamboo" 5 | Start-Process C:\Windows\Temp\atlassian-bamboo-6.1.0-windows-x64.exe -ArgumentList "-q" -Wait 6 | 7 | Write-Host "Installing Bamboo as a Service" 8 | & "C:\Program Files\Bamboo\InstallAsService.bat" 9 | 10 | # Set Creds to local Admin 11 | # Figure out how to get the password 12 | # https://blog.ipswitch.com/working-with-windows-services-in-powershell 13 | 14 | Write-Host "Setting Bamboo Service to Automatic startup and then starting" 15 | Set-Service Bamboo -startuptype "Automatic" 16 | Start-Service Bamboo 17 | 18 | Write-Host "Adding firewall rule for Bamboo if not present" 19 | If (!(Get-NetFirewallRule -Name "Bamboo Server")) { 20 | New-NetFirewallRule -Name "Bamboo Server" -Description "Exposes the default port 8085 for Bamboo Server" -DisplayName "Bamboo Server" -Enabled:True -Profile Public -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8085 21 | } 22 | -------------------------------------------------------------------------------- /scripts/RunTests.ps1: -------------------------------------------------------------------------------- 1 | Invoke-Pester C:/Windows/Temp/* -OutputFile TestResults.xml -OutputFormat NUnitXml 2 | -------------------------------------------------------------------------------- /scripts/SetUpDevTools.ps1: -------------------------------------------------------------------------------- 1 | # Install Chocolatey 2 | iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 3 | # Globally Auto confirm every action 4 | choco feature enable -n allowGlobalConfirmation 5 | 6 | # Install .net 4.5.2 7 | choco install netfx-4.5.2-devpack 8 | 9 | # Install build tools 2015 10 | choco install microsoft-build-tools --version 14.0.25420.1 11 | 12 | # Install JDK 8 for Bamboo 13 | choco install jdk8 14 | 15 | choco install nuget.commandline 16 | choco install nunit-console-runner 17 | # Extension for generating results readable by Bamboo 18 | choco install nunit-extension-nunit-v2-result-writer 19 | choco install git 20 | 21 | # Install Pester to run server tests 22 | choco install Pester 23 | -------------------------------------------------------------------------------- /scripts/SetUpWinRM.ps1: -------------------------------------------------------------------------------- 1 | 2 | 3 | write-output "Running User Data Script" 4 | write-host "(host) Running User Data Script" 5 | 6 | Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore 7 | 8 | # Don't set this before Set-ExecutionPolicy as it throws an error 9 | $ErrorActionPreference = "stop" 10 | 11 | # Remove HTTP listener 12 | Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse 13 | 14 | $Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" 15 | New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force 16 | 17 | # WinRM 18 | write-output "Setting up WinRM" 19 | write-host "(host) setting up WinRM" 20 | 21 | cmd.exe /c winrm quickconfig -q 22 | cmd.exe /c winrm set "winrm/config" '@{MaxTimeoutms="1800000"}' 23 | cmd.exe /c winrm set "winrm/config/winrs" '@{MaxMemoryPerShellMB="1024"}' 24 | cmd.exe /c winrm set "winrm/config/service" '@{AllowUnencrypted="true"}' 25 | cmd.exe /c winrm set "winrm/config/client" '@{AllowUnencrypted="true"}' 26 | cmd.exe /c winrm set "winrm/config/service/auth" '@{Basic="true"}' 27 | cmd.exe /c winrm set "winrm/config/client/auth" '@{Basic="true"}' 28 | cmd.exe /c winrm set "winrm/config/service/auth" '@{CredSSP="true"}' 29 | cmd.exe /c winrm set "winrm/config/listener?Address=*+Transport=HTTPS" "@{Port=`"5986`";Hostname=`"packer`";CertificateThumbprint=`"$($Cert.Thumbprint)`"}" 30 | cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes 31 | cmd.exe /c netsh firewall add portopening TCP 5986 "Port 5986" 32 | cmd.exe /c net stop winrm 33 | cmd.exe /c sc config winrm start= auto 34 | cmd.exe /c net start winrm 35 | 36 | -------------------------------------------------------------------------------- /tests/BambooInstalled.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe 'Bamboo Server installation' { 2 | It 'creates the installation directory' { 3 | Test-Path "C:\Program Files\Bamboo" | Should be $true 4 | } 5 | 6 | It 'creates the Home directory' { 7 | Test-Path "C:\Users\Administrator\Bamboo-home" | Should be $true 8 | } 9 | 10 | It 'sets up the Service' { 11 | Get-Service "bamboo" | Should be $true 12 | } 13 | 14 | It 'creates the inbound firewall rule' { 15 | Get-NetFirewallRule -Name "Bamboo Server" | Should Not BeNullOrEmpty 16 | } 17 | } -------------------------------------------------------------------------------- /tests/DevToolsInstalled.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe 'Dev Tools installation' { 2 | It 'installs nuget' { 3 | { Get-Command "nuget.exe" -ErrorAction Stop } | Should Not Throw 4 | } 5 | 6 | It 'installs nunit' { 7 | { Get-Command "nunit3-console.exe" -ErrorAction Stop } | Should Not Throw 8 | } 9 | 10 | It 'installs git' { 11 | { Get-Command "git" -ErrorAction Stop } | Should Not Throw 12 | } 13 | } -------------------------------------------------------------------------------- /tests/MSBuild14Installed.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe 'Dev Tools Installer' { 2 | It 'installs Framework .Net 4.5.2 or newer' { 3 | Test-Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" | Should be $true 4 | 5 | $key = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" 6 | $key.Release | Should BeGreaterThan 378758 #378758 is .net 4.5.1 7 | } 8 | 9 | It 'ensure MSBuild 14 is present at the expected location' { 10 | Test-Path "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" | Should be $true 11 | } 12 | } --------------------------------------------------------------------------------