Skip to content

Commit

Permalink
Add script to compare Dockerfiles generated by current and older… (#785)
Browse files Browse the repository at this point in the history
Add script to compare Dockerfiles generated by current and older version of repo2docker
  • Loading branch information
betatim committed Sep 8, 2019
2 parents 2bbd8ee + 5876439 commit 57919b9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ test_file_text.txt


\.vscode/

tests/dockerfile_diff.sh
13 changes: 13 additions & 0 deletions docs/source/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,16 @@ Server:
```

Then you are good to go!

## Building the documentation locally

If you only changed the documentation, you can also build the documentation locally using `sphinx` .

```bash
pip install -r docs/doc-requirements.txt

cd docs/
make html
```

Then open the file `docs/build/html/index.html` in your browser.
55 changes: 55 additions & 0 deletions docs/source/contributing/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,58 @@ same syntax to update the Pipfile and viceversa.

At the moment this has to be done manually so please make sure to update both
files accordingly.

# Uncommon tasks

## Compare generated Dockerfiles between repo2docker versions

For larger refactorings it can be useful to check that the generated Dockerfiles match
between an older version of r2d and the current version. The following shell script
automates this test.

```bash
#! /bin/bash -e

current_version=$(jupyter-repo2docker --version | sed s@+@-@)
echo "Comparing $(pwd) (local $current_version vs. $R2D_COMPARE_TO)"
basename="dockerfilediff"

diff_r2d_dockerfiles_with_version () {
docker run --rm -t -v "$(pwd)":"$(pwd)" --user 1000 jupyter/repo2docker:"$1" jupyter-repo2docker --no-build --debug "$(pwd)" &> "$basename"."$1"
jupyter-repo2docker --no-build --debug "$(pwd)" &> "$basename"."$current_version"

# remove first line logging the path
sed -i '/^\[Repo2Docker\]/d' "$basename"."$1"
sed -i '/^\[Repo2Docker\]/d' "$basename"."$current_version"

diff --strip-trailing-cr "$basename"."$1" "$basename"."$current_version" | colordiff
rm "$basename"."$current_version" "$basename"."$1"
}

startdir="$(pwd)"
cd "$1"

#diff_r2d_dockerfiles 0.10.0-22.g4f428c3.dirty
diff_r2d_dockerfiles_with_version "$R2D_COMPARE_TO"

cd "$startdir"
```

Put the code above in a file `tests/dockerfile_diff.sh` and make it executable: `chmod +x dockerfile_diff.sh`.

Configure the repo2docker version you want to compare with your local version in the environment variable `R2D_COMPARE_TO`.
The scripts takes one input: the directory where repo2docker should be executed.

```bash
cd tests/
R2D_COMPARE_TO=0.10.0 ./dockerfile_diff.sh venv/py35/
```

Run it for all directories where there is a `verify` file:

```bash
cd tests/
R2D_COMPARE_TO=0.10.0 CMD=$(pwd)/dockerfile_diff.sh find . -name 'verify' -execdir bash -c '$CMD $(pwd)' \;
```

To keep the created Dockefilers for further inspection, comment out the deletion line in the script.

0 comments on commit 57919b9

Please sign in to comment.