github.com/grafana/pyroscope@v1.18.0/tools/packaging/test-install.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  ## This script helps testing packages functionally, for this docker is used including a running systemd)
     4  #
     5  ## Usage
     6  # Test installing using rpm repos:
     7  # $ ./test-install.sh rpm
     8  # Test installing using apt repos:
     9  # $ ./test-install.sh deb
    10  # Test installing local deb/rpm file
    11  # $ ./test-install.sh ../../dist/pyroscope_1.1.0-rc1_linux_arm64.rpm
    12  
    13  set -euo pipefail
    14  
    15  IMAGE_DEBIAN=jrei/systemd-debian:12
    16  IMAGE_REDHAT=jrei/systemd-centos:8
    17  
    18  
    19  # Check if we should be using deb or rpm
    20  case ${1:-} in
    21      deb)
    22          IMAGE=${IMAGE_DEBIAN}
    23          MODE=deb
    24          ;;
    25  
    26      *.deb)
    27          IMAGE=${IMAGE_DEBIAN}
    28          MODE=deb-file
    29          if [ ! -f "$1" ]; then
    30            echo "$1 doesn't exists."
    31            exit 1
    32          fi
    33          FILE=$1
    34          ;;
    35  
    36      rpm)
    37          IMAGE=${IMAGE_REDHAT}
    38          MODE=rpm
    39          ;;
    40  
    41      *.rpm)
    42          IMAGE=${IMAGE_REDHAT}
    43          MODE=rpm-file
    44          if [ ! -f "$1" ]; then
    45            echo "$1 doesn't exists."
    46            exit 1
    47          fi
    48          FILE=$1
    49          ;;
    50  
    51      *)
    52          echo "unknown first argument specify either, 'deb' to download from the apt repository, 'rpm' to download from the rpm repository or a file path to a rpm/deb file."
    53          exit 1
    54          ;;
    55  esac
    56  
    57  
    58  # create a debian systemd container
    59  
    60  CONTAINER_ID=$(docker run -d --cgroupns=host --tmpfs /tmp --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup ${IMAGE})
    61  function container_cleanup {
    62    echo "Removing container ${CONTAINER_ID}"
    63    docker stop -t 5 "${CONTAINER_ID}"
    64    docker rm "${CONTAINER_ID}"
    65  }
    66  trap container_cleanup EXIT
    67  
    68  case $MODE in
    69    deb)
    70      docker exec -i "$CONTAINER_ID" /bin/bash <<EOF
    71  set -euo pipefail
    72  
    73  apt-get update
    74  
    75  apt-get install -y apt-transport-https software-properties-common curl
    76  
    77  mkdir -p /etc/apt/keyrings/
    78  curl -sL -o - https://apt.grafana.com/gpg.key | gpg --dearmor | tee /etc/apt/keyrings/grafana.gpg > /dev/null
    79  
    80  echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | tee -a /etc/apt/sources.list.d/grafana.list
    81  
    82  apt-get update
    83  
    84  apt-get install pyroscope
    85  
    86  EOF
    87      ;;
    88    deb-file)
    89      docker cp "$FILE" "${CONTAINER_ID}:/root/pyroscope.deb"
    90      docker exec -i "$CONTAINER_ID" /bin/bash <<EOF
    91  set -euo pipefail
    92  
    93  apt-get update
    94  
    95  apt-get install -y curl
    96  
    97  dpkg -i /root/pyroscope.deb
    98  
    99  EOF
   100      ;;
   101    rpm)
   102      docker exec -i "$CONTAINER_ID" /bin/bash <<EOF
   103  set -euo pipefail
   104  
   105  sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
   106  sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
   107  
   108  yum install -y curl
   109  
   110  curl -sL -o /tmp/gpg.key https://rpm.grafana.com/gpg.key
   111  
   112  rpm --import /tmp/gpg.key
   113  
   114  cat > /etc/yum.repos.d/grafana.repo <<EONF
   115  [grafana]
   116  name=grafana
   117  baseurl=https://rpm.grafana.com
   118  repo_gpgcheck=1
   119  enabled=1
   120  gpgcheck=1
   121  gpgkey=https://rpm.grafana.com/gpg.key
   122  sslverify=1
   123  sslcacert=/etc/pki/tls/certs/ca-bundle.crt
   124  EONF
   125  
   126  dnf -y install pyroscope
   127  
   128  EOF
   129      ;;
   130    rpm-file)
   131      docker cp "$FILE" "${CONTAINER_ID}:/root/pyroscope.rpm"
   132      docker exec -i "$CONTAINER_ID" /bin/bash <<"EOF"
   133  set -euo pipefail
   134  
   135  sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
   136  sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
   137  
   138  yum install -y curl
   139  
   140  rpm -i /root/pyroscope.rpm
   141  
   142  EOF
   143      ;;
   144      *)
   145          echo "unknown MODE"
   146          exit 1
   147  esac
   148  
   149  
   150  echo "installed successfully"
   151  
   152  
   153  echo "test health"
   154  docker exec -i "$CONTAINER_ID" /bin/bash <<"EOF"
   155  
   156  sleep 1
   157  
   158  # show systemd unit status
   159  systemctl status pyroscope
   160  
   161  url=http://127.0.0.1:4040/ready
   162  timeout -s TERM 300 bash -c \
   163    'while [[ "$(curl -s -o /dev/null -L -w ''%{http_code}'' '${url}')" != "200" ]];\
   164      do echo "Waiting for '${url}'" && sleep 2;\
   165      done'
   166  EOF