Skip to content

Commit ad0c997

Browse files
gonewest818bbatsov
authored andcommitted
[Fix #2144] Create a docker image to mimic the TravisCI environment (#2145)
1 parent c908e8d commit ad0c997

File tree

9 files changed

+127
-12
lines changed

9 files changed

+127
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [#2111](https://github.com/clojure-emacs/cider/pull/2111): Add `cider-pprint-eval-last-sexp-to-comment` and `cider-pprint-eval-defun-to-comment`.
99
* 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).
1010
* [#2112](https://github.com/clojure-emacs/cider/issues/2112): Add a new interactive command `cider-find-keyword` (bound to `C-c C-:`).
11+
* [#2144](https://github.com/clojure-emacs/cider/issues/2144): Create a Docker image to mimic the Travis environment
1112

1213
### Changes
1314

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM travisci/ci-garnet:packer-1490989530
2+
3+
RUN apt-get update -y \
4+
&& apt-get install -y \
5+
autogen \
6+
ca-certificates \
7+
curl \
8+
gcc \
9+
git \
10+
libgmp-dev \
11+
m4 \
12+
make \
13+
pkg-config \
14+
python \
15+
ruby \
16+
xz-utils
17+
18+
USER travis
19+
ENV HOME=/home/travis
20+
ENV PATH="${HOME}/local/evm/bin:${HOME}/local/cask/bin:${HOME}/local/bin:${PATH}"
21+
22+
ADD travis-ci/ ${HOME}/cider-setup/travis-ci/
23+
RUN echo ". ${HOME}/cider-setup/travis-ci/prompt.sh" >> ${HOME}/.bashrc
24+
25+
RUN ${HOME}/cider-setup/travis-ci/install-gnutls.sh
26+
RUN ${HOME}/cider-setup/travis-ci/install-evm.sh
27+
RUN ${HOME}/cider-setup/travis-ci/install-cask.sh
28+
29+
RUN evm install emacs-25.3-travis --use
30+
RUN evm install emacs-26-pretest-travis
31+
RUN evm install emacs-git-snapshot-travis
32+
33+
WORKDIR /home/travis/cider
34+
CMD /bin/bash

doc/hacking_on_cider.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,72 @@ You can also check for the presence of byte-compilation warnings in batch mode:
7777
$ make test-bytecomp
7878
```
7979

80+
#### Running the tests in Travis CI
81+
82+
If you prefer to see the full Travis test suite run successfully, the easiest
83+
way to achieve that is to create your own personal account on
84+
https://travis-ci.org. View your profile details on the Travis site, and toggle
85+
the switch to enable builds on your fork of the cider project.
86+
87+
Subsequent pushes to your fork will generate a Travis build you can monitor for
88+
success or failure.
89+
90+
#### Simulating the Travis tests locally in Docker
91+
92+
If you prefer not to wait for Travis all the time, or if you need to debug
93+
something that fails in Travis but does not fail for you on your own machine,
94+
then you can also run the Travis tests manually in Docker.
95+
96+
You will need to run some scripts to build and launch the Docker image.
97+
98+
To build:
99+
```
100+
$ docker/build.sh
101+
```
102+
103+
The build script uses a base image provided by the engineers at Travis. Note: the
104+
Travis docker image is currently more than 8GB, so be prepared with a good
105+
internet connection and time to spare.
106+
107+
The resulting docker image is tagged simply `cider-travis`. You can run this
108+
image by hand, but there is a convenience script available:
109+
```
110+
$ docker/run.sh
111+
```
112+
113+
This script launches a docker container and bind-mounts your cider project
114+
directory as `/home/travis/cider` such that you can instantly see any code
115+
changes reflected inside the docker environment.
116+
117+
For instance, you can run tests on emacs 25.3
118+
```
119+
(emacs-25.3-travis) ~/cider$ make test
120+
```
121+
122+
and then switch to emacs 26 and test again
123+
124+
```
125+
(emacs-25.3-travis) ~/cider$ evm use emacs-26-pretest-travis
126+
(emacs-26-pretest-travis) ~/cider$ cask install
127+
(emacs-26-pretest-travis) ~/cider$ make test
128+
```
129+
130+
You can test byte compilation too
131+
```
132+
(emacs-26-pretest-travis) ~/cider$ make test-bytecomp
133+
```
134+
135+
When you are done working in docker, just `exit` the bash prompt, and the docker
136+
container will also exit. Note that `docker/run.sh` runs the container with
137+
`--rm`, meaning any changes to the docker container are discarded when the
138+
container exits.
139+
140+
So for example, by default, the docker image pre-installs only the most recent
141+
releases of emacs 25, emacs 26, and a recent snapshot of the emacs git
142+
repository. The `evm` tool is available should you need to install some other
143+
specific build. However additional versions of emacs will be discarded when
144+
you exit the docker container.
145+
80146
## Hacking on cider-nrepl
81147

82148
### Obtaining the code

docker/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
docker build -t cider-travis .
4+

docker/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
docker run -it --rm -v `pwd`:/home/travis/cider cider-travis bash
4+

travis-ci/install-cask.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
#!/bin/bash
1+
#!/bin/bash -x
22

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

6-
set -x
7-
86
WORKDIR=${HOME}/local
97
CASKDIR=$WORKDIR/cask
8+
SCRIPTDIR=`dirname $(readlink -f $0)`
109

11-
. travis-ci/retry.sh
10+
. $SCRIPTDIR/retry.sh
1211

1312
cask_upgrade_cask_or_reset() {
1413
cask upgrade-cask || { rm -rf $HOME/.emacs.d/.cask && false; }
@@ -30,4 +29,7 @@ fi
3029
# Install dependencies for cider as descriped in ./Cask
3130
# Effect is identical to "make elpa", but here we can retry
3231
# in the event of network failures.
33-
travis_retry cask_install_or_reset && touch elpa-emacs
32+
if [ -f Cask ]
33+
then
34+
travis_retry cask_install_or_reset && touch elpa-emacs
35+
fi

travis-ci/install-evm.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
#!/bin/bash
1+
#!/bin/bash -x
22

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

6-
set -x
7-
86
WORKDIR=${HOME}/local
97
EVMDIR=$WORKDIR/evm
8+
SCRIPTDIR=`dirname $(readlink -f $0)`
109

11-
. travis-ci/retry.sh
10+
. $SCRIPTDIR/retry.sh
1211

1312
if [ -d $EVMDIR ]
1413
then

travis-ci/install-gnutls.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/bash -x
22

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

7-
set -x
8-
97
# adjust these versions as needed
108
export NETTLE_VERSION=3.4
119
export GNUTLS_VERSION=3.5.16
@@ -14,6 +12,12 @@ export WORKDIR=${HOME}/local/
1412
export LD_LIBRARY_PATH=${WORKDIR}/lib/
1513
export PKG_CONFIG_PATH=${WORKDIR}/lib/pkgconfig/
1614

15+
# make sure workdir exists
16+
if [ ! -d ${WORKDIR} ]
17+
then
18+
mkdir $WORKDIR
19+
fi
20+
1721
# exit if the cache is valid and up-to-date
1822
if [ -f ${WORKDIR}/bin/gnutls-cli ] && \
1923
[ -f ${WORKDIR}/nettle-${NETTLE_VERSION}.tar.gz ] && \

travis-ci/prompt.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export PS1="(\$(sed -ne 's/^.*\(emacs-.*-travis\).*$/\1/p' ~/local/evm/.config)) \w$ "

0 commit comments

Comments
 (0)