Skip to content

Commit

Permalink
[Fix #2144] Create a docker image to mimic the TravisCI environment (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gonewest818 authored and bbatsov committed Dec 20, 2017
1 parent c908e8d commit ad0c997
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [#2111](https://github.com/clojure-emacs/cider/pull/2111): Add `cider-pprint-eval-last-sexp-to-comment` and `cider-pprint-eval-defun-to-comment`.
* Add a REPL shortcut for `cider-repl-require-repl-utils` (this makes it easy to require common functions like `doc`, `source`, etc. in REPL buffers).
* [#2112](https://github.com/clojure-emacs/cider/issues/2112): Add a new interactive command `cider-find-keyword` (bound to `C-c C-:`).
* [#2144](https://github.com/clojure-emacs/cider/issues/2144): Create a Docker image to mimic the Travis environment

### Changes

Expand Down
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM travisci/ci-garnet:packer-1490989530

RUN apt-get update -y \
&& apt-get install -y \
autogen \
ca-certificates \
curl \
gcc \
git \
libgmp-dev \
m4 \
make \
pkg-config \
python \
ruby \
xz-utils

USER travis
ENV HOME=/home/travis
ENV PATH="${HOME}/local/evm/bin:${HOME}/local/cask/bin:${HOME}/local/bin:${PATH}"

ADD travis-ci/ ${HOME}/cider-setup/travis-ci/
RUN echo ". ${HOME}/cider-setup/travis-ci/prompt.sh" >> ${HOME}/.bashrc

RUN ${HOME}/cider-setup/travis-ci/install-gnutls.sh
RUN ${HOME}/cider-setup/travis-ci/install-evm.sh
RUN ${HOME}/cider-setup/travis-ci/install-cask.sh

RUN evm install emacs-25.3-travis --use
RUN evm install emacs-26-pretest-travis
RUN evm install emacs-git-snapshot-travis

WORKDIR /home/travis/cider
CMD /bin/bash
66 changes: 66 additions & 0 deletions doc/hacking_on_cider.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,72 @@ You can also check for the presence of byte-compilation warnings in batch mode:
$ make test-bytecomp
```

#### Running the tests in Travis CI

If you prefer to see the full Travis test suite run successfully, the easiest
way to achieve that is to create your own personal account on
https://travis-ci.org. View your profile details on the Travis site, and toggle
the switch to enable builds on your fork of the cider project.

Subsequent pushes to your fork will generate a Travis build you can monitor for
success or failure.

#### Simulating the Travis tests locally in Docker

If you prefer not to wait for Travis all the time, or if you need to debug
something that fails in Travis but does not fail for you on your own machine,
then you can also run the Travis tests manually in Docker.

You will need to run some scripts to build and launch the Docker image.

To build:
```
$ docker/build.sh
```

The build script uses a base image provided by the engineers at Travis. Note: the
Travis docker image is currently more than 8GB, so be prepared with a good
internet connection and time to spare.

The resulting docker image is tagged simply `cider-travis`. You can run this
image by hand, but there is a convenience script available:
```
$ docker/run.sh
```

This script launches a docker container and bind-mounts your cider project
directory as `/home/travis/cider` such that you can instantly see any code
changes reflected inside the docker environment.

For instance, you can run tests on emacs 25.3
```
(emacs-25.3-travis) ~/cider$ make test
```

and then switch to emacs 26 and test again

```
(emacs-25.3-travis) ~/cider$ evm use emacs-26-pretest-travis
(emacs-26-pretest-travis) ~/cider$ cask install
(emacs-26-pretest-travis) ~/cider$ make test
```

You can test byte compilation too
```
(emacs-26-pretest-travis) ~/cider$ make test-bytecomp
```

When you are done working in docker, just `exit` the bash prompt, and the docker
container will also exit. Note that `docker/run.sh` runs the container with
`--rm`, meaning any changes to the docker container are discarded when the
container exits.

So for example, by default, the docker image pre-installs only the most recent
releases of emacs 25, emacs 26, and a recent snapshot of the emacs git
repository. The `evm` tool is available should you need to install some other
specific build. However additional versions of emacs will be discarded when
you exit the docker container.

## Hacking on cider-nrepl

### Obtaining the code
Expand Down
4 changes: 4 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker build -t cider-travis .

4 changes: 4 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker run -it --rm -v `pwd`:/home/travis/cider cider-travis bash

12 changes: 7 additions & 5 deletions travis-ci/install-cask.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash
#!/bin/bash -x

# Install cask for Travis CI
# or if already installed, then check for updates

set -x

WORKDIR=${HOME}/local
CASKDIR=$WORKDIR/cask
SCRIPTDIR=`dirname $(readlink -f $0)`

. travis-ci/retry.sh
. $SCRIPTDIR/retry.sh

cask_upgrade_cask_or_reset() {
cask upgrade-cask || { rm -rf $HOME/.emacs.d/.cask && false; }
Expand All @@ -30,4 +29,7 @@ fi
# Install dependencies for cider as descriped in ./Cask
# Effect is identical to "make elpa", but here we can retry
# in the event of network failures.
travis_retry cask_install_or_reset && touch elpa-emacs
if [ -f Cask ]
then
travis_retry cask_install_or_reset && touch elpa-emacs
fi
7 changes: 3 additions & 4 deletions travis-ci/install-evm.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash
#!/bin/bash -x

# Install evm for Travis CI
# or if already installed, then check for updates

set -x

WORKDIR=${HOME}/local
EVMDIR=$WORKDIR/evm
SCRIPTDIR=`dirname $(readlink -f $0)`

. travis-ci/retry.sh
. $SCRIPTDIR/retry.sh

if [ -d $EVMDIR ]
then
Expand Down
10 changes: 7 additions & 3 deletions travis-ci/install-gnutls.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/bin/bash
#!/bin/bash -x

# Setup a newer gnutls-cli on Travis CI
# We need this as long as the Travis workers are Ubuntu 14.04
# and the TLS cert chain on elpa.gnu.org is out-of-order

set -x

# adjust these versions as needed
export NETTLE_VERSION=3.4
export GNUTLS_VERSION=3.5.16
Expand All @@ -14,6 +12,12 @@ export WORKDIR=${HOME}/local/
export LD_LIBRARY_PATH=${WORKDIR}/lib/
export PKG_CONFIG_PATH=${WORKDIR}/lib/pkgconfig/

# make sure workdir exists
if [ ! -d ${WORKDIR} ]
then
mkdir $WORKDIR
fi

# exit if the cache is valid and up-to-date
if [ -f ${WORKDIR}/bin/gnutls-cli ] && \
[ -f ${WORKDIR}/nettle-${NETTLE_VERSION}.tar.gz ] && \
Expand Down
1 change: 1 addition & 0 deletions travis-ci/prompt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export PS1="(\$(sed -ne 's/^.*\(emacs-.*-travis\).*$/\1/p' ~/local/evm/.config)) \w$ "

0 comments on commit ad0c997

Please sign in to comment.