install-runner.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # shellcheck shell=bash
  2. ## install the runner
  3. s3_location=${S3_LOCATION_RUNNER_DISTRIBUTION}
  4. architecture=${RUNNER_ARCHITECTURE}
  5. if [ -z "$RUNNER_TARBALL_URL" ] && [ -z "$s3_location" ]; then
  6. echo "Neither RUNNER_TARBALL_URL or s3_location are set"
  7. exit 1
  8. fi
  9. file_name="actions-runner.tar.gz"
  10. echo "Setting up GH Actions runner tool cache"
  11. # Required for various */setup-* actions to work, location is also know by various environment
  12. # variable names in the actions/runner software : RUNNER_TOOL_CACHE / RUNNER_TOOLSDIRECTORY / AGENT_TOOLSDIRECTORY
  13. # Warning, not all setup actions support the env vars and so this specific path must be created regardless
  14. mkdir -p /opt/hostedtoolcache
  15. echo "Creating actions-runner directory for the GH Action installation"
  16. cd /opt/
  17. mkdir -p actions-runner && cd actions-runner
  18. if [[ -n "$RUNNER_TARBALL_URL" ]]; then
  19. echo "Downloading the GH Action runner from $RUNNER_TARBALL_URL to $file_name"
  20. curl -o $file_name -L "$RUNNER_TARBALL_URL"
  21. else
  22. echo "Retrieving TOKEN from AWS API"
  23. token=$(curl -f -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 180")
  24. region=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
  25. echo "Retrieved REGION from AWS API ($region)"
  26. echo "Downloading the GH Action runner from s3 bucket $s3_location"
  27. aws s3 cp "$s3_location" "$file_name" --region "$region"
  28. fi
  29. echo "Un-tar action runner"
  30. tar xzf ./$file_name
  31. echo "Delete tar file"
  32. rm -rf $file_name
  33. if [[ "$architecture" == "arm64" ]]; then
  34. yum install -y libicu60
  35. fi
  36. os_id=$(awk -F= '/^ID/{print $2}' /etc/os-release)
  37. if [[ "$os_id" =~ ^ubuntu.* ]]; then
  38. echo "Installing dependencies"
  39. ./bin/installdependencies.sh
  40. fi
  41. echo "Set file ownership of action runner"
  42. chown -R "$user_name":"$user_name" .
  43. chown -R "$user_name":"$user_name" /opt/hostedtoolcache