Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take config's OS, Dist, OS X image name, known Env var values into cache slug computation #706

Merged
merged 15 commits into from
May 17, 2016

Conversation

BanzaiMan
Copy link
Contributor

@BanzaiMan BanzaiMan commented Apr 25, 2016

This PR addresses the issue with cache name collisions by taking into account extra pieces of information known at the build script compilation time.

Related issues:

travis-ci/travis-ci#4393
travis-ci/travis-ci#3023
travis-ci/travis-ci#5460

We assume that these values are reasonably set, and that environment
variables are explicitly set.

Since we must compute cache URL signatures at script compile time,
we cannot use the actual values of the environment variables at run
time.

Also note that we do *not* take secure environment variables when
computing the SHA256 digest.
@BanzaiMan
Copy link
Contributor Author

Currently, this PR does not take secure env vars into consideration. As we are just taking the SHA256 digest, I think it is acceptable to take secure env vars into computation. (There is no way to recover secure env vars from the SHA256 digest.)

@BanzaiMan BanzaiMan deployed to org-staging April 25, 2016 21:56 Active
@BanzaiMan BanzaiMan deployed to org-staging April 25, 2016 22:24 Active
@BanzaiMan
Copy link
Contributor Author

Actually, I think it is best to not include secure environment variables, since we do not use salt for the digest.

@BanzaiMan
Copy link
Contributor Author

Or add salt on the app side.

@BanzaiMan
Copy link
Contributor Author

BanzaiMan commented Apr 25, 2016

@BanzaiMan
Copy link
Contributor Author

The salt can be defined user or repo level in the database. Either as a new field (preferred) or reusing an existing secret (less preferred).

@BanzaiMan
Copy link
Contributor Author

Maybe we should take the osx_image value into account. This is a bit more granular information than OS X release (sw_vers -productVersion), but it is better than corrupt caches.

@BanzaiMan
Copy link
Contributor Author

BanzaiMan commented Apr 25, 2016

We should also consider not printing the hash at all, or omitting some characters. This requires a change to casher.

@BanzaiMan BanzaiMan changed the title Take config's OS, Dist, known Env var values into cache slug computation Take config's OS, Dist, OS X image name, known Env var values into cache slug computation Apr 26, 2016
No longer needed
@theuni
Copy link

theuni commented Apr 26, 2016

Would it be possible to include an extra user-defined salt value as well, so that individual builds may set themselves apart from others in the matrix?

We're currently working around this with a hack: https://github.com/bitcoin/bitcoin/blob/master/.travis.yml#L38

It would be great to use instead, something like:

    - cache_salt: arm
      env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="NO_QT=1" CHECK_DOC=1 GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
    - cache_salt: win32
...

Edit: or does this take all yml-defined env vars into account as well? If so, that would work solve our problem as well :)

@theuni
Copy link

theuni commented Apr 26, 2016

Ok, I clicked too fast, assuming this only applied to vars set outside of the .yml. Obviously that's not the case, and this work addresses our use-case exactly. Thanks!

@theuni
Copy link

theuni commented Apr 26, 2016

There are some cases where user-defined variables contain pre-defined vars from the builder. For example: https://travis-ci.org/bitcoin/bitcoin/jobs/125738866#L161

Would the values of vars like TRAVIS_BUILD_ID/TRAVIS_COMMIT/etc. be expanded before being used to calculate the slug? If so, I imagine there are many that would cause new cache id's for each build.

@BanzaiMan
Copy link
Contributor Author

BanzaiMan commented Apr 26, 2016

@theuni Thanks for taking time to look at this PR. I really appreciate the interest in this feature.

This PR considers only the environment variables defined in .travis.yml because only these are known at the build script compile time. This characteristic is important because in order to fetch and store caches securely, URLs have to be signed; and the signing _must happen_ at the script's compile time. (See the description of this PR.)

Some environment variables are evaluated and assigned only at the run time. Some can be reasoned beforehand (e.g., TRAVIS_BUILD_ID) but are probably not fit to be a part of the key for the cache (because the hash thus computed will never match again for future builds). We simply need to stay away from them. Users may assign others (e.g., in a script), but there is no way for travis-build to know them.

I also thought about some mechanism for the user to influence the cache name besides setting environment variables (e.g., with cache_salt as proposed in a previous comment here) with a key in .travis.yml. I like the idea, but I think the cost is rather high (in terms of cognition, and in terms of implementation). To achieve the same effect, however, one can simply set an extra environment variable that does nothing but signify the name of the cache (e.g., CACHE_NAME=arm).

@BanzaiMan BanzaiMan self-assigned this Apr 26, 2016
@BanzaiMan
Copy link
Contributor Author

My inclinations:

  • Leave secure environments out of the mix
  • Omit a few characters in the digest name in the logs

@theuni
Copy link

theuni commented Apr 27, 2016

@BanzaiMan Agree on leaving out secure vars.

As a suggestion though, it would be helpful to see (maybe behind a debug var?) which env vars have been considered for the slug, without their values.

@BanzaiMan
Copy link
Contributor Author

@theuni Do you want that information always printed? Sees a bit noisy. And adding a key to .travis.yml seems kludgy.

@theuni
Copy link

theuni commented Apr 28, 2016

@BanzaiMan No, only for troubleshooting the non-obvious cases. As a stupid example off the top of my head:

before:

env:
  global:
    - FOO=bar
matrix:
  include:
    - compiler: gcc
      env: BAR=blah
    - compiler: clang
      env:

after:

env:
  global:
    - FOO=bar BAR=blah
matrix:
  include:
    - compiler: gcc
      env:
    - compiler: clang
      env: BAR=

Do those end up with new cache ids?

It would be helpful in this case to see what's happening with BAR, as I'm not sure if empty is the same as nonexistent.

Not the end of the world if printing it is a hassle though, It would only take a few quick experiments to figure out what's happening.

@BanzaiMan
Copy link
Contributor Author

The very presence of such a variable should affect the cache name. BAR= and (absence ofBAR) are different.

So that we don't delete secure variables
Can't use `Hash#fetch` here, becauce it might be explicitly `nil`.
Conflicts:
	spec/build/script/r_spec.rb
The merge conflict was resolved incorrectly.
@BanzaiMan
Copy link
Contributor Author

This has been deployed to production. I will observe how it behaves for the next several hours, after which, if it's behaving well, I will merge this code and redeploy.

BanzaiMan added 2 commits May 16, 2016 15:31
Given a cache with name like:

    cache-linux-precise-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855--rvm-2.0.0--gemfile-Gemfile.tgz

We want

    cache--rvm-2.0.0--gemfile-Gemfile.tgz

not

    cache--gemfile-Gemfile.tgz
(and was fixed by the previous commit)
@BanzaiMan BanzaiMan deployed to org-staging May 17, 2016 05:25 Active
@BanzaiMan BanzaiMan deployed to org-production May 17, 2016 05:25 Active
@BanzaiMan BanzaiMan deployed to com-production May 17, 2016 05:25 Active
BanzaiMan added a commit to travis-ci/docs-travis-ci-com that referenced this pull request May 17, 2016
BanzaiMan added a commit to travis-ci/docs-travis-ci-com that referenced this pull request May 17, 2016
@BanzaiMan BanzaiMan merged commit f307afe into master May 17, 2016
@BanzaiMan BanzaiMan deleted the ha-feature-cache-naming branch May 17, 2016 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants