|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Deploy to S3 based repositories |
| 4 | +# ------------------------------- |
| 5 | +# |
| 6 | +# `deploy_s3.sh` is equivalent to `deploy_s3.sh staging`. |
| 7 | +# |
| 8 | +# `deploy_s3.sh staging` requires the following environment |
| 9 | +# variables: |
| 10 | +# |
| 11 | +# - OS |
| 12 | +# - DIST |
| 13 | +# - DEPLOY_STAGING_S3_ENDPOINT_URL="https://..." |
| 14 | +# - DEPLOY_STAGING_S3_LIVE_DIR="s3://my_bucket/foo/bar/live" |
| 15 | +# - DEPLOY_STAGING_S3_RELEASE_DIR="s3://my_bucket/foo/bar/release" |
| 16 | +# - DEPLOY_STAGING_S3_ACCESS_KEY_ID |
| 17 | +# - DEPLOY_STAGING_S3_SECRET_ACCESS_KEY |
| 18 | +# - DEPLOY_STAGING_S3_GPG_KEY_FILE_KEY (32 bytes in hex) |
| 19 | +# - DEPLOY_STAGING_S3_GPG_KEY_FILE_IV (16 bytes in hex) |
| 20 | +# |
| 21 | +# `deploy_s3.sh production` requires the following environment |
| 22 | +# variables: |
| 23 | +# |
| 24 | +# - OS |
| 25 | +# - DIST |
| 26 | +# - DEPLOY_PRODUCTION_S3_ENDPOINT_URL="https://..." |
| 27 | +# - DEPLOY_PRODUCTION_S3_LIVE_DIR="s3://my_bucket/foo/bar/live" |
| 28 | +# - DEPLOY_PRODUCTION_S3_RELEASE_DIR="s3://my_bucket/foo/bar/release" |
| 29 | +# - DEPLOY_PRODUCTION_S3_ACCESS_KEY_ID |
| 30 | +# - DEPLOY_PRODUCTION_S3_SECRET_ACCESS_KEY |
| 31 | +# - DEPLOY_PRODUCTION_S3_GPG_KEY_FILE_KEY (32 bytes in hex) |
| 32 | +# - DEPLOY_PRODUCTION_S3_GPG_KEY_FILE_IV (16 bytes in hex) |
| 33 | +# |
| 34 | +# If one of those variables is not set or empty, then deployment |
| 35 | +# will be skipped. |
| 36 | + |
| 37 | +# Make shell strictier. |
| 38 | +# |
| 39 | +# - Exit with a failure on a first failed command. |
| 40 | +# - Exit with a failure on an attempt to use an unset variable. |
| 41 | +# - Print each executed commmand. |
| 42 | +# |
| 43 | +# Note: The script expects that Travis-CI will filter sensitive |
| 44 | +# information (such as a token): 'Display value in build log' |
| 45 | +# toogle should be OFF for to keep a value secure. |
| 46 | +set -eux |
| 47 | + |
| 48 | +configuration=${1:-staging} |
| 49 | + |
| 50 | +# Choose URLs, directories, keys and so. |
| 51 | +if [ ${configuration} = staging ]; then |
| 52 | + DEPLOY_S3_ENDPOINT_URL="${DEPLOY_STAGING_S3_ENDPOINT_URL:-}" |
| 53 | + DEPLOY_S3_LIVE_DIR="${DEPLOY_STAGING_S3_LIVE_DIR:-}" |
| 54 | + DEPLOY_S3_RELEASE_DIR="${DEPLOY_STAGING_S3_RELEASE_DIR:-}" |
| 55 | + DEPLOY_S3_ACCESS_KEY_ID="${DEPLOY_STAGING_S3_ACCESS_KEY_ID:-}" |
| 56 | + DEPLOY_S3_SECRET_ACCESS_KEY="${DEPLOY_STAGING_S3_SECRET_ACCESS_KEY:-}" |
| 57 | + DEPLOY_S3_GPG_KEY_FILE_KEY="${DEPLOY_STAGING_S3_GPG_KEY_FILE_KEY:-}" |
| 58 | + DEPLOY_S3_GPG_KEY_FILE_IV="${DEPLOY_STAGING_S3_GPG_KEY_FILE_IV:-}" |
| 59 | +elif [ ${configuration} = production ]; then |
| 60 | + DEPLOY_S3_ENDPOINT_URL="${DEPLOY_PRODUCTION_S3_ENDPOINT_URL:-}" |
| 61 | + DEPLOY_S3_LIVE_DIR="${DEPLOY_PRODUCTION_S3_LIVE_DIR:-}" |
| 62 | + DEPLOY_S3_RELEASE_DIR="${DEPLOY_PRODUCTION_S3_RELEASE_DIR:-}" |
| 63 | + DEPLOY_S3_ACCESS_KEY_ID="${DEPLOY_PRODUCTION_S3_ACCESS_KEY_ID:-}" |
| 64 | + DEPLOY_S3_SECRET_ACCESS_KEY="${DEPLOY_PRODUCTION_S3_SECRET_ACCESS_KEY:-}" |
| 65 | + DEPLOY_S3_GPG_KEY_FILE_KEY="${DEPLOY_PRODUCTION_S3_GPG_KEY_FILE_KEY:-}" |
| 66 | + DEPLOY_S3_GPG_KEY_FILE_IV="${DEPLOY_PRODUCTION_S3_GPG_KEY_FILE_IV:-}" |
| 67 | +else |
| 68 | + echo "Unknown configuration: ${configuration}" |
| 69 | + exit 1 |
| 70 | +fi |
| 71 | + |
| 72 | +# Skip deployment if some variables are not set or empty. |
| 73 | +if [ -z "${OS:-}" ] || [ -z "${DIST:-}" ] || \ |
| 74 | + [ -z "${DEPLOY_S3_ENDPOINT_URL}" ] || \ |
| 75 | + [ -z "${DEPLOY_S3_LIVE_DIR}" ] || \ |
| 76 | + [ -z "${DEPLOY_S3_RELEASE_DIR}" ] || \ |
| 77 | + [ -z "${DEPLOY_S3_ACCESS_KEY_ID}" ] || \ |
| 78 | + [ -z "${DEPLOY_S3_SECRET_ACCESS_KEY}" ] || \ |
| 79 | + [ -z "${DEPLOY_S3_GPG_KEY_FILE_KEY}" ] || \ |
| 80 | + [ -z "${DEPLOY_S3_GPG_KEY_FILE_IV}" ]; then |
| 81 | + echo "Skip deployment: some of necessary environment" |
| 82 | + echo "variables are not set or empty" |
| 83 | + exit 0 |
| 84 | +fi |
| 85 | + |
| 86 | +# Download the tool to deploy to an S3 based repository. |
| 87 | +ref=f84cb1aae3144f5677feacf6be31bd4f15e91c2d |
| 88 | +base_url="https://raw.githubusercontent.com/tarantool/tarantool/${ref}" |
| 89 | +curl -Ssfo update_repo.sh "${base_url}/tools/update_repo.sh" |
| 90 | +chmod a+x update_repo.sh |
| 91 | + |
| 92 | +# FIXME: Upstream the patches. |
| 93 | +patch -p1 -i .travis/gh-5112-update-repo-sh-use-right-gpg-key.patch |
| 94 | +patch -p1 -i .travis/gh-5113-update-repo-sh-add-fedora-25-26.patch |
| 95 | +patch -p1 -i .travis/gh-5114-update-repo-sh-fix-unbound-var-access.patch |
| 96 | + |
| 97 | +# Decrypt a GPG key. |
| 98 | +gpg_key_file=".travis/deploy_${configuration}_s3_gpg_private_key.asc" |
| 99 | +openssl aes-256-cbc -K "${DEPLOY_S3_GPG_KEY_FILE_KEY}" \ |
| 100 | + -iv "${DEPLOY_S3_GPG_KEY_FILE_IV}" -in "${gpg_key_file}.enc" \ |
| 101 | + -out "${gpg_key_file}" -d |
| 102 | + |
| 103 | +# Import GPG key for signing repository files. |
| 104 | +gpg --import --batch "${gpg_key_file}" |
| 105 | + |
| 106 | +# Extract GPG key id for signing repository files. |
| 107 | +# |
| 108 | +# This way works for both GnuPG 1 and GnuPG 2. The alternative |
| 109 | +# would be using '--import-options show-only', but it is available |
| 110 | +# only in GnuPG 2. See https://unix.stackexchange.com/a/468889 |
| 111 | +mkdir -m 0700 temp-gpg-home |
| 112 | +gpg --homedir temp-gpg-home --import --batch "${gpg_key_file}" |
| 113 | +export GPG_SIGN_KEY="$(gpg --homedir temp-gpg-home --list-secret-keys \ |
| 114 | + --with-colons | grep ^sec: | cut -d: -f5)" |
| 115 | +rm -rf temp-gpg-home |
| 116 | + |
| 117 | +# Use SHA256 hashing algorithm for files signing. |
| 118 | +# |
| 119 | +# `apt-get update` gives a warning when InRelease file signature |
| 120 | +# is calculated with SHA1. We should configure GnuPG (which is |
| 121 | +# used by reprepro, which is used by update_repo.sh) to sign using |
| 122 | +# SHA265. |
| 123 | +# |
| 124 | +# https://askubuntu.com/a/819868 |
| 125 | +mkdir -p ~/.gnupg |
| 126 | +echo 'digest-algo sha256' >> ~/.gnupg/gpg.conf |
| 127 | + |
| 128 | +# Setup environment variables for the update_repo.sh tool. |
| 129 | +export AWS_S3_ENDPOINT_URL="${DEPLOY_S3_ENDPOINT_URL}" |
| 130 | +export AWS_ACCESS_KEY_ID="${DEPLOY_S3_ACCESS_KEY_ID}" |
| 131 | +export AWS_SECRET_ACCESS_KEY="${DEPLOY_S3_SECRET_ACCESS_KEY}" |
| 132 | + |
| 133 | +# ${product} value may affect location of *.deb, *.rpm and related |
| 134 | +# files relative to a base repository URL. We can provide it or |
| 135 | +# miss: the script will generate correct repository metainfo |
| 136 | +# anyway. |
| 137 | +# |
| 138 | +# However providing meaningful value for this option enables |
| 139 | +# grouping of related set of packages into a subdirectory named as |
| 140 | +# ${product} (only for Deb repositories at moment of writing |
| 141 | +# this). |
| 142 | +# |
| 143 | +# It is enabled here for consistency with locations of other Deb |
| 144 | +# packages in our repositories, but in fact it is the internal |
| 145 | +# detail, which does not lead to any change in the user |
| 146 | +# experience. |
| 147 | +product=php-tarantool |
| 148 | + |
| 149 | +# Setup arguments that are common for all repositories |
| 150 | +# (1.10, 2.1, ...). |
| 151 | +update_repo_args="--os=${OS} --distribution=${DIST} --product=${product}" |
| 152 | + |
| 153 | +# Staging repository: rewrite a package if there is a previous one |
| 154 | +# of the same version. |
| 155 | +# |
| 156 | +# Note: It differs from a logic in deploy_packagecloud.sh. |
| 157 | +if [ "${configuration}" = staging ]; then |
| 158 | + update_repo_args="${update_repo_args} --force" |
| 159 | +fi |
| 160 | + |
| 161 | +# Deploy to S3 based repositories. |
| 162 | +for repo in 1.10 2.1 2.2 2.3 2.4 2.5; do |
| 163 | + # Note: The update_repo.sh tool automatically find |
| 164 | + # *.{rpm,deb,dsc} within a passed directory, so we just |
| 165 | + # pass the directory name: 'build'. |
| 166 | + |
| 167 | + # FIXME: Machine-local locking that is used in the |
| 168 | + # update_repo.sh tool is insufficient when we deploy from a |
| 169 | + # just created virtual machine. |
| 170 | + |
| 171 | + # Deploy to live repository (per-push). |
| 172 | + bucket="${DEPLOY_S3_LIVE_DIR}/${repo}" |
| 173 | + ./update_repo.sh ${update_repo_args} --bucket="${bucket}" build |
| 174 | + |
| 175 | + # Deploy to release repository (tagged commits). |
| 176 | + if [ -n "${TRAVIS_TAG:-}" ]; then |
| 177 | + bucket="${DEPLOY_S3_RELEASE_DIR}/${repo}" |
| 178 | + ./update_repo.sh ${update_repo_args} --bucket="${bucket}" build |
| 179 | + fi |
| 180 | +done |
0 commit comments