Skip to content

Commit 5876439

Browse files
committed
add documentation how to compare Dockerfiles created between current and oder version of r2d
1 parent 28261be commit 5876439

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ test_file_text.txt
3333

3434

3535
\.vscode/
36+
37+
tests/dockerfile_diff.sh

docs/source/contributing/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Then you are good to go!
202202
If you only changed the documentation, you can also build the documentation locally using `sphinx` .
203203

204204
```bash
205-
#pip install -r docs/doc-requirements.txt
205+
pip install -r docs/doc-requirements.txt
206206

207207
cd docs/
208208
make html

docs/source/contributing/tasks.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,58 @@ same syntax to update the Pipfile and viceversa.
202202

203203
At the moment this has to be done manually so please make sure to update both
204204
files accordingly.
205+
206+
# Uncommon tasks
207+
208+
## Compare generated Dockerfiles between repo2docker versions
209+
210+
For larger refactorings it can be useful to check that the generated Dockerfiles match
211+
between an older version of r2d and the current version. The following shell script
212+
automates this test.
213+
214+
```bash
215+
#! /bin/bash -e
216+
217+
current_version=$(jupyter-repo2docker --version | sed s@+@-@)
218+
echo "Comparing $(pwd) (local $current_version vs. $R2D_COMPARE_TO)"
219+
basename="dockerfilediff"
220+
221+
diff_r2d_dockerfiles_with_version () {
222+
docker run --rm -t -v "$(pwd)":"$(pwd)" --user 1000 jupyter/repo2docker:"$1" jupyter-repo2docker --no-build --debug "$(pwd)" &> "$basename"."$1"
223+
jupyter-repo2docker --no-build --debug "$(pwd)" &> "$basename"."$current_version"
224+
225+
# remove first line logging the path
226+
sed -i '/^\[Repo2Docker\]/d' "$basename"."$1"
227+
sed -i '/^\[Repo2Docker\]/d' "$basename"."$current_version"
228+
229+
diff --strip-trailing-cr "$basename"."$1" "$basename"."$current_version" | colordiff
230+
rm "$basename"."$current_version" "$basename"."$1"
231+
}
232+
233+
startdir="$(pwd)"
234+
cd "$1"
235+
236+
#diff_r2d_dockerfiles 0.10.0-22.g4f428c3.dirty
237+
diff_r2d_dockerfiles_with_version "$R2D_COMPARE_TO"
238+
239+
cd "$startdir"
240+
```
241+
242+
Put the code above in a file `tests/dockerfile_diff.sh` and make it executable: `chmod +x dockerfile_diff.sh`.
243+
244+
Configure the repo2docker version you want to compare with your local version in the environment variable `R2D_COMPARE_TO`.
245+
The scripts takes one input: the directory where repo2docker should be executed.
246+
247+
```bash
248+
cd tests/
249+
R2D_COMPARE_TO=0.10.0 ./dockerfile_diff.sh venv/py35/
250+
```
251+
252+
Run it for all directories where there is a `verify` file:
253+
254+
```bash
255+
cd tests/
256+
R2D_COMPARE_TO=0.10.0 CMD=$(pwd)/dockerfile_diff.sh find . -name 'verify' -execdir bash -c '$CMD $(pwd)' \;
257+
```
258+
259+
To keep the created Dockefilers for further inspection, comment out the deletion line in the script.

0 commit comments

Comments
 (0)