diff --git a/config.json.example b/config.json.example index 30f9cc6..e8b82d4 100644 --- a/config.json.example +++ b/config.json.example @@ -15,5 +15,5 @@ "nginx_conf": "path_to/conf.d", "admin_url": "admin_url.headshed.dev", "preview_url": "app-prv.headshed.dev", - "ui_url": "ww2.headshed.dev", + "ui_url": "ww2.headshed.dev" } \ No newline at end of file diff --git a/vagrant/dev/ubuntu/Vagrantfile b/vagrant/dev/ubuntu/Vagrantfile index b813bce..fa3f41c 100644 --- a/vagrant/dev/ubuntu/Vagrantfile +++ b/vagrant/dev/ubuntu/Vagrantfile @@ -34,7 +34,7 @@ Vagrant.configure("2") do |config| end vm1.vm.provider "virtualbox" do |vb| - vb.memory = "4096" # 4GB memory + vb.memory = "2048" # 4GB memory vb.cpus = 2 end @@ -61,7 +61,11 @@ Vagrant.configure("2") do |config| end vm2.vm.provider "virtualbox" do |vb| +<<<<<<< HEAD vb.memory = "4096" # 4GB memory +======= + vb.memory = "2048" # 4GB memory +>>>>>>> 8396e72 (update: Added Longhorn installation process and updated memory allocation for VMs) vb.cpus = 2 end @@ -88,7 +92,11 @@ Vagrant.configure("2") do |config| end vm3.vm.provider "virtualbox" do |vb| +<<<<<<< HEAD vb.memory = "4096" # 4GB memory +======= + vb.memory = "2048" # 4GB memory +>>>>>>> 8396e72 (update: Added Longhorn installation process and updated memory allocation for VMs) vb.cpus = 2 end diff --git a/vagrant/dev/ubuntu/ansible/provision_workstation.sh b/vagrant/dev/ubuntu/ansible/provision_workstation.sh index 2d95d67..9448b09 100644 --- a/vagrant/dev/ubuntu/ansible/provision_workstation.sh +++ b/vagrant/dev/ubuntu/ansible/provision_workstation.sh @@ -8,10 +8,17 @@ sudo -u vagrant mkdir -p /home/vagrant/.ansible sudo -u vagrant touch /home/vagrant/.ansible/ansible.cfg # Create workspace and SSH directories -sudo -u vagrant mkdir -p /home/vagrant/ansible sudo -u vagrant mkdir -p /home/vagrant/.ssh sudo chmod 700 /home/vagrant/.ssh +# create directories and copy files to /home/vagrant +mkdir -p /home/vagrant/{ansible,scripts,pipelines,k8s} +sudo cp -r /vagrant/ansible/* /home/vagrant/ansible/ +sudo cp -r /vagrant/scripts/* /home/vagrant/scripts/ +sudo cp -r /vagrant/pipelines/* /home/vagrant/pipelines +sudo cp -r /vagrant/k8s/* /home/vagrant/k8s +sudo chmod +x /home/vagrant/pipelines/*.sh + # Copy the Vagrant private keys (these will be synced by Vagrant) for i in {1..3}; do sudo -u vagrant cp /vagrant/.vagrant/machines/vm$i/virtualbox/private_key /home/vagrant/.ssh/vm${i}_key @@ -81,7 +88,6 @@ if [ $? -ne 0 ]; then exit 1 fi -cp -r /vagrant/ansible/* /home/vagrant/ansible/ eval `ssh-agent -s` ssh-add # ~/machines/*/virtualbox/private_key @@ -144,4 +150,11 @@ if [ $? -ne 0 ]; then exit 1 fi +# check infctl +cd /home/vagrant +bash /home/vagrant/scripts/check_install_infctl.sh +if [ $? -ne 0 ]; then + echo "infctl check failed. Please check your installation." + exit 1 +fi diff --git a/vagrant/dev/ubuntu/pipelines/vagrant-longhorn.json b/vagrant/dev/ubuntu/pipelines/vagrant-longhorn.json new file mode 100644 index 0000000..85e4322 --- /dev/null +++ b/vagrant/dev/ubuntu/pipelines/vagrant-longhorn.json @@ -0,0 +1,29 @@ +[ + { + "name": "Install Longhorn pre-requisites", + "function": "RunCommand", + "params": [ + "./scripts/longhorn_prereqs.sh" + ], + "retryCount": 0, + "shouldAbort": true + }, + { + "name": "Install Longhorn", + "function": "RunCommand", + "params": [ + "./scripts/install_longhorn.sh" + ], + "retryCount": 0, + "shouldAbort": true + }, + { + "name": "Wait for Longhorn pods to come up", + "function": "RunCommand", + "params": [ + "./scripts/wait_for_longhorn.sh" + ], + "retryCount": 10, + "shouldAbort": true + } +] \ No newline at end of file diff --git a/vagrant/dev/ubuntu/scripts/check_install_infctl.sh b/vagrant/dev/ubuntu/scripts/check_install_infctl.sh new file mode 100755 index 0000000..fb7f66f --- /dev/null +++ b/vagrant/dev/ubuntu/scripts/check_install_infctl.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# function to install infctl +install_infctl() { + echo "Installing infctl..." + # Add installation commands here + curl -L https://codeberg.org/headshed/infctl-cli/raw/branch/main/install.sh | bash + +} + +if ! command -v infctl &> /dev/null +then + echo "infctl could not be found, installing..." + install_infctl +fi + +# base.json.example config.json.example + +# https://codeberg.org/headshed/infctl-cli/raw/branch/main/base.json.example + +# https://codeberg.org/headshed/infctl-cli/raw/branch/main/config.json.example + +if [ ! -f "base.json" ]; then + echo "base.json not found in home directory, downloading..." + curl -o "base.json" https://codeberg.org/headshed/infctl-cli/raw/branch/main/base.json.example +fi + +if [ ! -f "config.json" ]; then + echo "config.json not found in home directory, downloading..." + curl -o "config.json" https://codeberg.org/headshed/infctl-cli/raw/branch/main/config.json.example +fi + + + +echo "infctl is installed and ready to use." diff --git a/vagrant/dev/ubuntu/scripts/install_longhorn.sh b/vagrant/dev/ubuntu/scripts/install_longhorn.sh new file mode 100755 index 0000000..51c565e --- /dev/null +++ b/vagrant/dev/ubuntu/scripts/install_longhorn.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +echo +echo "vagrant longhorn installation" +echo + +ssh-add ~/.ssh/vm*_key +source /home/vagrant/ansible/venv/bin/activate +# Check if there are any pods in the longhorn-system namespace +if kubectl -n longhorn-system get pods --no-headers 2>/dev/null | grep -q '^[^ ]'; then + echo "Pods already exist in the longhorn-system namespace. Skipping installation." + exit 0 +fi +# https://github.com/longhorn/longhorn/releases +# v1.8.1 in prod 1.9.1 is latest +LONGHORN_RELEASE="v1.8.1" +LONGHORN_RELEASE_URL="https://raw.githubusercontent.com/longhorn/longhorn/$LONGHORN_RELEASE/deploy/longhorn.yaml" + +echo "Applying Longhorn release $LONGHORN_RELEASE..." +echo "Using Longhorn release URL: $LONGHORN_RELEASE_URL" + +kubectl apply -f $LONGHORN_RELEASE_URL diff --git a/vagrant/dev/ubuntu/scripts/longhorn_prereqs.sh b/vagrant/dev/ubuntu/scripts/longhorn_prereqs.sh new file mode 100755 index 0000000..9e00ade --- /dev/null +++ b/vagrant/dev/ubuntu/scripts/longhorn_prereqs.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +echo +echo "vagrant longhorn prerequisites" +echo + +ssh-add ~/.ssh/vm*_key +source /home/vagrant/ansible/venv/bin/activate +ANSIBLE_SUPPRESS_INTERPRETER_DISCOVERY_WARNING=1 ANSIBLE_HOST_KEY_CHECKING=False ansible --inventory-file /home/vagrant/ansible/ansible_inventory.ini -m ping vm1,vm2,vm3 +if [ $? -ne 0 ]; then + echo "Ansible ping failed. Please check your Vagrant VMs and network configuration." + exit 1 +fi +echo "Ansible ping successful." + +# Check if there are any pods in the longhorn-system namespace +if kubectl -n longhorn-system get pods --no-headers 2>/dev/null | grep -q '^[^ ]'; then + echo "Pods already exist in the longhorn-system namespace. Skipping installation." + exit 0 +fi + +exit + +echo "Installing Longhorn prerequisites..." + + +# install_longhorn_prereqs.yaml +ANSIBLE_SUPPRESS_INTERPRETER_DISCOVERY_WARNING=1 ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook ~/ansible/install_longhorn_prereqs.yaml --inventory-file /home/vagrant/ansible/ansible_inventory.ini +if [ $? -ne 0 ]; then + echo "Ansible playbook failed. Please check the playbook and your inventory." + exit 1 +fi diff --git a/vagrant/dev/ubuntu/scripts/wait_for_longhorn.sh b/vagrant/dev/ubuntu/scripts/wait_for_longhorn.sh new file mode 100755 index 0000000..b07aa3b --- /dev/null +++ b/vagrant/dev/ubuntu/scripts/wait_for_longhorn.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +echo +echo "wait for longhorn installation" +echo + +ssh-add ~/.ssh/vm*_key +source /home/vagrant/ansible/venv/bin/activate +while true; do + not_ready=$(kubectl -n longhorn-system get pods --no-headers 2>/dev/null | grep -vE 'Running|Completed' | wc -l) + total=$(kubectl -n longhorn-system get pods --no-headers 2>/dev/null | wc -l) + if [[ $total -gt 0 && $not_ready -eq 0 ]]; then + echo "All Longhorn pods are ready." + break + fi + sleep 10 +done