Skip to content

Commit e85f084

Browse files
committed
Cache redis server compilation on CI
1 parent 6efb53a commit e85f084

File tree

3 files changed

+78
-10
lines changed

3 files changed

+78
-10
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
language: ruby
2-
2+
cache:
3+
directories:
4+
- tmp/cache
35
before_install:
46
- gem update --system 2.6.14
57
- gem --version

bin/build

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env ruby
2+
3+
TARBALL = ARGV[0]
4+
5+
require 'digest/sha1'
6+
require 'fileutils'
7+
8+
class Builder
9+
def initialize(redis_branch, tmp_dir)
10+
@redis_branch = redis_branch
11+
@tmp_dir = tmp_dir
12+
@build_dir = File.join(@tmp_dir, "cache", "redis-#{redis_branch}")
13+
end
14+
15+
def run
16+
download_tarball
17+
if old_checkum != checksum
18+
build
19+
update_checksum
20+
end
21+
0
22+
end
23+
24+
def download_tarball
25+
command!('wget', tarball_url, '-O', tarball_path)
26+
end
27+
28+
def tarball_path
29+
File.join(@tmp_dir, "redis-#{@redis_branch}.tar.gz")
30+
end
31+
32+
def tarball_url
33+
"https://github.com/antirez/redis/archive/#{@redis_branch}.tar.gz"
34+
end
35+
36+
def build
37+
FileUtils.rm_rf(@build_dir)
38+
FileUtils.mkdir_p(@build_dir)
39+
command!('tar', 'xf', tarball_path, '-C', File.expand_path('../', @build_dir))
40+
Dir.chdir(@build_dir) do
41+
command!('make')
42+
end
43+
end
44+
45+
def update_checksum
46+
File.write(checksum_path, checksum)
47+
end
48+
49+
def old_checkum
50+
File.read(checksum_path)
51+
rescue Errno::ENOENT
52+
nil
53+
end
54+
55+
def checksum_path
56+
File.join(@build_dir, 'build.checksum')
57+
end
58+
59+
def checksum
60+
@checksum ||= Digest::SHA1.file(tarball_path).hexdigest
61+
end
62+
63+
def command!(*args)
64+
puts "$ #{args.join(' ')}"
65+
unless system(*args)
66+
raise "Command failed with status #{$?.exitstatus}"
67+
end
68+
end
69+
end
70+
71+
exit Builder.new(ARGV[0], ARGV[1]).run

makefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
TEST_FILES := $(shell find test -name *_test.rb -type f)
22
REDIS_BRANCH := unstable
33
TMP := tmp
4-
BUILD_DIR := ${TMP}/redis-${REDIS_BRANCH}
4+
BUILD_DIR := ${TMP}/cache/redis-${REDIS_BRANCH}
55
TARBALL := ${TMP}/redis-${REDIS_BRANCH}.tar.gz
66
BINARY := ${BUILD_DIR}/src/redis-server
77
PID_PATH := ${BUILD_DIR}/redis.pid
@@ -17,19 +17,14 @@ test: ${TEST_FILES}
1717
${TMP}:
1818
mkdir $@
1919

20-
${TARBALL}: ${TMP}
21-
wget https://github.com/antirez/redis/archive/${REDIS_BRANCH}.tar.gz -O $@
22-
23-
${BINARY}: ${TARBALL} ${TMP}
24-
rm -rf ${BUILD_DIR}
25-
mkdir -p ${BUILD_DIR}
26-
tar xf ${TARBALL} -C ${TMP}
27-
cd ${BUILD_DIR} && make
20+
${BINARY}: ${TMP}
21+
bin/build ${REDIS_BRANCH} ${TMP}
2822

2923
stop:
3024
(test -f ${PID_PATH} && (kill $$(cat ${PID_PATH}) || true) && rm -f ${PID_PATH}) || true
3125

3226
start: ${BINARY}
27+
echo ${BINARY}
3328
${BINARY} \
3429
--daemonize yes \
3530
--pidfile ${PID_PATH} \

0 commit comments

Comments
 (0)