diff --git a/.github/workflows/test_pull_request.yml b/.github/workflows/test_pull_request.yml index d6b364a6..c4b0d98a 100644 --- a/.github/workflows/test_pull_request.yml +++ b/.github/workflows/test_pull_request.yml @@ -24,18 +24,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - run: sudo apt-get install graphviz graphviz-dev - - run: make test-postgres + - run: ./pytest.sh lint: timeout-minutes: 5 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - run: sudo apt-get install graphviz graphviz-dev - - run: make lint + - run: ./lint.sh diff --git a/.run.docker.sh b/.run.docker.sh new file mode 100755 index 00000000..e61eec35 --- /dev/null +++ b/.run.docker.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -ex +export DOCKER_IMG=redun_python_test:redun_python_test +export DOCKER_CONTAINER_NAME=redun_python_test + +docker build . --tag $DOCKER_IMG >/dev/null + +( docker rm -f $DOCKER_CONTAINER_NAME || true ) 2>&1 >/dev/null + +docker run \ + -u "$(id -u):$(id -g)" \ + -it \ + --rm \ + --name $DOCKER_CONTAINER_NAME \ + -e PGUSER=postgres -e PGPASSWORD=postgres \ + -v "$PWD:/v" \ + -w /v \ + --net host \ + --shm-size=4gb \ + --memory 6gb \ + --memory-swap 6gb \ + $DOCKER_IMG \ + "$@" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..98329f37 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.10-bookworm +ENV DEBIAN_FRONTEND=noninteractive +RUN mkdir -p /usr/share/man/man1 /usr/share/man/man2 +RUN apt-get update -y && apt-get install -y libpq-dev gcc graphviz graphviz-dev openjdk-17-jdk libpq-dev gcc postgresql-client-15 pre-commit +RUN java --version +ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ +ENV REQUIRE_POSTGRES=1 + +# run containers with user with id 1000 +RUN useradd -rm -d /home/debian -s /bin/bash -g root -G sudo -u 1000 debian +USER debian +WORKDIR /home/debian diff --git a/docs/source/developing.md b/docs/source/developing.md index bd6639ad..40130556 100644 --- a/docs/source/developing.md +++ b/docs/source/developing.md @@ -4,6 +4,16 @@ tocpdeth: 3 # Developer guide +## One-liner to run tests using Docker & Docker-Compose + +Run `./pytest.sh` with the arguments that you would pass to `pytest`, for example: + +``` +./pytest.sh -k static +``` + +The lints also have their own shortcut: `./lint.sh` + ## Development installation If you have postgres available, (perhaps with `brew install postgresql` on macOS), you can prepare diff --git a/lint.sh b/lint.sh new file mode 100755 index 00000000..319e994f --- /dev/null +++ b/lint.sh @@ -0,0 +1,2 @@ +#!/bin/bash -e +time ./.run.docker.sh make lint diff --git a/pytest.sh b/pytest.sh new file mode 100755 index 00000000..5da234bb --- /dev/null +++ b/pytest.sh @@ -0,0 +1,3 @@ +#!/bin/bash -ex +ARGS="$@" +time ./.run.docker.sh bash -c "set -ex; export TEST_ARGS=\"$ARGS\"; make test-postgres"