问题
Inside my build on travis I need to first download a large .tar.gz
file.
This .tar.gz
never changes so it's a good idea cache it.
The .tar.gz
it's downloaded inside my Dockerfile:
RUN curl ftp://mycompanyftp.com/foo/bar/mylargefile.tar.gz -o /tmp/mylarge.tar.gz
With that the docker container build with the file inside.
How can I cache this file?
PS: It's also possible to download the file on before_install
and use docker ADD
to put it inside the Docker container.
回答1:
This is not possible as long as you have this command in your dockerfile
.
Instead, I suggest that you put this command in your .travis.yml
file and download the file as part of the pre-build activities:
before_install: |
if ! [ -f ./src/mylarge.tar.gz ]; then
curl ftp://mycompanyftp.com/foo/bar/mylargefile.tar.gz -o ./src/mylarge.tar.gz;
fi
install: |
./scripts/build.sh;
script: |
./scripts/test-integration.sh;
cache:
directories:
- $TRAVIS_BUILD_DIR/src/
after_success: |
./scripts/deploy.sh;
As you can see, the before_install
section will download the file if it does not exist already. The cache
section will tell Travis to keep the ./src/
directory and restore it at the beginning of your next build so it will not be downloaded for a second time.
In your dockerfile
, what you want to do now instead of downloading is to just copy the local file into the container:
COPY ./src/mylargefile.tar.gz /tmp/mylargefile.tar.gz
You can read more about caching on Travis CI on their docs page.
来源:https://stackoverflow.com/questions/35203169/caching-a-single-file-on-travis-ci