|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The Cockroach Authors. |
| 4 | +# |
| 5 | +# Use of this software is governed by the CockroachDB Software License |
| 6 | +# included in the /LICENSE file. |
| 7 | + |
| 8 | + |
| 9 | +set -euxo pipefail |
| 10 | + |
| 11 | +service_account=$(curl --header "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email" || echo "") |
| 12 | + |
| 13 | +if [[ $service_account != "[email protected]" ]] ; then |
| 14 | + echo "Not running on a signing agent, skipping signing" |
| 15 | + exit 0 |
| 16 | +fi |
| 17 | + |
| 18 | +dir="$(dirname $(dirname $(dirname $(dirname $(dirname "${0}")))))" |
| 19 | +source "$dir/release/teamcity-support.sh" |
| 20 | + |
| 21 | +tc_start_block "Variable Setup" |
| 22 | + |
| 23 | +build_name=$(git describe --tags --dirty --match=v[0-9]* 2> /dev/null || git rev-parse --short HEAD;) |
| 24 | + |
| 25 | +# On no match, `grep -Eo` returns 1. `|| echo""` makes the script not error. |
| 26 | +release_branch="$(echo "$build_name" | grep -Eo "^v[0-9]+\.[0-9]+" || echo"")" |
| 27 | +is_customized_build="$(echo "$TC_BUILD_BRANCH" | grep -Eo "^custombuild-" || echo "")" |
| 28 | +is_release_build="$(echo "$TC_BUILD_BRANCH" | grep -Eo "^((staging|release|rc)-(v)?[0-9][0-9]\.[0-9](\.0)?).*|master$" || echo "")" |
| 29 | + |
| 30 | +if [[ -z "${DRY_RUN}" ]] ; then |
| 31 | + if [[ -z "${is_release_build}" ]] ; then |
| 32 | + gcs_bucket="cockroach-customized-builds-artifacts-prod" |
| 33 | + google_credentials="$GOOGLE_CREDENTIALS_CUSTOMIZED" |
| 34 | + else |
| 35 | + gcs_bucket="cockroach-builds-artifacts-prod" |
| 36 | + google_credentials="$GCS_CREDENTIALS_PROD" |
| 37 | + fi |
| 38 | +else |
| 39 | + gcs_bucket="cockroach-builds-artifacts-dryrun" |
| 40 | + build_name="${build_name}.dryrun" |
| 41 | + google_credentials="$GCS_CREDENTIALS_DEV" |
| 42 | +fi |
| 43 | + |
| 44 | +cat << EOF |
| 45 | +
|
| 46 | + build_name: $build_name |
| 47 | + release_branch: $release_branch |
| 48 | + is_customized_build: $is_customized_build |
| 49 | + gcs_bucket: $gcs_bucket |
| 50 | + is_release_build: $is_release_build |
| 51 | +
|
| 52 | +EOF |
| 53 | +tc_end_block "Variable Setup" |
| 54 | + |
| 55 | +secrets_dir="$(mktemp -d)" |
| 56 | +_on_exit() { |
| 57 | + rm -rf "$secrets_dir" |
| 58 | + gcloud config set account "[email protected]" |
| 59 | +} |
| 60 | +trap _on_exit EXIT |
| 61 | + |
| 62 | + |
| 63 | +# Explicitly set the account to the signing agent. This is helpful if one of the previous |
| 64 | +# commands failed and left the account set to something else. |
| 65 | +gcloud config set account "[email protected]" |
| 66 | +gcloud secrets versions access latest --secret=apple-signing-cert | base64 -d > "$secrets_dir/cert.p12" |
| 67 | +gcloud secrets versions access latest --secret=apple-signing-cert-password > "$secrets_dir/cert.pass" |
| 68 | +gcloud secrets versions access latest --secret=appstoreconnect-api-key > "$secrets_dir/api_key.json" |
| 69 | + |
| 70 | +google_credentials="$google_credentials" log_into_gcloud |
| 71 | + |
| 72 | +workdir="$(mktemp -d)" |
| 73 | +cd "$workdir" |
| 74 | + |
| 75 | +for product in cockroach cockroach-sql; do |
| 76 | + # In case we want to sign darwin-10.9-amd64, we can add it here. |
| 77 | + for platform in darwin-11.0-arm64; do |
| 78 | + gsutil cp "gs://$gcs_bucket/$product-$build_name.$platform.unsigned.tgz" "$product-$build_name.$platform.unsigned.tgz" |
| 79 | + tar -xzf "$product-$build_name.$platform.unsigned.tgz" |
| 80 | + mv "$product-$build_name.$platform.unsigned" "$product-$build_name.$platform" |
| 81 | + rcodesign sign \ |
| 82 | + --p12-file "$secrets_dir/cert.p12" --p12-password-file "$secrets_dir/cert.pass" \ |
| 83 | + --code-signature-flags runtime \ |
| 84 | + "$product-$build_name.$platform/$product" |
| 85 | + zip -r crl.zip "$product-$build_name.$platform/$product" |
| 86 | + rcodesign notary-submit --api-key-file "$secrets_dir/api_key.json" --wait crl.zip |
| 87 | + tar -czf "$product-$build_name.$platform.tgz" "$product-$build_name.$platform" |
| 88 | + shasum --algorithm 256 "$product-$build_name.$platform.tgz" > "$product-$build_name.$platform.tgz.sha256sum" |
| 89 | + gsutil cp "$product-$build_name.$platform.tgz" "gs://$gcs_bucket/$product-$build_name.$platform.tgz" |
| 90 | + gsutil cp "$product-$build_name.$platform.tgz.sha256sum" "gs://$gcs_bucket/$product-$build_name.$platform.tgz.sha256sum" |
| 91 | + rm -rf "$product-$build_name.$platform" \ |
| 92 | + "$product-$build_name.$platform.tgz" \ |
| 93 | + "$product-$build_name.$platform.tgz.sha256sum" \ |
| 94 | + crl.zip |
| 95 | + done |
| 96 | +done |
0 commit comments