Skip to content

Commit e8ece33

Browse files
author
carlad
committed
update custom software install and add caching
1 parent 15a6cef commit e8ece33

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

user/migrating-from-legacy.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ For Ruby projects, it's as simple as adding `cache: bundler` to your .travis.yml
3333

3434
## How can I use it?
3535

36-
Using our new container-based stack only requires one additional line in your .travis.yml:
36+
If you see this on your log `This job is running on container-based infrastructure` it means you are already running on our container-based stack.
37+
38+
Otherwise, using our container-based stack only requires one additional line in your .travis.yml:
3739

3840
`sudo: false`
3941

@@ -106,17 +108,53 @@ To install something from source, you can follow similar steps. Here's an exampl
106108
install:
107109
- wget https://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz
108110
- tar -xzvf protobuf-2.4.1.tar.gz
109-
- cd protobuf-2.4.1 && ./configure --prefix=/usr && make && sudo make install
111+
- cd protobuf-2.4.1 && ./configure --prefix=$HOME/protobuf && make && make install
110112

111113
These three commands can be extracted into a shell script, let's name it `install-protobuf.sh`:
112114

113115
#!/bin/sh
114116
set -ex
115117
wget https://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz
116118
tar -xzvf protobuf-2.4.1.tar.gz
117-
cd protobuf-2.4.1 && ./configure --prefix=/usr && make && sudo make install
119+
cd protobuf-2.4.1 && ./configure --prefix=$HOME/protobuf && make && make install
118120

119-
Once it's added to the repository, you can run it from your .travis.yml:
121+
Once it's added to the repository, you can run it from your `.travis.yml`:
120122

121123
before_install:
122124
- ./install-protobuf.sh
125+
126+
We can also add a `script` command to list the contect of the protobuf folder to make sure it's been installed:
127+
128+
script:
129+
- ls -R $HOME/protobuf
130+
131+
## How Do I Cache Dependencies and Directories?
132+
133+
In the example above, to avoid having to download and compile the protobuf library each time we run a build, we can cache its directory.
134+
135+
We add the following to our `.travis.yml`:
136+
137+
cache:
138+
directories:
139+
- $HOME/protobuf
140+
141+
And then change our shell script to only compile and install if the cached directory is not empty:
142+
143+
#!/bin/sh
144+
set -ex
145+
# check to see if protobuf folder is empty
146+
if [ ! -d "$HOME/protobuf/lib" ]; then
147+
wget https://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz
148+
tar -xzvf protobuf-2.4.1.tar.gz
149+
cd protobuf-2.4.1 && ./configure --prefix=$HOME/protobuf && make && make install
150+
else
151+
echo 'Using cached directory.'
152+
fi
153+
154+
See [here](https://github.com/travis-ci/container-example) for a working example of compiling, installing, and caching protobuf.
155+
156+
More information about using caching can be found in our [Caching Directories and Dependencies](http://docs.travis-ci.com/user/caching/) doc.
157+
158+
## Need Help?
159+
160+
Email [support](mailto: [email protected]) or create a GitHub issue.

0 commit comments

Comments
 (0)