update config files to support systemd and Azure; reorganize Packer file hierarchy; update Vagrantfile to use latest tool versions

This commit is contained in:
Rob Genova
2017-11-15 19:31:46 +00:00
parent f41fac333c
commit 042ee76e3a
14 changed files with 84 additions and 137 deletions

View File

@@ -8,14 +8,20 @@ Vagrant.configure(2) do |config|
cd /tmp
PACKERVERSION=1.0.0
PACKERVERSION=1.1.1
PACKERDOWNLOAD=https://releases.hashicorp.com/packer/${PACKERVERSION}/packer_${PACKERVERSION}_linux_amd64.zip
TERRAFORMVERSION=0.9.8
TERRAFORMVERSION=0.10.8
TERRAFORMDOWNLOAD=https://releases.hashicorp.com/terraform/${TERRAFORMVERSION}/terraform_${TERRAFORMVERSION}_linux_amd64.zip
echo "Dependencies..."
sudo apt-get install -y unzip tree
# Azure CLI
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893
sudo apt-get install apt-transport-https
sudo apt-get update && sudo apt-get install azure-cli
# Disable the firewall
sudo ufw disable
@@ -43,9 +49,10 @@ Vagrant.configure(2) do |config|
SHELL
config.vm.synced_folder "../aws/", "/home/vagrant/aws", owner: "vagrant", group: "vagrant"
config.vm.synced_folder "../shared/", "/home/vagrant/shared", owner: "vagrant", group: "vagrant"
config.vm.synced_folder "../examples/", "/home/vagrant/examples", owner: "vagrant", group: "vagrant"
config.vm.synced_folder "aws/", "/home/vagrant/aws", owner: "vagrant", group: "vagrant"
config.vm.synced_folder "azure/", "/home/vagrant/azure", owner: "vagrant", group: "vagrant"
config.vm.synced_folder "shared/", "/home/vagrant/shared", owner: "vagrant", group: "vagrant"
config.vm.synced_folder "examples/", "/home/vagrant/examples", owner: "vagrant", group: "vagrant"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"

View File

@@ -5,7 +5,7 @@
"source_ami": "ami-80861296",
"instance_type": "t2.medium",
"ssh_username": "ubuntu",
"ami_name": "nomad-packer {{timestamp}}",
"ami_name": "hashistack {{timestamp}}",
"ami_groups": ["all"]
}],
"provisioners": [
@@ -18,16 +18,16 @@
},
{
"type": "file",
"source": "../../shared",
"source": "../shared",
"destination": "/ops"
},
{
"type": "file",
"source": "../../examples",
"source": "../examples",
"destination": "/ops"
},
{
"type": "shell",
"script": "../../shared/scripts/setup.sh"
"script": "../shared/scripts/setup.sh"
}]
}

View File

