Skip to content

Commit 40100b7

Browse files
committed
travis-ci: deploy RPM / Deb packages
Now php-tarantool packages are deployed into two kinds of repositories: packagecloud.io and to S3 based ones. The download.tarantool.org now points to the latter, but we keep packagecloud.io for a while to don't break users, which use it directly (we don't recommend it though). See [1] for more info about deprecation of our packagecloud.io repositories. The deployment scripts allows to provide two configurations: production and staging. The former is for deployment from the master branch and from a git tag. The latter is for deployments from a developer branch. It is useful when something should be verified in a specific environment using a built package or when the deployment process itself was modified and should be tested. The difference between production and staging deployment process is how duplicate package versions are handled. It give an error for production deployment, but does not for staging. The new package is discarded in the case for packagecloud.io, but it replaces the old package in S3 repositories. Read comments in the deployment scripts for more details. [1]: tarantool/tarantool#4947 Fixes #117
1 parent 2d506f7 commit 40100b7

11 files changed

+547
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ debian/php5-tarantool.substvars
4646
debian/php5-tarantool/
4747
build
4848
.*.sw[a-z]
49+
50+
# Unencrypted private GPG keys for deployment.
51+
.travis/*.asc

.travis.yml

+43-2
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,61 @@ python:
129129

130130
script:
131131
- |
132+
# Make shell strictier.
133+
#
134+
# - Exit with a failure on a first failed command.
135+
# - Print each executed commmand.
136+
set -ex
137+
132138
if [ -n "${TARANTOOL_VERSION}" ]; then
133139
./test.sh
134140
elif [ -n "${OS}" ] && [ -n "${DIST}" ]; then
135141
git clone --depth 1 https://github.com/packpack/packpack.git
136142
./packpack/packpack
137143
if [ "${OS}" = "el" ]; then
138-
export OS=centos
144+
DOCKER_IMAGE="centos:${DIST}"
145+
else
146+
DOCKER_IMAGE="${OS}:${DIST}"
139147
fi
140148
docker run \
141149
--volume "$(realpath .):/tarantool-php" \
142150
--workdir /tarantool-php \
143151
--rm \
144-
"${OS}:${DIST}" \
152+
"${DOCKER_IMAGE}" \
145153
./test.pkg.sh
146154
else
147155
exit 1
148156
fi
157+
158+
# Deploy
159+
# ------
160+
161+
# Skip deployment when it is not expected.
162+
if [ -z "${OS}" ] || [ -z "${DIST}" ]; then
163+
echo "Skip deployment: it is pure testing job w/o any RPM / Deb artefacts"
164+
exit 0
165+
fi
166+
if [ "${TRAVIS_REPO_SLUG}" != "tarantool/tarantool-php" ]; then
167+
echo "Skip deployment: it is a fork, not the base repository"
168+
exit 0
169+
fi
170+
if [ "${TRAVIS_EVENT_TYPE}" != "push" ]; then
171+
echo "Skip deployment: event is not 'push', but ${TRAVIS_EVENT_TYPE}"
172+
exit 0
173+
fi
174+
175+
# Choose destination to push packages.
176+
if [ "${TRAVIS_BRANCH}" == "master" ] || [ -n "${TRAVIS_TAG}" ]; then
177+
echo "Set production deployment parameters"
178+
configuration=production
179+
else
180+
echo "Set staging deployment parameters"
181+
configuration=staging
182+
fi
183+
184+
# Deploy to packagecloud repositories.
185+
./.travis/deploy_packagecloud.sh ${configuration}
186+
187+
# Deploy to S3 based repositories.
188+
./.travis/deploy_s3_dependencies.sh
189+
./.travis/deploy_s3.sh ${configuration}

.travis/deploy_packagecloud.sh

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/bin/sh
2+
3+
# Deploy to packagecloud repositories
4+
# -----------------------------------
5+
#
6+
# `deploy_packagecloud.sh` is equivalent to
7+
# `deploy_packagecloud.sh staging`.
8+
#
9+
# `deploy_packagecloud.sh staging` requires the following
10+
# environment variables:
11+
#
12+
# - OS
13+
# - DIST
14+
# - DEPLOY_STAGING_PACKAGECLOUD_USER
15+
# - DEPLOY_STAGING_PACKAGECLOUD_TOKEN
16+
#
17+
# `deploy_packagecloud.sh production` requires the following
18+
# environment variables:
19+
#
20+
# - OS
21+
# - DIST
22+
# - DEPLOY_PRODUCTION_PACKAGECLOUD_USER
23+
# - DEPLOY_PRODUCTION_PACKAGECLOUD_TOKEN
24+
#
25+
# If one of those variables is not set or empty, then deployment
26+
# will be skipped.
27+
28+
# Make shell strictier.
29+
#
30+
# - Exit with a failure on a first failed command.
31+
# - Exit with a failure on an attempt to use an unset variable.
32+
# - Print each executed commmand.
33+
#
34+
# Note: The script expects that Travis-CI will filter sensitive
35+
# information (such as a token): 'Display value in build log'
36+
# toogle should be OFF for to keep a value secure.
37+
set -eux
38+
39+
configuration=${1:-staging}
40+
41+
# Choose credentials.
42+
if [ ${configuration} = staging ]; then
43+
DEPLOY_PACKAGECLOUD_USER="${DEPLOY_STAGING_PACKAGECLOUD_USER:-}"
44+
DEPLOY_PACKAGECLOUD_TOKEN="${DEPLOY_STAGING_PACKAGECLOUD_TOKEN:-}"
45+
elif [ ${configuration} = production ]; then
46+
DEPLOY_PACKAGECLOUD_USER="${DEPLOY_PRODUCTION_PACKAGECLOUD_USER:-}"
47+
DEPLOY_PACKAGECLOUD_TOKEN="${DEPLOY_PRODUCTION_PACKAGECLOUD_TOKEN:-}"
48+
else
49+
echo "Unknown configuration: ${configuration}"
50+
exit 1
51+
fi
52+
53+
# Skip deployment if some variables are not set or empty.
54+
if [ -z "${OS:-}" ] || [ -z "${DIST:-}" ] || \
55+
[ -z "${DEPLOY_PACKAGECLOUD_USER}" ] || \
56+
[ -z "${DEPLOY_PACKAGECLOUD_TOKEN}" ]; then
57+
echo "Skip deployment: some of necessary environment"
58+
echo "variables are not set or empty"
59+
exit 0
60+
fi
61+
62+
# Verify that packpack is cloned into the current directory.
63+
packagecloud_tool=./packpack/tools/packagecloud
64+
if [ ! -f "${packagecloud_tool}" ]; then
65+
echo "Could not find ${packagecloud_tool}"
66+
exit 1
67+
fi
68+
69+
# Staging repository: keep older packages in case of a
70+
# version clash.
71+
#
72+
# It would be better to replace old ones, but there is no
73+
# such option in the packagecloud tool we use. It may be
74+
# important if we'll have some manual or automatic testing
75+
# upward a staging repository. But at least CI will not fail
76+
# because a package is already exists.
77+
push_args=""
78+
if [ "${configuration}" = staging ]; then
79+
push_args="${push_args} --ignore-duplicates"
80+
fi
81+
82+
# Setup environment variables for the packagecloud tool.
83+
export PACKAGECLOUD_TOKEN="${DEPLOY_PACKAGECLOUD_TOKEN}"
84+
85+
# FIXME: It would be good to upstream the repos_list command.
86+
(cd packpack/tools &&
87+
patch -p1 -i ../../.travis/packagecloud-list-repos.patch)
88+
89+
# Fetch list of repositories from packagecloud.io.
90+
#
91+
# Set default repositories if the attempt to fetch them fails.
92+
#
93+
# We have tarantool repositories on packagecloud.io up to
94+
# 2_4. The next ones present only in the S3 based storage.
95+
repositories=""
96+
for i in $(seq 1 5); do
97+
repositories="$(${packagecloud_tool} list_repos || true)"
98+
[ -n "${repositories}" ] && break
99+
done
100+
[ -z "${repositories}" ] && repositories="1_6 1_7 1_9 1_10 2x 2_2 2_3 2_4"
101+
102+
for repo in ${repositories}; do
103+
# FIXME: Enable *.ddeb when packagecloud.io will support it.
104+
for file in build/*.rpm build/*.deb build/*.dsc; do
105+
extension=${file##*.}
106+
107+
# Skip non-matched globs: say, build/*.rpm on Debian.
108+
basename="$(basename "${file}" ".${extension}")"
109+
[ "${basename}" = "*" ] && continue
110+
111+
# Push all source files listed in .dsc file together with
112+
# the file.
113+
#
114+
# FIXME: It seems logical to move this logic to the
115+
# packagecloud tool we use.
116+
files="${file}"
117+
if [ "${extension}" = "dsc" ]; then
118+
parse_dsc_file='{
119+
if ($0 == "Files:") {
120+
FILES_SECTION = 1;
121+
} else if (FILES_SECTION != 0) {
122+
print "build/"$3;
123+
}
124+
}'
125+
files="${files} $(awk "${parse_dsc_file}" "${file}")"
126+
fi
127+
128+
user=${DEPLOY_PACKAGECLOUD_USER}
129+
130+
# Retry failed attempts to upload a package.
131+
#
132+
# packagecloud.io sometimes replieds with 502 Bad Gateway
133+
# for attempts to push, so retrying is important here.
134+
#
135+
# FIXME: This way we don't differentiate network errors
136+
# and all other ones. It would be much better to retry
137+
# from inside the packagecloud tool (requests library
138+
# supports it).
139+
for i in $(seq 1 5); do
140+
# FIXME: The tool fetches distributions.json each
141+
# time. It can cache the data somewhere and reuse
142+
# during some time period until expiration.
143+
${packagecloud_tool} push ${push_args} ${user}/${repo} \
144+
${extension} ${OS} ${DIST} ${files} && break
145+
done
146+
done
147+
done
Binary file not shown.

0 commit comments

Comments
 (0)