Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Makefile target to run it tests inside Docker #487

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:16.04

ARG NEW_USER_UID
ARG NEW_USER

RUN apt-get -y update && \
apt-get install -y curl python3 python3-pip vim openssh-client \
git make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \
openjdk-8-jdk

RUN pip3 install tox virtualenvwrapper twine sphinx sphinx_rtd_theme wheel

RUN curl --progress-bar -o openjdk-10.0.1_linux-x64_bin.tar.gz \
https://download.java.net/java/GA/jdk10/10.0.1/fb4372174a714e6b8c52526dc134031e/10/openjdk-10.0.1_linux-x64_bin.tar.gz && \
mkdir -p /opt/jdk-10 ; tar xzf openjdk-10.0.1_linux-x64_bin.tar.gz -C /opt/jdk-10 --strip-components 1 && rm openjdk-10.0.1_linux-x64_bin.tar.gz

RUN useradd -u ${NEW_USER_UID} -U -d /home/${NEW_USER} -s /bin/bash -m ${NEW_USER}

USER ${NEW_USER}
WORKDIR /home/${NEW_USER}

RUN git clone https://github.com/yyuu/pyenv.git ~/.pyenv

ENV HOME /home/${NEW_USER}
ENV PYENV_ROOT=/home/${NEW_USER}/.pyenv
ENV PATH=$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
ENV JAVA_HOME=/opt/jdk-10
ENV RUNTIME_JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

RUN pyenv install 3.4.8
RUN pyenv install 3.5.5
RUN pyenv install 3.6.5
RUN pyenv global 3.6.5 3.5.5 3.4.8
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
clean:
clean: nondocs-clean docs-clean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether clean should clean everything (including Python caches).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ambivalent about this one because it you don't use docker it will introduce some slowness every time you run make docs or make it as I've noticed some downloads happening. At the same time it ensures consistency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it does not make sense to clean Python caches for make docs. However, I think for make it would make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would make sense for make it. I think we should add it to the individual it34/35/36 targets too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.


nondocs-clean:
rm -rf .benchmarks .eggs .tox .rally_it .cache build dist esrally.egg-info logs junit-py*.xml

docs-clean:
cd docs && $(MAKE) clean

# Avoid conflicts between .pyc/pycache related files created by local Python interpreters and other interpreters in Docker
python-caches-clean:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I type make python-caches-clean locally (on MacOS), I get:

(.venv) daniel@io:Projects/rally ‹pr/487›$ make python-caches-clean
find ./ -name "__pycache__" -exec rm -rf -- \{\} \;
find: .//.venv/lib/python3.6/__pycache__: No such file or directory
[...]
find: .//tests/utils/__pycache__: No such file or directory
make: [python-caches-clean] Error 1 (ignored)
find ./ -name ".pyc" -exec rm -rf -- \{\} \;

Copy link
Contributor Author

@dliappis dliappis May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, this is harmless and should always return exit 0 due to the - prefix in the command.

Consecutive slashes will get collapsed as per the Single Unix Specification.

Seems that using . instead of ./ makes the output look saner on macOS so I'll push this plus an @ to suppress output echoing altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Makes sense.

-@find . -name "__pycache__" -exec rm -rf -- \{\} \;
-@find . -name ".pyc" -exec rm -rf -- \{\} \;

docs:
cd docs && $(MAKE) html

test:
python3 setup.py test

it:
it: python-caches-clean
tox

it34:
it34: python-caches-clean
tox -e py34

it35:
it35: python-caches-clean
tox -e py35

it36:
it36: python-caches-clean
tox -e py36

benchmark:
Expand All @@ -34,4 +43,11 @@ release-checks:
release: release-checks clean docs it
./release.sh $(release_version) $(next_version)

.PHONY: clean docs test it it34 it35 it36 benchmark coverage release release-checks
docker-it: nondocs-clean python-caches-clean
@if ! export | grep UID; then export UID=$(shell id -u); fi ; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with this syntax. Why is there an @ in the first line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ causes make to suppress echoing: https://www.gnu.org/software/make/manual/make.html#Echoing

less junk on the output esp. with if's that can confuse the user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about that. I also saw now that this is actually just one long line separated by \, i.e. all output from this target will get suppressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small correction not all output will get suppressed (e.g. the output generated from the commands themselves e.g. make it output will get displayed as expected).

e.g. if you have a Makefile target called:

testme:
    @ls

this will display the ls output normally but not the ls command itself, which would be the case without @.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should have said "echoing" instead of "output". Thanks for the explanation.

if ! export | grep USER; then export USER=$(shell echo $$USER); fi ; \
if ! export | grep PWD; then export PWD=$(shell pwd); fi ; \
docker-compose build --pull; `# add --pull here to rebuild a fresh image` \
docker-compose run --rm rally-tests /bin/bash -c "make docs-clean && make it"

.PHONY: clean nondocs-clean docs-clean python-caches-clean docs test docker-it it it34 it35 it36 benchmark coverage release release-checks
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '2.2'
services:
rally-tests:
build:
context: .
args:
- NEW_USER_UID=${UID}
- NEW_USER=${USER}
container_name: rally-tests
volumes:
- ${PWD}/.:/home/${USER}/rally
image: rally-tests
user: ${UID}
working_dir: /home/${USER}/rally
stdin_open: true
tty: true