github.com/grafana/synthetic-monitoring-agent@v0.64.2/scripts/sm-dev (about)

     1  #!/bin/sh
     2  
     3  set -e
     4  
     5  usage() {
     6  	cat <<-EOT
     7  	Usage:
     8  
     9  	        $0 [-h] [-r] <filename.cfg>
    10  
    11  	Flags:
    12  
    13  	        -h: show this help
    14  	        -n: don't build api, already built
    15  	EOT
    16  }
    17  
    18  k3d_context=k3d-sm-test
    19  k3d_cluster=sm-test
    20  build_agent=true
    21  while getopts ":hn" arg ; do
    22  	case "$arg" in
    23  		n)
    24  			build_agent=false
    25  			shift
    26  			;;
    27  		h)
    28  			usage
    29  			exit 0
    30  			;;
    31  		*)
    32  			usage
    33  			exit 1
    34  			;;
    35  	esac
    36  done
    37  
    38  cfg_file=$1
    39  
    40  # check if k3d cluster is running or not
    41  # k3d image import fails if cluster is not running and script hangs
    42  cluster_running=$(k3d cluster get "${k3d_cluster}" -o json 2>/dev/null | jq '.[].serversRunning')
    43  if [ "${cluster_running}" != 1 ]; then
    44    echo "E: k3d cluster '${k3d_cluster}' is not running!"
    45    echo "INFO: start it with 'k3d cluster start ${k3d_cluster}'"
    46    exit 1
    47  fi
    48  
    49  agent_yaml_tmpl=$(dirname "$0")/agent.yaml.tmpl
    50  
    51  if test ! -e "${agent_yaml_tmpl}" ; then
    52  	echo "E: agent.yaml.tmpl not found. Abort."
    53  	exit 1
    54  fi
    55  
    56  if test -z "${cfg_file}" -o ! -e "${cfg_file}" ; then
    57  	echo "E: configuration file '${cfg_file}' not found. Abort."
    58  	exit 1
    59  fi
    60  
    61  agent_yaml=$(mktemp)
    62  gomplate -d config=stdin:///in.env --file "${agent_yaml_tmpl}" < "${cfg_file}" > "${agent_yaml}"
    63  
    64  if "${build_agent}" ; then
    65    ./scripts/docker_build
    66    docker build -t "grafana/synthetic-monitoring-agent" -f Dockerfile .
    67    k3d image import grafana/synthetic-monitoring-agent:latest -c sm-test
    68  fi
    69  
    70  echo "Applying configuration..."
    71  
    72  kubectl --context="${k3d_context}" apply -f "${agent_yaml}"
    73  
    74  echo "Done."