diff --git a/discovery/Dockerfile b/discovery/Dockerfile index 64a9dc8..2ea8c13 100644 --- a/discovery/Dockerfile +++ b/discovery/Dockerfile @@ -2,6 +2,12 @@ FROM alpine:3.13.1 RUN apk add --no-cache util-linux curl +ARG COLONY_SCOUT_VERSION=0.0.8-rc1 + +RUN curl -L -o colony-scout.tar.gz https://assets.kubefirst.com/colony/colony-scout_${COLONY_SCOUT_VERSION}_linux_amd64.tar.gz && \ + tar -xzvf colony-scout.tar.gz && \ + chmod +x colony-scout + COPY . . ENTRYPOINT ["/bin/sh","./entrypoint.sh"] diff --git a/discovery/entrypoint.sh b/discovery/entrypoint.sh index 6035acb..94b1812 100755 --- a/discovery/entrypoint.sh +++ b/discovery/entrypoint.sh @@ -2,104 +2,33 @@ set -x -if [ -z "${K1_COLONY_API_URL}" ]; then - echo "K1_COLONY_API_URL NEEDS SETTING" - exit 1 -fi - if [ -z "${K1_COLONY_HARDWARE_ID}" ]; then echo "K1_COLONY_HARDWARE_ID NEEDS SETTING" exit 1 fi -# Function to get architecture info -get_architecture_info() { - architecture_info=$(lscpu | grep Architecture: | awk '{print $2}') - echo "$architecture_info" -} - -# Function to get number of cpu -get_cpu_info() { - cpu_info=$(nproc) - echo "$cpu_info" -} - -# Function to get memory info -get_mem_info() { - mem_info=$(free -m | grep Mem | awk '{print $2}') - echo "$mem_info" -} - -# Function to get physical disk info -get_disk_info() { - disk_info=$(lsblk -dpno NAME,SIZE | awk '$2 != "0B" {print $1, $2}' | sort -k2 | awk '{printf "\"%s\",", $1}' | sed 's/,$//') - echo "[${disk_info}]" -} - -# Function to get physical interface info -get_interface_info() { - interface_info=$(ip -o link show | awk -F': ' 'NR>1{print ",\""$2"\""}') - echo "["${interface_info:1}"]" -} - -# Main function to generate JSON output -generate_json() { - architecture_info=$(get_architecture_info) - cpu_info=$(get_cpu_info) - mem_info=$(get_mem_info) - disk_info=$(get_disk_info) - interface_info=$(get_interface_info) - - json_output=$(cat <&1) - echo "----------------------------" - echo "Server ${K1_COLONY_API_URL}/api/v1/hardwares/${K1_COLONY_HARDWARE_ID}" - echo "body: $body" - echo "http_code: $http_code" - echo "response_body: $response_body" - echo "----------------------------" + exit_status=$? - if [[ $http_code -ge 200 && $http_code -le 299 ]]; then - echo "Request success." - else - echo "Error request updating hardware." - exit 1 - fi + if [[ $exit_status -eq 0 ]]; then + echo "Request success." + else + echo "Error request updating hardware." + echo "Output: $output" + exit 1 + fi } -# Call the main function to generate JSON output -generate_json -echo "Successfully" +update_hardware set +x