Skip to content

Commit

Permalink
Added packer and updated AMI info for CF scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
droyad committed Jul 17, 2017
1 parent e97e6d1 commit f41716c
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 4 deletions.
12 changes: 12 additions & 0 deletions AWS/CloudFormation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion AWS/DeployCloudFormation.ps1
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion AWS/UserData.sh
Original file line number Diff line number Diff line change
@@ -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%%"
7 changes: 5 additions & 2 deletions AzureFuctions/CreateTenant.csx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceW
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();

// 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);
Expand All @@ -22,13 +22,16 @@ public static async Task<HttpResponseMessage> 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()
{
Name = branchName,
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);

Expand Down
9 changes: 9 additions & 0 deletions AzureFuctions/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"frameworks": {
"net46":{
"dependencies": {
"Octopus.Client": "4.21.0"
}
}
}
}
33 changes: 33 additions & 0 deletions BuildAmi/WebServer.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
1 change: 1 addition & 0 deletions BuildAmi/build.ps1
Original file line number Diff line number Diff line change
@@ -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
Binary file added BuildAmi/packer.exe
Binary file not shown.
23 changes: 23 additions & 0 deletions BuildAmi/scripts/install-dotnet.sh
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 19 additions & 0 deletions BuildAmi/scripts/install-mono.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions HighestCommon/PostDeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
nohup dotnet HighestCommon.dll &

0 comments on commit f41716c

Please sign in to comment.