From 5a27d748d16e2f92abdfa898093f2e282eb7215c Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Mon, 22 Nov 2021 00:26:25 -0700 Subject: [PATCH] Create separate test workflow for docker This expands on the current testing suite a bit by introducing a new workflow for testing functionality within the docker container. It runs the same test suite as the regular "test" workflow, but also performs a health check after running the app for 10 seconds to ensure functionality. The buildx workflow now waits for the docker test script to finish successfully, rather than the regular test workflow. This will hopefully avoid situations where new images are pushed with issues that aren't detected in regular testing of the app. --- .github/workflows/buildx.yml | 2 +- .github/workflows/docker_tests.yml | 19 +++++++++++++++++++ app/routes.py | 17 ++++++++--------- 3 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/docker_tests.yml diff --git a/.github/workflows/buildx.yml b/.github/workflows/buildx.yml index 35861ee..8d201ce 100644 --- a/.github/workflows/buildx.yml +++ b/.github/workflows/buildx.yml @@ -2,7 +2,7 @@ name: buildx on: workflow_run: - workflows: ["tests"] + workflows: ["docker_tests"] branches: [main] types: - completed diff --git a/.github/workflows/docker_tests.yml b/.github/workflows/docker_tests.yml new file mode 100644 index 0000000..3624bbb --- /dev/null +++ b/.github/workflows/docker_tests.yml @@ -0,0 +1,19 @@ +name: docker_tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: build and test + run: | + docker build --tag whoogle-search:test . + TEST_CONTAINER=$(docker run --entrypoint=/bin/bash --detach whoogle-search:test) + docker cp test "$TEST_CONTAINER":/whoogle/test + docker exec "$TEST_CONTAINER" ./run test + docker exec --detach "$TEST_CONTAINER" ./run + sleep 10 + docker exec "$TEST_CONTAINER" curl -f http://localhost:5000/healthz || exit 1 diff --git a/app/routes.py b/app/routes.py index 406d33e..1790c0d 100644 --- a/app/routes.py +++ b/app/routes.py @@ -28,7 +28,6 @@ from requests.models import PreparedRequest # Load DDG bang json files only on init bang_json = json.load(open(app.config['BANG_FILE'])) - # Check the newest version of WHOOGLE update = bsoup(get(app.config['RELEASES_URL']).text, 'html.parser') newest_version = update.select_one('[class="Link--primary"]').string[1:] @@ -36,7 +35,7 @@ current_version = int(''.join(filter(str.isdigit, app.config['VERSION_NUMBER']))) newest_version = int(''.join(filter(str.isdigit, newest_version))) newest_version = '' if current_version >= newest_version \ - else newest_version + else newest_version def auth_required(f): @@ -113,10 +112,10 @@ def before_request_func(): session['uuid'] = str(uuid.uuid4()) session['key'] = generate_user_key() - # Skip checking for session on /autocomplete searches, - # since they can be done from the browser search bar (aka - # no ability to initialize a session) - if not Endpoint.autocomplete.in_path(request.path): + # Skip checking for session on any searches that don't + # require a valid session + if (not Endpoint.autocomplete.in_path(request.path) and + not Endpoint.healthz.in_path(request.path)): return redirect(url_for( 'session_check', session_id=session['uuid'], @@ -199,9 +198,9 @@ def index(): 'logo.html', dark=g.user_config.dark), config_disabled=( - app.config['CONFIG_DISABLE'] or - not valid_user_session(session) or - 'cookies_disabled' in request.args), + app.config['CONFIG_DISABLE'] or + not valid_user_session(session) or + 'cookies_disabled' in request.args), config=g.user_config, tor_available=int(os.environ.get('TOR_AVAILABLE')), version_number=app.config['VERSION_NUMBER'])