Cloud CI services such as Travis CI are often used to test projects hosted on GitHub. right.
Basically, after confirming that the test has passed in the local development environment, commit and push should be performed, so the test should pass on Travis as well. However, the test sometimes fails due to mistakes in the Travis configuration file .travis.yml
or forgetting to add dependent libraries. Especially in the case of dependent libraries, if they happen to be installed in the development environment, local tests will pass and may be overlooked.
If the test fails, it will be fixed in the local environment, then pushed again and the commit history of the remote branch will be polluted, so mistakes should be avoided as much as possible (especially if you do it in someone else's repository). So, for a Python or Go language project, use Docker to set up a clean local environment, as described in .travis.yml
. I created a tool to execute tests, Loci.
First, Docker is required, so install it in advance (I will omit the installation method of Docker).
Loci can be installed if Go is installed.
$ go get github.com/jkawamoto/loci
If Homebrew is installed,
$ brew tap jkawamoto/loci
$ brew install loci
You can do it with. In other cases, there is a compiled binary on GitHub, so you can download it and place it in your path.
If you have .travis.yml
in your current directory, just run the loci
command. To test another file, pass loci <filepath>
and the file path.
Loci has files contained under the current directory and creates a container image with the packages described in .travis.yml
installed. The original image is ʻubuntu: latest`. At the first execution, it takes some time to install the package, but after the second execution, if there is no change in the dependent package, the past container image is reused as appropriate (Docker function).
If you have your own APT cache server or PyPI cache server, you can use them by using the --apt-proxy
and --pypi-proxy
flags. (Reference: Build an Apt cache server on QNAP, [Build a Pypi cache server on QNAP](http://qiita.com/jkawamoto/items/ 082af79bdf9a381a1d1b)))
All command options are as follows.
loci [global options] [script file]
If script file isn't given, .travis.yml will be used.
GLOBAL OPTIONS:
--name NAME, -n NAME creating a container named NAME to run tests,
and that container will not be deleted.
--tag TAG, -t TAG creating an image named TAG.
--base TAG, -b TAG use image TAG as the base image.
(default: "ubuntu:latest")
--verbose verbose mode, which prints Dockerfile and
entrypoint.sh.
--apt-proxy URL URL for a proxy server of apt repository.
[$APT_PROXY]
--pypi-proxy URL URL for a proxy server of pypi repository.
[$PYPI_PROXY]
--http-proxy URL URL for a http proxy server. [$HTTP_PROXY]
--https-proxy URL URL for a https proxy server. [$HTTPS_PROXY]
--no-proxy LIST Comma separated URL LIST for which proxies won't
be used. [$NO_PROXY]
--help, -h show help
--version, -v print the version
Currently, it only supports Python and Go, so we plan to increase the supported languages as needed.
Recommended Posts