diff --git a/README.md b/README.md index 1d1143e..1b0743c 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,8 @@ cp pipeline.json.example pipeline.json # Run with pipeline file ./infctl-cli --deployment-file pipeline.json +# or using the short format +./infctl-cli -f pipeline.json--deployment-file ``` ## Configuration @@ -178,6 +180,8 @@ Run the CLI by providing a path to your pipeline JSON file: ```bash ./infctl-cli --deployment-file /path/to/pipeline.json +# or using the short format +./infctl-cli -f /path/to/pipeline.json ``` The tool will automatically: @@ -187,13 +191,20 @@ The tool will automatically: 3. Execute the deployment pipeline defined in your JSON file 4. Run scripts from the `scripts/` directory 5. Apply Kubernetes manifests using kustomize (for K8s deployments) +--deployment-file +### Command Line Options + +- `--deployment-file ` or `-f `: Path to the pipeline JSON configuration file +- `--help`: Show help message and usage information ### Running from Source You can also run directly with Go: ```bash -go run main.go -pipeline /path/to/pipeline.json +go run main.go --deployment-file /path/to/pipeline.json +# or using the short format +go run main.go -f /path/to/pipeline.json ``` ### Running Tests @@ -317,14 +328,14 @@ The CLI uses structured JSON logging. Debug logs are enabled by default and incl 1. Place shell scripts / executables in the `scripts/` directory 2. Add confiiguration as appropriate into `pipeline.json` -3. Re-run `cnfctl --deployment-file pipeline.json` +3. Re-run `infctl-cli --deployment-file pipeline.json` or `infctl-cli -f pipeline.json` ### Adding New Manifests 1. Create Kubernetes YAML files in the appropriate `k8s-manifests/` subdirectory 2. Include a `kustomization.yaml` file for kustomize processing 3. Add confiiguration as appropriate into `pipeline.json` -4. Re-run `cnfctl --deployment-file pipeline.json` +4. Re-run `infctl-cli --deployment-file pipeline.json` or `infctl-cli -f pipeline.json` ## Contributing diff --git a/pipelines/dev/vagrant-k3s.json b/pipelines/dev/vagrant-k3s.json index fdf476b..99a86b1 100644 --- a/pipelines/dev/vagrant-k3s.json +++ b/pipelines/dev/vagrant-k3s.json @@ -1,9 +1,31 @@ [ + { - "name": "pre-requisties", + "name": "Create Vagrant nodes", "function": "RunCommand", "params": [ - "./scripts/vagrant_check_prerequisites.sh" + "./scripts/install_vagrant_nodes.sh" + ], + "retryCount": 0, + "shouldAbort": true + }, + + { + "name": "Configure Vagrant K3s", + "function": "RunCommand", + "params": [ + "./scripts/configure_vagrant_k3s.sh" + ], + "retryCount": 0, + "shouldAbort": true + }, + + + { + "name": "Create Vagrant workstation", + "function": "RunCommand", + "params": [ + "./scripts/install_vagrant_workstation.sh" ], "retryCount": 0, "shouldAbort": true diff --git a/scripts/configure_vagrant_k3s.sh b/scripts/configure_vagrant_k3s.sh index b204185..29aabdf 100755 --- a/scripts/configure_vagrant_k3s.sh +++ b/scripts/configure_vagrant_k3s.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash -# This script checks for Vagrant and VirtualBox prerequisites, ensures Vagrant VMs are running, and gathers network and system information from the VMs. +# set -euo pipefail + +# This script checks for Vagrant and VirtualBox prerequisites, +# ensures Vagrant VMs are running, and gathers network and +# system information from the VMs. echo "Checking Vagrant prerequisites..." # Check if Vagrant is installed @@ -20,8 +24,6 @@ else fi fi - - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "Script directory: $SCRIPT_DIR" @@ -39,8 +41,6 @@ if [ -z "$(vagrant status | grep 'running')" ]; then vagrant up fi - - network_info=() vagrant_ports=() @@ -50,12 +50,11 @@ running_vms=$(vagrant status | grep "running" | awk '{print $1}') for vm in $running_vms; do # Check network interfaces and get specific IPs - vm_ips=$(vagrant ssh "$vm" -c "ip -j addr" | jq -r '.[] | - select(.addr_info != null) | + vm_ips=$(vagrant ssh "$vm" -c "ip -j addr | jq -r '.[] | + select(.ifname==\"enp0s8\") | .addr_info[] | - select(.family == "inet" and (.local | startswith("'${VAGRANT_NETWORK_PREFIX:-192.168.56}'."))) | - .local') - + select(.family==\"inet\" and .scope==\"global\" and .prefixlen<32 and .local!=\"'${VAGRANT_NETWORK_PREFIX:-192.168.56.250}'\") | + .local'") # Save the VM's IP to the array if it matches our pattern if [ ! -z "$vm_ips" ]; then @@ -74,11 +73,6 @@ done echo "Network information gathered successfully." - -# get vagrant ports -# echo "Gathering Vagrant port information..." - - # Ensure unique ports are added to the vagrant_ports array add_unique_port() { local port=$1 @@ -97,13 +91,11 @@ while read -r line; do done < <(vagrant ssh-config | grep Port) while read -r line; do - # Extract the port number port=$(echo "$line" | awk '{print $2}') add_unique_port "$port" done < <(vagrant ssh-config | grep Port) - ips=() # Print network information for info in "${network_info[@]}"; do diff --git a/scripts/install_vagrant_nodes.sh b/scripts/install_vagrant_nodes.sh new file mode 100755 index 0000000..7c504f5 --- /dev/null +++ b/scripts/install_vagrant_nodes.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +VAGRANT_DIR="$SCRIPT_DIR/../vagrant/dev/ubuntu/" + +echo "Script directory: $SCRIPT_DIR" +echo "Vagrant directory: $VAGRANT_DIR" +cd "$VAGRANT_DIR" || { + echo "Failed to change directory to Vagrant directory: $VAGRANT_DIR" + exit 1 +} + +vagrant up vm1 vm2 vm3 +if [ $? -ne 0 ]; then + echo "Failed to start Vagrant VMs. Please check your Vagrant setup." + exit 1 +fi diff --git a/scripts/install_vagrant_workstation.sh b/scripts/install_vagrant_workstation.sh new file mode 100755 index 0000000..5bc444a --- /dev/null +++ b/scripts/install_vagrant_workstation.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +VAGRANT_DIR="$SCRIPT_DIR/../vagrant/dev/ubuntu/" + +echo "Script directory: $SCRIPT_DIR" +echo "Vagrant directory: $VAGRANT_DIR" +cd "$VAGRANT_DIR" || { + echo "Failed to change directory to Vagrant directory: $VAGRANT_DIR" + exit 1 +} + + +vagrant up workstation diff --git a/vagrant/dev/ubuntu/ansible/provision_workstation.sh b/vagrant/dev/ubuntu/ansible/provision_workstation.sh index bb92431..45605b7 100644 --- a/vagrant/dev/ubuntu/ansible/provision_workstation.sh +++ b/vagrant/dev/ubuntu/ansible/provision_workstation.sh @@ -103,7 +103,7 @@ else echo "Provisioning block already present in $BASHRC" fi -ANSIBLE_HOST_KEY_CHECKING=False ansible --inventory-file /home/vagrant/ansible/ansible_inventory.ini -m ping all +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."