From 1d58862bc787f48b089e580b9b25c499204c8589 Mon Sep 17 00:00:00 2001 From: Aurelio Jargas Date: Sat, 27 Jun 2020 02:08:05 +0200 Subject: [PATCH] Move Docker image to new repo, use dev-only image In #34, development tools were added to the clitest Docker image, making it both an end user image and a development environment. This was a bad idea. This commit separates them in two different images. - The public clitest image was moved to a new repository: https://github.com/aureliojargas/clitest-docker. Now everything is automated and releasing a new clitest image to Docker Hub is just a matter of adding a git tag to that repository. Everything related to that image was removed from this repository. - The local development image remains here, named `clitest-dev` and described in the new `Dockerfile.dev` file. It does not have clitest inside it, it's just the development environment. When running the image, the current clitest code should be mounted inside it. In short, everything dev-related is here. After releasing a new clitest version (here), go to the other repository to make the official Docker image for it. --- Dockerfile | 14 ------ Dockerfile.dev | 19 ++++++++ Makefile | 14 +++--- README-docker.md | 118 ----------------------------------------------- README.md | 17 +++++-- 5 files changed, 38 insertions(+), 144 deletions(-) delete mode 100644 Dockerfile create mode 100644 Dockerfile.dev delete mode 100644 README-docker.md diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4b56aeb..0000000 --- a/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM alpine:3.11 - -# Perl is required by clitest's --regex matching mode -RUN apk --no-cache add \ - bash dash mksh zsh \ - perl \ - make \ - checkbashisms shellcheck - -COPY clitest test.md /clitest/ -COPY test/ /clitest/test/ -RUN ln -s /clitest/clitest /usr/local/bin/clitest - -WORKDIR /clitest diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..32c1d45 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,19 @@ +# clitest-dev +# Local Docker image used for clitest development. +# +# It has all the required tools for linting and testing clitest code. +# See Makefile for commands to build and run this image. +# +# If you're searching for the official clitest Docker image (for users): +# https://hub.docker.com/r/aureliojargas/clitest + +FROM alpine:3.11 + +# Perl is required by clitest's --regex matching mode +RUN apk --no-cache add \ + bash dash mksh zsh \ + perl \ + make \ + checkbashisms shellcheck + +WORKDIR /mnt diff --git a/Makefile b/Makefile index dbbe46a..1f3c552 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ # Developer workflow: run locally the same commands Travis will run in # the CI. See the .travis.yml file for the list of commands. # -# By default, the linting and testing targets are run inside the clitest -# Docker container. To run them directly on the host, avoiding the -# container, unset the `docker_run` variable. Examples: +# By default, the linting and testing targets are run inside the +# clitest-dev Docker container. To run them directly on the host, +# avoiding the container, unset the `docker_run` variable. Examples: # # make test-bash # test using container's bash # make test-bash docker_run= # test using host's bash -docker_image = aureliojargas/clitest -docker_run = docker run --rm -it -v $$PWD:/clitest $(docker_image) -test_cmd = clitest --first --progress none test.md +docker_image = clitest-dev +docker_run = docker run --rm -it -v $$PWD:/mnt $(docker_image) +test_cmd = ./clitest --first --progress none test.md default: @echo "Read the comments in the Makefile for help" @@ -27,7 +27,7 @@ versions: @$(docker_run) sh -c 'apk list 2>/dev/null | cut -d " " -f 1 | sort' docker-build: - docker build -t $(docker_image) . + docker build -t $(docker_image) -f Dockerfile.dev . docker-run: $(docker_run) $(cmd) diff --git a/README-docker.md b/README-docker.md deleted file mode 100644 index 65bdbe3..0000000 --- a/README-docker.md +++ /dev/null @@ -1,118 +0,0 @@ -# clitest Docker image - -This is a [clitest](https://github.com/aureliojargas/clitest) Docker image based on the lightweight [Alpine Linux image](https://hub.docker.com/_/alpine/). - -## Get it - -``` -docker pull aureliojargas/clitest -``` - -## Initial run - -For the available clitest options, just run the image with the command `clitest --help`: - -```console -$ docker run --rm aureliojargas/clitest clitest --help -Usage: clitest [options] - -Options: - -1, --first Stop execution upon first failed test - -l, --list List all the tests (no execution) - -L, --list-run List all the tests with OK/FAIL status - -t, --test RANGE Run specific tests, by number (1,2,4-7) - -s, --skip RANGE Skip specific tests, by number (1,2,4-7) - --pre-flight COMMAND Execute command before running the first test - --post-flight COMMAND Execute command after running the last test - -q, --quiet Quiet operation, no output shown - -V, --version Show program version and exit - -Customization options: - -P, --progress TYPE Set progress indicator: test, number, dot, none - --color WHEN Set when to use colors: auto, always, never - --diff-options OPTIONS Set diff command options (default: '-u') - --inline-prefix PREFIX Set inline output prefix (default: '#=> ') - --prefix PREFIX Set command line prefix (default: '') - --prompt STRING Set prompt string (default: '$ ') -$ -``` - -## Test your own files - -To run clitest on your own test files, map their directory with `-v`. For example, mapping the current directory to container's `/src` and testing the `test.md` file: - -``` -docker run --rm -t -v "$PWD:/src/" aureliojargas/clitest clitest /src/test.md -``` - -Same as before, but this time using `-w` to set the current directory to `/src`, making sure the execution happens inside your directory: - -``` -docker run --rm -t -v "$PWD:/src/" -w /src aureliojargas/clitest clitest test.md -``` - -If you don't have any test files right now, you can see clitest in action by running its own test suite: - -```console -$ docker run --rm -t -w /clitest aureliojargas/clitest clitest test.md -#1 test -f ./clitest; echo $? -#2 test -d ./test/; echo $? -#3 COLUMNS=80 -#4 export COLUMNS -#5 echo $COLUMNS -... -#260 ./clitest test/blank-output.sh -#261 ./clitest test/no-nl-file-1.sh -#262 ./clitest test/no-nl-file-2.sh -#263 ./clitest test/no-nl-file-3.sh -#264 ./clitest test/no-nl-command.sh -#265 ./clitest --color yes --first test/fail-2.sh -OK: 265 of 265 tests passed -$ -``` - -Make sure to use `-t` in `docker run` to get colors in clitest output. - -## Build - -To build this image, go to clitest repository root and run: - -``` -make docker-build -``` - - -## About clitest - -[Clitest](https://github.com/aureliojargas/clitest) is a portable POSIX shell script that performs automatic testing in Unix command lines. - -It's the same concept as in [Python's doctest module](http://en.wikipedia.org/wiki/Doctest). You save the commands and their expected output in a text file: - -``` -$ echo "Hello World" -Hello World -$ cd /tmp -$ pwd -/tmp -$ cd "$OLDPWD" -$ -``` - -and then use clitest to run those commands and compare their output: - -```console -$ clitest examples/intro.txt -#1 echo "Hello World" -#2 cd /tmp -#3 pwd -#4 cd "$OLDPWD" -OK: 4 of 4 tests passed -$ -``` - -That's it! - -- **There's no syntax to learn**, just copy/paste the command line history into a text file. -- Useful for automated testing and testable documentation (Markdown file with commands). - -See examples and instructions in the [GitHub repository](https://github.com/aureliojargas/clitest). diff --git a/README.md b/README.md index 5365e51..65723a9 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,19 @@ sudo mv clitest /usr/bin Now check if everything is fine: -```console -$ clitest -V -clitest HEAD -https://github.com/aureliojargas/clitest/tree/HEAD -$ ``` +clitest --help +``` + + +## Docker image + +You can also run clitest in a Docker container ([more info in Docker Hub](https://hub.docker.com/r/aureliojargas/clitest)). + +``` +docker run --rm -t aureliojargas/clitest --help +``` + ## Quick Intro