@@ -1,31 +0,0 @@
# Build an Amazon machine image with Packer
[Packer](https://www.packer.io/intro/index.html) is HashiCorp's open source tool
for creating identical machine images for multiple platforms from a single
source configuration. The Terraform templates included in this repo reference a
publicly avaialble Amazon machine image (AMI) by default. The Packer build
configuration used to create the public AMI is included [here](./packer.json).
If you wish to customize it and build your own private AMI, follow the
instructions below.
## Pre-requisites
See the pre-requisites listed [here](../../README.md). If you did not use the
included `Vagrantfile` to bootstrap a staging environment, you will need to
[install Packer](https://www.packer.io/intro/getting-started/install.html).
Set environment variables for your AWS credentials if you haven't already:
```bash
$ export AWS_ACCESS_KEY_ID=[ACCESS_KEY_ID]
$ export AWS_SECRET_ACCESS_KEY=[SECRET_ACCESS_KEY]
```
After you make your modifications to `packer.json`, execute the following
command to build the AMI:
```bash
$ packer build packer.json
```
Don't forget to copy the AMI ID to your [terraform.tfvars file](../env/us-east/terraform.tfvars).

View File

@@ -18,9 +18,9 @@
"image_sku": "16.04-LTS",
"os_type": "Linux",
"ssh_username": "packer",
"managed_image_name": "nomad",
"managed_image_name": "hashistack",
"azure_tags": {
"Product": "Consul"
"Product": "Hashistack"
}
}],
"provisioners": [
@@ -33,17 +33,17 @@
},
{
"type": "file",
"source": "../../shared",
"source": "../shared",
"destination": "/ops"
},
{
"type": "file",
"source": "../../examples",
"source": "../examples",
"destination": "/ops"
},
{
"type": "shell",
"script": "../../shared/scripts/setup.sh"
"script": "../shared/scripts/setup.sh"
},
{
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Consul Agent
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
Environment=CONSUL_ALLOW_PRIVILEGED_PORTS=true
ExecStart=/usr/local/bin/consul agent -config-dir="/etc/consul.d" -dns-port="53" -recursor="172.31.0.2"
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGTERM
User=root
Group=root
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Consul Agent
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
Environment=CONSUL_ALLOW_PRIVILEGED_PORTS=true
ExecStart=/usr/local/bin/consul agent -config-dir="/etc/consul.d" -dns-port="53" -recursor="168.63.129.16"
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGTERM
User=root
Group=root
[Install]
WantedBy=multi-user.target

View File

@@ -1,24 +0,0 @@
description "Consul"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
console log
script
if [ -f "/etc/service/consul" ]; then
. /etc/service/consul
fi
# Allow Consul to use privileged ports
export CONSUL_ALLOW_PRIVILEGED_PORTS=true
exec /usr/local/bin/consul agent \
-config-dir="/etc/consul.d" \
-dns-port="53" \
-recursor="172.31.0.2" \
\$${CONSUL_FLAGS} \
>>/var/log/consul.log 2>&1
end script

View File

@@ -1,24 +0,0 @@
description "Consul"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
console log
script
if [ -f "/etc/service/consul" ]; then
. /etc/service/consul
fi
# Allow Consul to use privileged ports
export CONSUL_ALLOW_PRIVILEGED_PORTS=true
exec /usr/local/bin/consul agent \
-config-dir="/etc/consul.d" \
-dns-port="53" \
-recursor="168.63.129.16" \
\$${CONSUL_FLAGS} \
>>/var/log/consul.log 2>&1
end script

View File

@@ -7,8 +7,6 @@ server {
bootstrap_expect = SERVER_COUNT
}
name = "nomad@IP_ADDRESS"
consul {
address = "127.0.0.1:8500"
}

View File

@@ -0,0 +1,15 @@
[Unit]
Description=Nomad Agent
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/bin/nomad agent -config="/etc/nomad.d/nomad.hcl"
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGTERM
User=root
Group=root
[Install]
WantedBy=multi-user.target

View File

@@ -1,6 +1,5 @@
data_dir = "/opt/nomad/data"
bind_addr = "0.0.0.0"
name = "nomad@IP_ADDRESS"
# Enable the client
client {

View File

@@ -1,19 +0,0 @@
description "Nomad"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
console log
script
if [ -f "/etc/service/nomad" ]; then
. /etc/service/nomad
fi
exec /usr/local/bin/nomad agent \
-config="/etc/nomad.d/nomad.hcl" \
\$${NOMAD_FLAGS} \
>>/var/log/nomad.log 2>&1
end script

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Vault Agent
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
Environment=GOMAXPROCS=nproc
ExecStart=/usr/local/bin/vault server -config="/etc/vault.d/vault.hcl"
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGTERM
User=root
Group=root
[Install]
WantedBy=multi-user.target

View File

@@ -1,22 +0,0 @@
description "Vault"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
console log
script
if [ -f "/etc/service/vault" ]; then
. /etc/service/vault
fi
# Make sure to use all our CPUs, because Vault can block a scheduler thread
export GOMAXPROCS=`nproc`
exec /usr/local/bin/vault server \
-config="/etc/vault.d/vault.hcl" \
\$${VAULT_FLAGS} \
>>/var/log/vault.log 2>&1
end script