roboticslab-uc3m / questions-and-answers

A place for general debate and question&answer
https://robots.uc3m.es/developer-manual/appendix/repository-index.html
2 stars 0 forks source link

Cache dependencies (e.g. YARP) in Travis #48

Closed PeterBowman closed 6 years ago

PeterBowman commented 6 years ago

Thanks to #17, weekly cron jobs automatically test latest commits on production against YARP's devel branch. Currently, YARP needs to be cloned and built on every push action, and so do other dependencies (e.g. KDL, PCL, OpenRAVE).

Proposal: for non-cron jobs (perhaps cron too if it makes sense), store YARP (and other dependencies if present) in the Travis cache (docs) in order to speed up things. It's preferrable to hold a global variable with the targeted version so that it can be easily bumped in the YAML file with every new release. Speaking of YARP, current master is tagged at 2.3.72.

Caching has been extensively tested on https://github.com/asrob-uc3m/robotDevastation, see .travis.yml and latest builds.

PeterBowman commented 6 years ago

Another example of caching (CMake + YARP): roboticslab-uc3m/project-generator.

BTW those larger blocks of YAML code (example) could be better placed as standalone shell scripts in scripts/travis/.

PeterBowman commented 6 years ago

Build times have been cut by a half thanks to https://github.com/roboticslab-uc3m/kinematics-dynamics/compare/9bc689c...e21895c (cache YARP + KDL deps). Two issues arise:

PeterBowman commented 6 years ago

I'd like to solve https://github.com/roboticslab-uc3m/installation-guides/issues/13 first, but not marking as blocked until further investigation.

As spoken with @jgvictores, let's add another shell script for use by Travis that would extract/deduce the time of creation of the latest cache, then invalidate an regenerate it if older than, say, one week. A new cron job launched once per week would perform this sequence again so that we don't need to wait for the next push build (which may or may not happen in a long time). Also, let's clone and store latest YARP master in this cache instead of a specific release.

PeterBowman commented 6 years ago

Regarding dependencies, caching and containerization: https://github.com/robotology/yarp/issues/1625.

PeterBowman commented 6 years ago

I had to compile YARP with ACE in order to solve that

Fixed at https://github.com/roboticslab-uc3m/kinematics-dynamics/commit/ebcfb55df254d68ebbd3df28bbbdd7952d845a76.

Less sudos led me to think about container-based build on Travis. Sadly, libace-dev has not been whitelisted (yet?)

No more ACE, and the only relevant sudo left in the whole YAML file is this one. See #50.

PeterBowman commented 6 years ago

let's add another shell script for use by Travis that would extract/deduce the time of creation of the latest cache, then invalidate an regenerate it if older than, say, one week

Alternatively, check the latest remote commit against a cached copy, then only invalidate and regenerate the cache if not the last one. Would need a clone operation (other option involves a SSH connection per this SO answer), but it could improve times significantly when working with non-tagged dependencies such as OpenRAVE.

Edit: not so straightforward with GitHub, requires adding SSH keys.

Edit 2 (note to self): clone only specific branches (e.g. master and devel, specified in the /scripts/cache-<pkg>.sh) with --depth=1, don't invalidate cache if same revision as the one stored. Extensible to our own repos, e.g. yarp-devices! Keep using wget with tagged releases (e.g. v2.3.72.1).

PeterBowman commented 6 years ago

Notes:

PeterBowman commented 6 years ago

Conditions and matrix.exclude don't cope well together.

Per https://blog.travis-ci.com/2017-09-12-build-stages-order-and-conditions:

Jobs need to be listed explicitely, i.e. using jobs.include or matrix.include (alias), in order to specify conditions for them. Jobs created via matrix expansion currently cannot have conditions.

PeterBowman commented 6 years ago

