github.com/secure-build/gitlab-runner@v12.5.0+incompatible/ci/package (about)

     1  #!/usr/bin/env bash
     2  
     3  set -eo pipefail
     4  
     5  check_macos_package() {
     6      local binary="${1}"
     7      local package="${2}"
     8  
     9      if ! which "${binary}" >/dev/null 2>&1; then
    10          echo
    11          echo -e "\\033[31;1m"
    12          echo "Seems that you're using Mac OS. In case of troubles with packaging ensure"
    13          echo "that ${package} is installed. You can do this e.g. with 'brew install ${package}'"
    14          echo -e "\\033[0m"
    15          echo
    16      fi
    17  }
    18  
    19  create_package() {
    20      local packageType=${1}
    21      shift
    22  
    23      local customOptions
    24      read -r -a customOptions <<< "${@}"
    25  
    26      local uname_s
    27      uname_s=$(uname -s)
    28  
    29      if [[ "${uname_s}" == "Darwin" ]]; then
    30          check_macos_package "gtar" "gnu-tar"
    31          check_macos_package "rpmbuild" "rpm"
    32      fi
    33  
    34  	mkdir -p "out/${packageType}/"
    35  
    36      fpm \
    37  		--package "out/${packageType}/${PACKAGE_NAME}_${PACKAGE_ARCH}.${packageType}" \
    38  		--force \
    39  		--input-type dir \
    40  		--output-type "${packageType}" \
    41  		\
    42  		--name "${PACKAGE_NAME}" \
    43  		--description "GitLab Runner" \
    44  		--version "${VERSION}" \
    45  		--url https://gitlab.com/gitlab-org/gitlab-runner \
    46  		--maintainer "GitLab Inc. <support@gitlab.com>" \
    47  		--license "MIT" \
    48  		--vendor "GitLab Inc." \
    49  		--architecture "${PACKAGE_ARCH}" \
    50  		\
    51  		--conflicts "${PACKAGE_NAME}-beta" \
    52  		--conflicts gitlab-ci-multi-runner \
    53  		--conflicts gitlab-ci-multi-runner-beta \
    54  		--provides gitlab-ci-multi-runner \
    55  		--replaces gitlab-ci-multi-runner \
    56  		\
    57  		--depends git \
    58  		--depends curl \
    59  		--depends tar \
    60  		\
    61  		${customOptions[@]} \
    62  		\
    63  		--after-install "packaging/scripts/postinst.${packageType}" \
    64  		--before-remove "packaging/scripts/prerm.${packageType}" \
    65  		\
    66  		packaging/root/=/ \
    67  		"${RUNNER_BINARY}=/usr/lib/gitlab-runner/gitlab-runner" \
    68  		out/helper-images/=/usr/lib/gitlab-runner/helper-images/
    69  }
    70  
    71  create_deb() {
    72      local options=()
    73      options+=("--depends ca-certificates")
    74      options+=("--category admin")
    75      options+=("--deb-priority optional")
    76      options+=("--deb-compression bzip2")
    77      options+=("--deb-suggests docker-engine")
    78  
    79      create_package deb "${options[@]}"
    80  
    81      if [ -n "${GPG_KEYID}" ]; then
    82          dpkg-sig \
    83              -g "--no-tty --digest-algo 'sha512' --passphrase '${GPG_PASSPHRASE}' --pinentry-mode=loopback" \
    84  			-k "${GPG_KEYID}" \
    85  			--sign builder \
    86  			"out/deb/${PACKAGE_NAME}_${PACKAGE_ARCH}.deb"
    87  	fi
    88  }
    89  
    90  create_rpm() {
    91      local options=()
    92      options+=("--rpm-compression bzip2")
    93      options+=("--rpm-os linux")
    94  
    95      create_package rpm "${options[@]}"
    96  
    97      if [ -n "${GPG_KEYID}" ] ; then
    98  		echo "yes" | setsid rpm \
    99  			--define "_gpg_name ${GPG_KEYID}" \
   100  			--define "_signature gpg" \
   101  			--define "__gpg_check_password_cmd /bin/true" \
   102  			--define "__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --digest-algo 'sha512' --passphrase '${GPG_PASSPHRASE}' --pinentry-mode=loopback --no-secmem-warning -u '%{_gpg_name}' --sign --detach-sign --output %{__signature_filename} %{__plaintext_filename}" \
   103  			--addsign "out/rpm/${PACKAGE_NAME}_${PACKAGE_ARCH}.rpm"
   104  	fi
   105  
   106  }
   107  
   108  case "${1}" in
   109      deb)
   110          create_deb
   111          ;;
   112      rpm)
   113          create_rpm
   114          ;;
   115      *)
   116          echo "Usage: ${0} (deb|rpm)"
   117          ;;
   118  esac