diff --git a/AWS/CloudFormation.json b/AWS/CloudFormation.json index 0e70e46..9b7140c 100644 --- a/AWS/CloudFormation.json +++ b/AWS/CloudFormation.json @@ -72,6 +72,18 @@ "CidrIp": "0.0.0.0/0" } }, + "ingress2": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Properties": { + "GroupId": { + "Ref": "sglaunchwizard1" + }, + "IpProtocol": "tcp", + "FromPort": "80", + "ToPort": "85", + "CidrIp": "0.0.0.0/0" + } + }, "egress1": { "Type": "AWS::EC2::SecurityGroupEgress", "Properties": { diff --git a/AWS/DeployCloudFormation.ps1 b/AWS/DeployCloudFormation.ps1 index ec2b9b5..f9bbf90 100644 --- a/AWS/DeployCloudFormation.ps1 +++ b/AWS/DeployCloudFormation.ps1 @@ -1,7 +1,8 @@ Param( [string]$tenant, [Parameter(Mandatory=$True)] [string]$stackName, - [Parameter(Mandatory=$True)] [string]$environment + [Parameter(Mandatory=$True)] [string]$environment, + [Parameter(Mandatory=$True)] [string]$ami ) $ErrorActionPreference = "Stop" @@ -39,6 +40,8 @@ function GetUserData($roles) { } $formation.Resources.AppServerInstance.Properties.UserData = GetUserData(@("App")) $formation.Resources.WebServerInstance.Properties.UserData = GetUserData(@("Web", "App")) +$formation.Resources.AppServerInstance.Properties.ImageId = $ami +$formation.Resources.WebServerInstance.Properties.ImageId = $ami ConvertTo-Json $formation -Depth 100 | Set-Content -Path $completedFormationName diff --git a/AWS/UserData.sh b/AWS/UserData.sh index fd07319..d84a891 100644 --- a/AWS/UserData.sh +++ b/AWS/UserData.sh @@ -1,6 +1,6 @@ #!/bin/bash hostname=`curl http://169.254.169.254/latest/meta-data/public-hostname` instanceid=`curl http://169.254.169.254/latest/meta-data/instance-id` -thumbprint=`ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub | egrep -o "[0-9a-f]+:[^ ]*"` +thumbprint=`ssh-keygen -E md5 -lf /etc/ssh/ssh_host_rsa_key.pub | grep -P -o "(?<=MD5:)[0-9a-f]+:[^ ]*"` curl https://droyad.gq/api/machines --header "X-Octopus-ApiKey:API-WNKDGUJOY857GW3A0ID7WQHC0" --data "%%registerRequest%%" \ No newline at end of file diff --git a/AzureFuctions/CreateTenant.csx b/AzureFuctions/CreateTenant.csx index 1e72e89..b91df9e 100644 --- a/AzureFuctions/CreateTenant.csx +++ b/AzureFuctions/CreateTenant.csx @@ -10,9 +10,9 @@ public static async Task Run(HttpRequestMessage req, TraceW // Get request body dynamic data = await req.Content.ReadAsAsync(); - // Extract github comment from request body + // Get the branch name string branchName = data["ref"]; - log.Info("Creating tentant " + branchName); + log.Info("Creating tenant " + branchName); var endpoint = new OctopusServerEndpoint("https://droyad.gq", Environment.GetEnvironmentVariable("ApiKey")); var repository = new OctopusRepository(endpoint); @@ -22,6 +22,8 @@ public static async Task Run(HttpRequestMessage req, TraceW repository.Environments.FindByName("Integration Test").Id }); var tenant = repository.Tenants.FindByName(branchName); + + // Create the tenant if it doesn't exist if (tenant == null) tenant = repository.Tenants.Create(new TenantResource() { @@ -29,6 +31,7 @@ public static async Task Run(HttpRequestMessage req, TraceW ProjectEnvironments = projects.ToDictionary(p => p.Id, p => environments) }); + // Update the logo using (var fs = File.OpenRead($@"{context.FunctionDirectory}\tennant.jpg")) repository.Tenants.SetLogo(tenant, "logo.jpg", fs); diff --git a/AzureFuctions/project.json b/AzureFuctions/project.json new file mode 100644 index 0000000..7af87f6 --- /dev/null +++ b/AzureFuctions/project.json @@ -0,0 +1,9 @@ +{ + "frameworks": { + "net46":{ + "dependencies": { + "Octopus.Client": "4.21.0" + } + } + } +} \ No newline at end of file diff --git a/BuildAmi/WebServer.json b/BuildAmi/WebServer.json new file mode 100644 index 0000000..1d25765 --- /dev/null +++ b/BuildAmi/WebServer.json @@ -0,0 +1,33 @@ +{ + "variables": { + "aws_access_key": "", + "aws_secret_key": "" + }, + "builders": [{ + "type": "amazon-ebs", + "access_key": "{{user `aws_access_key`}}", + "secret_key": "{{user `aws_secret_key`}}", + "region": "ap-southeast-2", + "source_ami_filter": { + "filters": { + "virtualization-type": "hvm", + "name": "*ubuntu-xenial-16.04-amd64-server-*", + "root-device-type": "ebs" + }, + "owners": ["099720109477"], + "most_recent": true + }, + "instance_type": "t2.micro", + "ssh_username": "ubuntu", + "ami_name": "integration-test-demo {{timestamp}}" + }], + "provisioners": [ + { + "scripts": [ + "scripts/install-mono.sh", + "scripts/install-dotnet.sh" + ], + "type": "shell" + } + ] +} \ No newline at end of file diff --git a/BuildAmi/build.ps1 b/BuildAmi/build.ps1 new file mode 100644 index 0000000..7260c19 --- /dev/null +++ b/BuildAmi/build.ps1 @@ -0,0 +1 @@ +.\packer build -var "aws_access_key=$env:AWS_ACCESS_KEY_ID" -var "aws_secret_key=$env:AWS_SECRET_ACCESS_KEY" .\WebServer.json \ No newline at end of file diff --git a/BuildAmi/packer.exe b/BuildAmi/packer.exe new file mode 100644 index 0000000..a5d6b3f Binary files /dev/null and b/BuildAmi/packer.exe differ diff --git a/BuildAmi/scripts/install-dotnet.sh b/BuildAmi/scripts/install-dotnet.sh new file mode 100644 index 0000000..2c0d390 --- /dev/null +++ b/BuildAmi/scripts/install-dotnet.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +COLOR_START="\033[01;34m" +COLOR_END="\033[00m" +MSG_TIME="${MSG_TIME:-30}" + +function show_msg() { + echo -e "${COLOR_START}${@}${COLOR_END}" +} + +show_msg "Adding dotnet repo" +sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list' || exit 1 +sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 || exit 1 + +show_msg "Running 'apt-get install aptitude'..." +sudo apt-get install aptitude -y || exit 1 + +show_msg "Updating aptitude" +sudo aptitude update || exit 1 + +show_msg "Installing dotnet" +sudo aptitude install dotnet-dev-1.0.4 --assume-yes || exit 1 + +show_msg "dotnet installation complete" diff --git a/BuildAmi/scripts/install-mono.sh b/BuildAmi/scripts/install-mono.sh new file mode 100644 index 0000000..7b51bdc --- /dev/null +++ b/BuildAmi/scripts/install-mono.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +COLOR_START="\033[01;34m" +COLOR_END="\033[00m" +MSG_TIME="${MSG_TIME:-30}" + +function show_msg() { + echo -e "${COLOR_START}${@}${COLOR_END}" +} + +show_msg "Adding mono repo" +sudo apt-key update || exit 1 +sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF || exit 1 +echo "deb http://download.mono-project.com/repo/debian wheezy/snapshots 4.6.0.245/main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list || exit 1 +sudo apt-get update || exit 1 + +show_msg "Installing mono 4.6.1" +sudo apt-get install mono-complete --yes --force-yes || exit 1 + +show_msg "Mono installation complete" \ No newline at end of file diff --git a/HighestCommon/PostDeploy.sh b/HighestCommon/PostDeploy.sh new file mode 100644 index 0000000..7aea20d --- /dev/null +++ b/HighestCommon/PostDeploy.sh @@ -0,0 +1,2 @@ +#!/bin/bash +nohup dotnet HighestCommon.dll & \ No newline at end of file