From b6db602ece7c82a851c061d51aade417ed876ffe Mon Sep 17 00:00:00 2001 From: "J. Scott Elblein" Date: Wed, 28 Jun 2023 20:09:05 -0500 Subject: [PATCH 1/8] Update Dockerfile Add Wallabag bin path to environment path so it's commands (i.e console cache:clear --env=prod) can be run from anywhere. --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 7300f8f..cee45fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,6 +74,8 @@ RUN set -ex \ && rm -rf /root/.composer/* /var/www/wallabag/var/cache/* /var/www/wallabag/var/logs/* /var/www/wallabag/var/sessions/* \ && chown -R nobody:nobody /var/www/wallabag +ENV PATH="${PATH}:/var/www/wallabag/bin" + EXPOSE 80 ENTRYPOINT ["/entrypoint.sh"] CMD ["wallabag"] From e38f9adb8bad3ce544a6e119c9f413803f2ff7bf Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 22 Jul 2023 17:17:11 +0200 Subject: [PATCH 2/8] tests: move docker service start in pytest Signed-off-by: Kevin Decherf --- .github/workflows/test.yml | 19 ++++++-------- conftest.py | 4 +++ tests/test_login.py | 52 +++++++++++++++++++++++++++++++++----- 3 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 conftest.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80cf2c0..b76f642 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,17 +36,14 @@ jobs: - name: "Build image" run: docker-compose -f tests/docker-compose.${{ matrix.database }}.yml build - - name: "Run image" - run: docker-compose -f tests/docker-compose.${{ matrix.database }}.yml up -d - - name: "Install dependencies" - run: pip install pytest requests - - - name: "Check running instance" - run: docker ps - - - name: "Wait 60s" - run: sleep 60 + run: pip install pytest pytest-docker requests - name: "Run tests" - run: py.test tests/ + run: py.test --database=${{ matrix.database }} tests/ + + - name: "Get docker logs" + run: docker-compose -p "wallabag_${{ matrix.database }}" -f tests/docker-compose.${{ matrix.database }}.yml logs wallabag + + - name: "Cleanup environment" + run: docker-compose -p "wallabag_${{ matrix.database }}" -f tests/docker-compose.${{ matrix.database }}.yml down -v diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..f1d9707 --- /dev/null +++ b/conftest.py @@ -0,0 +1,4 @@ +import pytest + +def pytest_addoption(parser): + parser.addoption("--database", action="store", default="default") diff --git a/tests/test_login.py b/tests/test_login.py index 1a398fc..5a037de 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -1,13 +1,53 @@ import pytest import re import requests +import os +from requests.exceptions import ConnectionError -URL = 'http://127.0.0.1:80' +@pytest.fixture(scope="session") +def database(pytestconfig): + return pytestconfig.getoption("database") +def is_responsive(url): + try: + response = requests.get(url) + if response.status_code == 200: + return True + except ConnectionError: + return False -def test_accessing_login_page(): - r = requests.get(URL, allow_redirects=True) +@pytest.fixture(scope="session") +def docker_compose_project_name(database): + return "wallabag_{}".format(database) + +@pytest.fixture(scope="session") +def docker_cleanup(): + """Disable docker cleanup at the end of tests to get logs outside of pytest""" + return False + +@pytest.fixture(scope="session") +def docker_compose_command() -> str: + return "docker-compose" + +@pytest.fixture(scope="session") +def docker_compose_file(pytestconfig, database): + return os.path.join(str(pytestconfig.rootdir), "tests/", "docker-compose.{}.yml".format(database)) + +@pytest.fixture(scope="session") +def wallabag_service(docker_ip, docker_services): + """Ensure that wallabag service is up and responsive""" + + # `port_for` takes a container port and returns the corresponding host port + port = docker_services.port_for("wallabag", 80) + url = "http://{}:{}".format(docker_ip, port) + docker_services.wait_until_responsive( + timeout=60.0, pause=0.5, check=lambda: is_responsive(url) + ) + return url + +def test_accessing_login_page(wallabag_service): + r = requests.get(wallabag_service, allow_redirects=True) assert r.status_code == 200 assert 'Log in' in r.text @@ -16,9 +56,9 @@ def test_accessing_login_page(): assert 'Username' in r.text -def test_logging_in(): +def test_logging_in(wallabag_service): client = requests.session() - r = client.get(URL, allow_redirects=True) + r = client.get(wallabag_service, allow_redirects=True) jar = r.cookies # get csrf token @@ -39,7 +79,7 @@ def test_logging_in(): '_csrf_token': csrf } - r = client.post(URL + '/login_check', cookies=jar, data=data) + r = client.post(wallabag_service + '/login_check', cookies=jar, data=data) assert r.status_code == 200 assert '/unread/list' in r.text assert '/starred/list' in r.text From 835e9ad84bc9ea4687f5c6cf9e855fedcea7170c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 15 Jul 2023 16:09:16 +0200 Subject: [PATCH 3/8] Remove 2fa parameter --- root/etc/wallabag/parameters.template.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/root/etc/wallabag/parameters.template.yml b/root/etc/wallabag/parameters.template.yml index 826b551..eb055e2 100644 --- a/root/etc/wallabag/parameters.template.yml +++ b/root/etc/wallabag/parameters.template.yml @@ -20,7 +20,6 @@ parameters: secret: ${SYMFONY__ENV__SECRET:-ovmpmAWXRCabNlMgzlzFXDYmCFfzGv} # two factor stuff - twofactor_auth: ${SYMFONY__ENV__TWOFACTOR_AUTH:-true} twofactor_sender: ${SYMFONY__ENV__TWOFACTOR_SENDER:-no-reply@wallabag.org} # fosuser stuff From c12a84557ac377556382f1a1e2d58990f6f2ea22 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 22 Jul 2023 17:46:33 +0200 Subject: [PATCH 4/8] tests: always run ci steps for logs and cleanup Signed-off-by: Kevin Decherf --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b76f642..eb14cbe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,9 @@ jobs: run: py.test --database=${{ matrix.database }} tests/ - name: "Get docker logs" + if: ${{ always() }} run: docker-compose -p "wallabag_${{ matrix.database }}" -f tests/docker-compose.${{ matrix.database }}.yml logs wallabag - name: "Cleanup environment" + if: ${{ always() }} run: docker-compose -p "wallabag_${{ matrix.database }}" -f tests/docker-compose.${{ matrix.database }}.yml down -v From c0c280b60675a3e0d620cfb84235cf1827c47b67 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 22 Jul 2023 18:23:26 +0200 Subject: [PATCH 5/8] Update base alpine to 3.18 Signed-off-by: Kevin Decherf --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7300f8f..483d1e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM golang:alpine as builder # flag -ldflags "-s -w" produces a smaller executable RUN go install -ldflags "-s -w" -v github.com/a8m/envsubst/cmd/envsubst@v1.3.0 -FROM alpine:3.17 +FROM alpine:3.18 COPY --from=builder /go/bin/envsubst /usr/bin/envsubst From 98ed4730b3ea71abd4b5bae59d2006ac8ca7bef1 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 22 Jul 2023 18:34:12 +0200 Subject: [PATCH 6/8] drop: run tests on master Signed-off-by: Kevin Decherf --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 483d1e8..9536d47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ FROM alpine:3.18 COPY --from=builder /go/bin/envsubst /usr/bin/envsubst -ARG WALLABAG_VERSION=2.6.1 +ARG WALLABAG_VERSION=master RUN set -ex \ && apk add --no-cache \ From 1ad213de860dd0373abbaa2de4cd6b3d390892cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 24 Jul 2023 13:11:12 +0200 Subject: [PATCH 7/8] Update README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 930d1ce..785038e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ Default login is `wallabag:wallabag`. - `-e SYMFONY__ENV__LOCALE=...` (default to en) - `-e SYMFONY__ENV__MAILER_DSN=...` (defaults to "smtp://127.0.0.1") - `-e SYMFONY__ENV__FROM_EMAIL=...`(defaults to "`wallabag@example.com`", the address wallabag uses for outgoing emails) -- `-e SYMFONY__ENV__TWOFACTOR_AUTH=...` (defaults to "true", enable or disable two-factor authentication) - `-e SYMFONY__ENV__TWOFACTOR_SENDER=...` (defaults to "`no-reply@wallabag.org`", the address wallabag uses for two-factor emails) - `-e SYMFONY__ENV__FOSUSER_REGISTRATION=...`(defaults to "true", enable or disable public user registration) - `-e SYMFONY__ENV__FOSUSER_CONFIRMATION=...`(defaults to "true", enable or disable registration confirmation) From 886535f76715239f42d60983df234d728603f9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 24 Jul 2023 13:15:37 +0200 Subject: [PATCH 8/8] Update Dockerfile for wallabag 2.6.2 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b720c29..966c694 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ FROM alpine:3.18 COPY --from=builder /go/bin/envsubst /usr/bin/envsubst -ARG WALLABAG_VERSION=master +ARG WALLABAG_VERSION=2.6.2 RUN set -ex \ && apk add --no-cache \