Add lutim_startup.sh

This commit is contained in:
arunodhayamsam
2022-05-13 10:38:08 +05:30
parent 21b592cb51
commit 5db403f040
7 changed files with 187 additions and 28 deletions
+1 -1
View File
@@ -4,4 +4,4 @@ An ansible role deploy the application on host machine(Ubuntu 20.04)
## terraform-aws-lutim
A terraform plan creates necessary AWS infrastructure and deploy the lutim. This terraform plan uses the above ansible roles `ansible-role-lutim` to configure the application on AWS.
A terraform plan creates necessary AWS infrastructure and deploy the lutim. This terraform plan uses the `lutim_startup.sh` script to deploy lufi on AWS and also uses above ansible role `ansible-role-lutim` to configure the application on AWS.
+74
View File
@@ -16,3 +16,77 @@
| `aws_access_key` | AWSACCESSKEY | Enter your aws access key |
| `aws_secrete_key` | AWSSECRETEKEY | Enter your aws secrete key |
| `instance_name` | lutim_app_instance | Set the name for instance |
| `app_dir` | /var/www/lutim | Set the application directory for the best practice |
| `lutim_owner` | www-data | Set the application user for the best practice |
| `lutim_group` | www-data | Set the application group for the best practice |
| `contact` | contact.example.com | Contact option (mandatory), where you have to put some way for the users to contact you. |
| `contact_user` | name | Name of the user |
| `secrets` | ffyg7kbkjba | Secrets option (mandotory), which is array of random string. Used by Mojolicious for encrypting session cookies |
| `app_dir` | /var/www/lutim | Set the application directory for the best practice |
| `lutim_owner` | www-data | Set the application user for the best practice |
| `lutim_group` | www-data | Set the application group for the best practice |
| `contact` | contact.example.com | Contact option (mandatory), where you have to put some way for the users to contact you. |
| `contact_user` | name | Name of the user |
| `secrets` | ffyg7kbkjba | Secrets option (mandotory), which is array of random string. Used by Mojolicious for encrypting session cookies |
## Usage of terraform plan with lufi deploy script
```sh
git clone https://framagit.org/fiat-tux/hat-softwares/lutim.git
cd lutim/.provision/terraform-aws-lutim
terraform init
terraform plan
terraform apply
```
## Usage of terraform plan with ansible role
- Comment out the below `locals` and `user_data` source in __main.tf__ file
```hcl
locals {
user_data_vars = {
user = var.lutim_owner
group = var.lutim_group
directory = var.app_dir
contact_user = var.contact_user
contact_lutim = var.contact
secret_lutim = var.secret
}
}
```
```hcl
user_data = templatefile("${path.module}/lutim_startup.sh", local.user_data_vars)
```
- Add the below provisioner data in __main.tf__ file at the `aws_instance` resource
```sh
connection {
agent = false
type = "ssh"
host = aws_instance.ec2_instance.public_dns
private_key = "${file(var.private_key)}"
user = "${var.user}"
}
provisioner "remote-exec" {
inline = [
"sudo apt update -y",
"sudo apt install python3.9 -y",
]
}
provisioner "local-exec" {
command = <<EOT
sleep 120 && \
> hosts && \
echo "[Lutim]" | tee -a hosts && \
echo "${aws_instance.ec2_instance.public_ip} ansible_user=${var.user} ansible_ssh_private_key_file=${var.private_key}" | tee -a hosts && \
export ANSIBLE_HOST_KEY_CHECKING=False && \
ansible-playbook -u ${var.user} --private-key ${var.private_key} -i hosts site.yml
EOT
}
```
@@ -0,0 +1,66 @@
#!/bin/bash
echo "**********************************************************************"
echo " *"
echo "Install dependencies *"
echo " *"
echo "**********************************************************************"
SUDO=sudo
$SUDO apt update
$SUDO apt install jq -y
$SUDO apt install wget -y
$SUDO apt install unzip
$SUDO apt install carton -y
$SUDO apt install build-essential -y
$SUDO apt install nginx -y
$SUDO apt install libssl-dev -y
$SUDO apt install libio-socket-ssl-perl -y
$SUDO apt install liblwp-protocol-https-perl -y
$SUDO apt install zlib1g-dev -y
$SUDO apt install libmojo-sqlite-perl -y
$SUDO apt install libpq-dev -y
echo "**********************************************************************"
echo " *"
echo "Configuring the Application *"
echo " *"
echo "**********************************************************************"
sleep 10;
version=$(curl -s https://framagit.org/api/v4/projects/1/releases | jq '.[]' | jq -r '.name' | head -1)
echo $version
pushd ${directory}
$SUDO wget https://framagit.org/fiat-tux/hat-softwares/lutim/-/archive/$version/lutim-$version.zip
$SUDO unzip lutim-$version.zip
$SUDO chown ${user} lutim-$version
$SUDO chgrp ${group} lutim-$version
pushd lutim-$version
echo "**********************************************************************"
echo " *"
echo "Install Carton Packages *"
echo " *"
echo "**********************************************************************"
$SUDO carton install --deployment --without=test --without=sqlite --without=mysql
sleep 10;
$SUDO cp lutim.conf.template lutim.conf
sed -i 's/127.0.0.1/0.0.0.0/' lutim.conf
sed -i 's/#contact/contact/g' lutim.conf
sed -i "s/John Doe/${contact_user}/g" lutim.conf
sed -i "s/admin[at]example.com/${contact_lutim}/g" lutim.conf
sed -i "s/fdjsofjoihrei/${secret_lutim}/g" lutim.conf
sed -i '153 , 158 s/#/ /g' lutim.conf
echo "**********************************************************************"
echo " *"
echo "Run the Application *"
echo " *"
echo "**********************************************************************"
$SUDO carton exec hypnotoad script/lutim
+12 -26
View File
@@ -1,3 +1,14 @@
locals {
user_data_vars = {
user = var.lutim_owner
group = var.lutim_group
directory = var.app_dir
contact_user = var.contact_user
contact_lutim = var.contact
secret_lutim = var.secret
}
}
#Create the VPC
resource "aws_vpc" "vpc" {
cidr_block = "${var.vpc_cidr}"
@@ -100,33 +111,8 @@ resource "aws_instance" "ec2_instance" {
associate_public_ip_address = "true"
subnet_id = "${aws_subnet.publicsubnet.id}"
vpc_security_group_ids = ["${aws_security_group.security.id}"]
user_data = templatefile("${path.module}/lutim_startup.sh", local.user_data_vars)
key_name = "lutim.webapp"
connection {
agent = false
type = "ssh"
host = aws_instance.ec2_instance.public_dns
private_key = "${file(var.private_key)}"
user = "${var.user}"
}
provisioner "remote-exec" {
inline = [
"sudo apt update -y",
"sudo apt install python3.9 -y",
]
}
provisioner "local-exec" {
command = <<EOT
sleep 120 && \
> hosts && \
echo "[lutim]" | tee -a hosts && \
echo "${aws_instance.ec2_instance.public_ip} ansible_user=${var.user} ansible_ssh_private_key_file=${var.private_key}" | tee -a hosts && \
export ANSIBLE_HOST_KEY_CHECKING=False && \
ansible-playbook -u ${var.user} --private-key ${var.private_key} -i hosts site.yml
EOT
}
tags = {
Name = "${var.instance_name}"
+1 -1
View File
@@ -3,5 +3,5 @@ output "public_ip" {
}
output "App_running_at" {
value = "http://${aws_instance.ec2_instance.public_ip}:8081"
value = "http://${aws_instance.ec2_instance.public_ip}:8080"
}
@@ -1,3 +1,12 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
+24
View File
@@ -33,4 +33,28 @@ variable "instance_name" {
default = "instance_name"
}
variable "lutim_owner" {
default = ""
}
variable "lutim_group" {
default = ""
}
variable "app_dir" {
default = ""
}
variable "contact_user" {
default = ""
}
variable "contact" {
default = ""
}
variable "secret" {
default = ""
}