Server now pops up with ansible. Removed packer entirely

This commit is contained in:
spengreb 2022-02-13 23:07:02 +01:00
parent 25001c88f7
commit 59ae5328a7
7 changed files with 11 additions and 111 deletions

View file

@ -1,26 +1,13 @@
image:
name: hashicorp/packer:latest
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
name: hashicorp/terraform:latest
before_script:
- packer --version
- terraform --version
stages:
- validate
- build
validate:
stage: validate
script:
- find . -maxdepth 1 -name '*.json' -print0 | xargs -t0n1 packer validate
build:
stage: build
environment: production
script:
- ./build.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
when: manual
only:
- master
- validate

View file

@ -1,46 +0,0 @@
{
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "eu-central-1",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "ubuntu/images/*ubuntu-focal-20.04-amd64-server-*",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
},
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "Jamulus-{{timestamp}}",
"launch_block_device_mappings": [{
"device_name":"/dev/sda1",
"volume_size":100,
"volume_type":"gp2",
"encrypted":false,
"delete_on_termination":true
}],
"tags": {
"Name": "jamulus-{{timestamp}}"
}
}],
"provisioners": [
{
"type": "file",
"source": "payload/init.d/node_exporter.service",
"destination": "/tmp/node_exporter.service"
},
{
"type": "file",
"source": "payload/init.d/jamulus.service",
"destination": "/tmp/jamulus.service"
},
{
"type": "shell",
"script": "scripts/deps.sh"
}
]
}

2
dns.tf
View file

@ -7,8 +7,6 @@ terraform {
}
}
variable "do_token" {}
provider "digitalocean" {
token = var.do_token
}

26
main.tf
View file

@ -13,14 +13,12 @@ terraform {
resource "aws_instance" "jamulus" {
ami = "${data.aws_ami.image.id}"
instance_type = "c5.large"
instance_type = "t3.small"
key_name = "jamulus"
security_groups = [ aws_security_group.ssh.name, aws_security_group.jamulus.name, aws_security_group.node-exporter.name ] # Add your own IP to this group
provisioner "file" {
source = "scripts/server-start.sh"
destination = "/tmp/server-start.sh"
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Done!"]
connection {
type = "ssh"
user = "ubuntu"
@ -29,18 +27,8 @@ resource "aws_instance" "jamulus" {
}
}
provisioner "remote-exec" {
inline = [
"sleep 45",
"chmod +x /tmp/server-start.sh",
"/tmp/server-start.sh"
]
connection {
type = "ssh"
user = "ubuntu"
host = self.public_ip
private_key = file("${path.module}/jamulus.pem")
}
provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u ubuntu -i '${self.public_ip},' --private-key ${"${path.module}/jamulus.pem"} jamulus-install.yml"
}
tags = {
@ -50,10 +38,10 @@ resource "aws_instance" "jamulus" {
data "aws_ami" "image" {
most_recent = true
owners = ["self"]
owners = ["099720109477"]
filter {
name = "name"
values = ["Jamulus-*"]
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
}

View file

@ -16,7 +16,7 @@ IOSchedulingPriority=0
#### Change this to publish this server, set genre, location and other parameters.
#### See https://jamulus.io/wiki/Command-Line-Options ####
ExecStart=/bin/sh -c 'exec /usr/bin/jamulus-headless -s -n -o "VerethanE;Falkenstein;224" -w "Welcome to Vereto Private" -T -F'
ExecStart=/bin/sh -c 'exec /usr/bin/jamulus-headless -s -n -w "Welcome to Vereto Private" -T -F -o "VerethanE;Falkenstein;224"'
Restart=on-failure

View file

@ -1,22 +0,0 @@
#!/bin/bash -ex
# apt Deps
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt dist-upgrade -y
sudo apt-get install -y libqt5core5a libqt5network5 libqt5xml5
# Prometheus Setup
wget -O /tmp/node_exporter.tar.gz https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
tar xvzf /tmp/node_exporter.tar.gz -C /tmp/
sudo cp /tmp/node_exporter-1.2.2.linux-amd64/node_exporter /usr/local/bin/
sudo mv /tmp/node_exporter.service /lib/systemd/system/
# Jamulus Setup
sudo useradd -m -s /bin/bash jam
wget -O /tmp/jamulus_headless_3.8.0_ubuntu_amd64.deb https://github.com/jamulussoftware/jamulus/releases/download/r3_8_0/jamulus_headless_3.8.0_ubuntu_amd64.deb
sudo dpkg -i /tmp/jamulus_headless_3.8.0_ubuntu_amd64.deb
sudo mv /tmp/jamulus.service /lib/systemd/system/
# Enable Services
sudo systemctl daemon-reload
sudo systemctl enable jamulus-headless.service
sudo systemctl enable node_exporter.service

View file

@ -1,5 +0,0 @@
#!/bin/bash -xe
sudo systemctl start jamulus-headless.service
sudo systemctl start node_exporter.service