I have refactored the caching script (now it's a single .sh file that accepts several options via CLI) and applied it to all kin-dyn's dependencies at https://github.com/roboticslab-uc3m/kinematics-dynamics/commit/fe405d3c0682a01087a93f220f87eb6e24edfc60.

Notes:

PeterBowman commented 6 years ago

Since YARP's master and release jobs are already covered, I'd rather omit them on cron, but it's not that simple (see previous comments).

In fact, YARP's master branch builds would make sense once per week, so keep them. Perhaps I could configure Travis in such a way that release builds (e.g. YARP 2.3.70.2, 2.3.72.1, etc.) are added with matrix.include and if: type != cron, thus they wouldn't be considered for current weekly cron builds.

Edit: however, other dependencies (e.g. KDL, OpenRAVE, our RL projects...) might respond differently to distinct YARP releases. It would make sense to test everything on weekly cron builds, then.

PeterBowman commented 6 years ago

Idea: move Travis-related bash scripts (in scripts/travis/) to a separate repo (perhaps even a gist?) and clone/download it on every build.

PeterBowman commented 6 years ago

Remark: ccache (official page) does not seem to improve build times. In fact, they are significantly worse on the first (cold) run, and perhaps a bit longer than usual on successive (warm) runs.

PeterBowman commented 6 years ago

Some updates on this:

PeterBowman commented 6 years ago

Idea: move Travis-related bash scripts (in scripts/travis/) to a separate repo (perhaps even a gist?) and clone/download it on every build.

Alternatively, use git submodules that point to a branch (usually, they point at a specific commit): https://www.activestate.com/blog/2014/05/getting-git-submodule-track-branch.

See also https://git-scm.com/docs/gitmodules.

PeterBowman commented 6 years ago

In recent versions of Git, specific branches can be tracked - there is a convenient branch property in .gitmodules for such purpose. With the new --remote option to git submodule update, Git will fetch the latest HEAD commit of said branch and merge it into the current submodule tree (see docs regarding the update command). Still, the hosting repository will track a specific commit instead, which is what I wanted to avoid or circumvent. My original intention was to decouple somehow the revision history of this internal repository and let Travis fetch whatever commit was last at that time. It doesn't make much sense on a second thought, though.

On the other hand, gists can be either cloned (full history) or downloaded (specific or latest commit). However, they must live in a user account.

Edit: check my submodule experiments at https://github.com/roboticslab-uc3m/kinematics-dynamics/commit/f7f22f2006430b7451ca320d14d075bf1c364648 (Travis CI).

jgvictores commented 6 years ago

Looking at https://github.com/roboticslab-uc3m/kinematics-dynamics/commit/f7f22f2006430b7451ca320d14d075bf1c364648 and not fully understanding everything... I guess https://github.com/PeterBowman/travis-scripts is something that existed at some time?

PeterBowman commented 6 years ago

Yes, I just moved the contents of scripts/travis/ in there. The tests proved that Travis will not update the HEAD commit the submodule points to unless changed manually, which I hoped to avoid by setting a tracking branch in the .gitmodules file.

Let's speak about this f2f tomorrow.

PeterBowman commented 6 years ago

As spoken with @jgvictores, and as a better alternative to using Gists, we could move those scripts to a separate repo (just as I did) and treat it as another hard dependency. Then, Travis would process it in the before_install section (either git clone or wget a branch).

Since this is not a priority, (harmless) duplicates of said scripts will be created for now.

PeterBowman commented 6 years ago

See implementation at https://github.com/roboticslab-uc3m/kinematics-dynamics/commit/c597f7a581e34234f0072312a2768513c8915777.

PeterBowman commented 6 years ago

For future reference (on using set -e in shell scripts sourced by Travis): https://github.com/roboticslab-uc3m/tools/commit/2f0fddb96202a20feadc9546e8916e86de9dea34.

PeterBowman commented 6 years ago

@jgvictores would you like to have this enabled on xgnitive, too? (30 minutes per job ATOW)

jgvictores commented 6 years ago

That would be very very nice!

PeterBowman commented 6 years ago

@jgvictores would you like to have this enabled on xgnitive, too? (30 minutes per job ATOW)

Done at https://github.com/roboticslab-uc3m/xgnitive/commit/8c2f26c9724e16a3b159816c583582f6b6a17ed5. BTW the Find<pkg>.cmake scripts were mostly broken and I had to update the installation guides, too: https://github.com/roboticslab-uc3m/installation-guides/commit/1fa60070041afefb183db710a634be2f0bbfe59a. I'm applying the same policy as everywhere else (testing against YARP 2.3.70/2.3.72/master + YARP devel on weekly cron jobs), please adjust it to your needs.

PeterBowman commented 6 years ago

Done on all Travis-enabled repos except gait. Final notes:

PeterBowman commented 5 years ago

As mentioned in earlier comments, if support is dropped for previous dependency releases, their associated cache directory will remain on server disks. Therefore, the entire cache should be invalidated (e.g. we no longer want to perform tests on YARP 2.3.70, so we remove that line from .travis.yml). I wonder if Travis itself invalidates the storage from time to time. Otherwise, another cron script could take care of this (see previous point).

The cache is invalidated after 28 days (ref):

Cache archives are currently set to expire after 28 days for open source projects and 45 days for private projects. This means a specific cache archive will be deleted if it wasn’t changed after its expiration delay.

Anyway, that policy is enforced for dangling/old branches, I'm not sure whether the cache files for an active branch (say, develop) would be deleted if not changed - even if used regularly (cron jobs). Manual invalidation is still recommended in the aforementioned case, see https://github.com/roboticslab-uc3m/questions-and-answers/issues/83.