在Travis CI上缓存单个文件 [英] Caching a single file on Travis CI
问题描述
在travis上的构建中,我需要先下载一个大的 .tar.gz
文件。
此 .tar.gz
永不更改,因此将其缓存是个好主意。
。 tar.gz
会在我的Dockerfile中下载:
运行curl ftp://mycompanyftp.com/foo/bar /mylargefile.tar.gz -o /tmp/mylarge.tar.gz
有了docker容器,文件就在其中构建了。 / p>
如何缓存此文件?
PS :也可以下载 before_install
上的文件,并使用docker ADD
将其放入Docker容器中。
这是不可能的,只要您在 dockerfile
中有此命令。
相反,建议您将此命令放在 .travis.yml
文件中,并作为预构建的一部分下载该文件活动:
之前_install:
如果! [-f ./src/mylarge.tar.gz];然后
curl ftp://mycompanyftp.com/foo/bar/mylargefile.tar.gz -o ./src/mylarge.tar.gz;
fi
安装:|
./scripts/build.sh;
脚本:|
./scripts/test-integration.sh;
高速缓存:
目录:
-$ TRAVIS_BUILD_DIR / src /
after_success:|
./scripts/deploy.sh;
如您所见, before_install
部分如果文件尚不存在,将下载该文件。 cache
部分将告诉Travis保留 ./ src /
目录,并在下一个版本开始时将其还原因此不会再次下载。
在您的 dockerfile
中,现在要执行的操作是下载的方法只是将本地文件复制到容器中:
COPY ./src/mylargefile.tar.gz / tmp / mylargefile.tar.gz
您可以在Travis CI的文档页面。
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.
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.
这篇关于在Travis CI上缓存单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!