· 7 years ago · May 14, 2018, 09:30 PM
1$sourcePath = $OctopusParameters["Octopus.Action.Package.InstallationDirectoryPath"]
2$destinationPath = $TradingWebSiteZipFullPath
3
4Write-Host "Cleaning up previous zip files"
5Remove-Item "$ZipRootDirectory*.zip"
6
7Write-Host "Compressing $sourcePath to $destinationPath"
8Compress-Archive -Path "$sourcePath*" -DestinationPath $destinationPath -Force
9
10$params = @{}
11
12#Initialises the S3 Credentials based on the Access Key and Secret Key provided, so that we can invoke the APIs further down
13Set-AWSCredentials -AccessKey $AwsAccessKey -SecretKey $AwsAccessSecret -StoreAs S3Creds
14
15#Initialises the Default AWS Region based on the region provided
16Set-DefaultAWSRegion -Region $AwsRegion
17
18#Gets all relevant files and uploads them
19function Upload($item)
20{
21 #Gets all files and child folders within the given directory
22 foreach ($i in Get-ChildItem $item) {
23 #Inserts file to AWS
24 Write-S3Object -ProfileName S3Creds -BucketName $S3BucketName -Key $($i.Name) -File $i.FullName @params
25 }
26}
27
28Upload($destinationPath)
29
30Write-Host "ApplicationName $AwsApplicationName"
31 Write-Host "DeploymentConfigName $AwsCodeDeployConfigName"
32 Write-Host "CodeDeployName $AwsCodeDeployGroupName"
33 Write-Host "BucketLocation $S3BucketName"
34 Write-Host "KeyName $TradingWebSiteZipFileName"
35
36 $fullyQualifiedBucket = "$S3BucketName-us-west-1"
37 Write-Host "Fully Qualified Bucket $fullyQualifiedBucket"
38
39 $deployment = aws deploy create-deployment --application-name $AwsApplicationName --deployment-config-name $AwsCodeDeployConfigName --deployment-group-name $AwsCodeDeployGroupName --s3-location bucket=$S3BucketName,bundleType=zip,key=$TradingWebSiteZipFileName
40 Write-Host "Deployment info $deployment"