Adding self installation command for fabrica

This commit is contained in:
Philippe Caseiro 2021-03-23 10:47:39 +01:00
parent 740a8de4a2
commit 3851c247a3
4 changed files with 104 additions and 31 deletions

View File

@ -0,0 +1,5 @@
location /fabrica/ {
alias %%ROOT%%/images/;
autoindex on;
allow all;
}

View File

@ -1,17 +0,0 @@
location /factory/ {
alias /srv/factory/images/;
autoindex on;
allow 192.168.10.0/24;
allow 192.168.5.0/24;
deny all;
}
location /factory/images/cadoles/ {
alias /srv/factory/images/cadoles/;
autoindex on;
allow 192.168.5.10;
allow 192.168.5.11;
allow 192.168.5.12;
allow 192.168.5.13;
allow 192.168.10.177/24;
deny all;
}

109
fabrica
View File

@ -4,6 +4,8 @@ WORKDIR="./terraform"
TERRA="terraform"
PACKER_ROOT="./packer"
[ -f /etc/lsb-release ] && source /etc/lsb-release
# FIXME
function needGitPull()
{
@ -12,6 +14,85 @@ function needGitPull()
return ${diff}
}
## Install & Uninstall ##
function install_hashicorp_tools()
{
if [[ ${DISTRIB_ID} == "ManjaroLinux" ]]
then
pacman -Syq terraform packer --noconfirm
return ${?}
elif [[ ${DISTRIB_ID} == "Ubuntu" ]]
then
gpg_key_url="https://apt.releases.hashicorp.com/gpg"
curl -fsSL ${gpg_key_url} | apt-key add -
apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
apt-get update
apt-get -y install terraform packer
return ${?}
fi
}
function setup_nginx()
{
root=${1}
if [ -d /etc/nginx/web.d ]
then
sed -i -e "s!%%ROOT%%!${root}!g" ${root}/configs/nginx/fabrica.conf
ln -s ${root}/configs/nginx/fabrica.conf /etc/nginx/web.d/
echo "Don't forget to restart nginx"
fi
return 0
}
function install_fabrica()
{
root=${1}
[ ! -d ${root} ] && mkdir -p $root
cp -rp * ${root}
return ${?}
}
function install()
{
ROOT=${2}
ret=0
if [[ -z ${ROOT} ]]
then
echo "You need to provide an installation directory as paramter"
echo "./fabrica install /srv/fabrica"
return 1
fi
if [[ -e ${ROOT}/.ist ]]
then
echo "Flag file ${ROOT}/.ist exists !"
echo " ==> Fabrica is allready installed !"
echo "Nothing to do !"
return 0
fi
install_hashicorp_tools
ret=$((ret+${?}))
install_fabrica ${ROOT}
ret=$((ret+${?}))
setup_nginx ${ROOT}
ret=$((ret+${?}))
if [ ${ret} -eq 0 ]
then
touch ${ROOT}/.ist
fi
return ${ret}
}
## TERRAFORM ##
# Run Terraform command with the correct options
function trun()
{
#needGitPull
@ -37,24 +118,28 @@ function trun()
return ${res}
}
# Run terraform plan
function plan()
{
trun plan
return $?
}
# Run terraform apply
function apply()
{
trun apply
return $?
}
# Run terraform destroy
function destroy()
{
trun destroy
return $?
}
# Run terraform taint
function taint()
{
target=$1
@ -62,33 +147,38 @@ function taint()
cd ${WORKDIR}
$TERRA taint module.${resource}.opennebula_template.vm_template
$TERRA taint module.${resource}.opennebula_virtual_machine.vm
$TERRA taint module.${resource}.opennebula_image.system
$TERRA taint module.vms[${resource}].opennebula_template.vm_template
$TERRA taint module.vms[${resource}].opennebula_virtual_machine.vm
$TERRA taint module.vms[${resource}].opennebula_image.system
cd -
}
# Run terraform taint for all resources
function taint_all()
{
target=$1
resource=$2
cd ${WORKDIR}
$TERRA taint module.${resource}.opennebula_template.vm_template
$TERRA taint module.${resource}.opennebula_virtual_machine.vm
$TERRA taint module.${resource}.opennebula_image.system
$TERRA taint module.${resource}.opennebula_image.data
$TERRA taint module.vms[${resource}].opennebula_template.vm_template
$TERRA taint module.vms[${resource}].opennebula_virtual_machine.vm
$TERRA taint module.vms[${resource}].opennebula_image.system
$TERRA taint module.vms[${resource}].opennebula_image.data
cd -
}
# Run terraform init
function init()
{
trun init
return ${?}
}
## PACKER ##
# Run packer build
function build()
{
target=$2
@ -98,11 +188,6 @@ function build()
return ${?}
}
function publish()
{
target=$2
echo "FIXME for publish"
}
$1 $@
exit ${?}

View File

@ -16,7 +16,7 @@ virtual_machines = {
disks = {
system = {
name = "prod-amon-static",
source = "http://localhost/fabrica/infra/production/amon.fabrica.local/system/amon.fabrica.local"
source = "http://localhost/fabrica/infra/production/amon.fabrica.local/system/amon.fabrica.local.img"
}
}
depends = [ "internet" ]
@ -37,7 +37,7 @@ virtual_machines = {
disks = {
system = {
name = "prod-scribe-static",
source = "http://localhost/fabrica/infra/production/scribe.fabrica.local/system/scribe.fabrica.local"
source = "http://localhost/fabrica/infra/production/scribe.fabrica.local/system/scribe.fabrica.local.img"
}
}
depends = [ "internet" ]