Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E Integration test environment setup #746

Merged
merged 37 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f11f10f
Add playwright to dev requirements
pavish Oct 21, 2021
226c4a6
Set base docker image to a temp custom prebuilt image with ubuntu+pyt…
pavish Oct 22, 2021
668e67c
Set container names in docker compose
pavish Oct 22, 2021
88488a0
Remove playwright from requirements file
pavish Oct 22, 2021
71817c0
Fix container name in documents and tests
pavish Oct 22, 2021
07cd5b8
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Oct 22, 2021
007f883
Github action to run e2e tests
pavish Oct 22, 2021
608e452
Sleep for 60 seconds to wait for server to be up, handle migrations
pavish Oct 22, 2021
bb6b7f0
Merge branch 'master' into integ_test_playwright_python
pavish Oct 25, 2021
3382926
Skip confirmation during db creation in github actions
pavish Oct 25, 2021
11bf8fa
Log page content to debug failing of test cases in GH workflow
pavish Oct 25, 2021
deb7f46
Record video artifacts to help debug failing tests
pavish Oct 25, 2021
5efcfe0
Merge branch 'master' into integ_test_playwright_python
pavish Oct 26, 2021
edd7854
Print DB name in installation message.
kgodey Oct 26, 2021
94e7827
Remove copy of env file.
kgodey Oct 26, 2021
2cb167b
Change cache key.
kgodey Oct 26, 2021
063cb7a
Revert "Remove copy of env file."
kgodey Oct 26, 2021
12ef48d
Update status: waiting issues automatically
kgodey Oct 30, 2021
e772b0a
Merge branch 'fix_install_script' of https://github.com/centerofci/ma…
pavish Nov 1, 2021
4c67223
Merge branch 'master' into integ_test_playwright_python
kgodey Nov 1, 2021
954901c
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 5, 2021
49eb096
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 8, 2021
a710cfc
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 8, 2021
2a07f16
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 9, 2021
64352b8
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 12, 2021
649e904
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 15, 2021
f26ca02
Reverting dockerfile changes
pavish Nov 16, 2021
6395b19
Run pytest on mathesar and db modules
pavish Nov 16, 2021
ff3e5cf
Dockerfile for integration tests
pavish Nov 16, 2021
62439b2
Use integ test dockerfile for running e2e tests
pavish Nov 16, 2021
b7657c3
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 16, 2021
ba894a2
Specify different path for artifacts for each workflow
pavish Nov 16, 2021
04b970b
Documentation for running E2E tests
pavish Nov 16, 2021
609dd49
chore(docs): update TOC
pavish Nov 16, 2021
1db88d1
Add license of python3.9 dockerfile used as reference
pavish Nov 16, 2021
cfa53d9
Merge branch 'integ_test_playwright_python' of https://github.com/cen…
pavish Nov 16, 2021
e5bfc70
Removing conflicting step to set waiting status on issues
pavish Nov 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/run-e2e-integ-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Run E2E integration tests
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
# We only want to run on external PRs, since internal PRs are covered by "push"
# This prevents this from running twice on internal PRs
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v2

# In this step, this action saves a list of existing images,
# the cache is created without them in the post run.
# It also restores the cache if it exists.
- uses: satackey/action-docker-layer-caching@v0.0.11
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true
with:
key: mathesar-docker-cache-integ-tests-{hash}
restore-keys: |
mathesar-docker-cache-integ-tests-

- name: Copy env file
run: cp .env.example .env

# The code is checked out under uid 1001 - reset this to 1000 for the
# container to run tests successfully
- name: Fix permissions
run: sudo chown -R 1000:1000 .

- name: Build the stack
run: docker-compose up --build -d

- name: Sleep for 60 seconds
run: sleep 60s
shell: bash

# TODO: This needs to be handled inside the tests
- name: Run migrations
run: docker exec mathesar_service python manage.py migrate

- name: Run type installation
run: docker exec mathesar_service python install.py

- name: Run integ tests with pytest
run: docker exec mathesar_service pytest --browser chromium --browser webkit --browser firefox tests/
2 changes: 1 addition & 1 deletion .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: docker-compose up --build -d

- name: Run tests with pytest
run: docker exec mathesar_service_1 pytest
run: docker exec mathesar_service pytest mathesar/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add db/ to this, otherwise we're no longer running tests in the db module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it. Thanks.

19 changes: 1 addition & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
FROM python:3.9-buster

# These should be run as a single command to avoid caching issues.
# See: http://lenguyenthedat.com/docker-cache/
RUN apt update && apt install -y sudo

# Add mathesar user
ENV PYTHONUNBUFFERED=1
ENV DOCKERIZE_VERSION v0.6.1

# Install dockerize
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

# Install node
RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
RUN apt install -y nodejs
FROM pavish73/mathesar-base:latest-all

# Change work directory
WORKDIR /code/
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ docker-compose up

If it's your first time running the application, you'll also need to run database migrations and install Mathesar types and functions:
```
docker exec mathesar_service_1 python manage.py migrate
docker exec -it mathesar_service_1 python install.py
docker exec mathesar_service python manage.py migrate
docker exec -it mathesar_service python install.py
```

You should now have a web server and database server running. Opening `http://localhost:8000` in your browser will open the application. For sample table data, you can create a new table in the UI using the `patents.csv` file found in `/mathesar/tests/data`.
Expand Down Expand Up @@ -85,19 +85,19 @@ If you'd like to run tests before pushing, here's how you do it:

Backend tests:
```
docker exec mathesar_service_1 pytest
docker exec mathesar_service pytest
```

Frontend tests:
```
docker exec mathesar_service_1 bash -c "cd mathesar_ui && npm test"
docker exec mathesar_service bash -c "cd mathesar_ui && npm test"
```

### Opening a shell in the container

If you need to do some work on the container that's running the code, here's how you access it:
```
docker exec -it mathesar_service_1 bash
docker exec -it mathesar_service bash
```

To open a PostgreSQL psql terminal for the data in Mathesar:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: "3.9"
services:
db:
image: postgres:13
container_name: mathesar_db
environment:
- POSTGRES_DB=${POSTGRES_DB-mathesar_django}
- POSTGRES_USER=${POSTGRES_USER-mathesar}
Expand All @@ -13,6 +14,7 @@ services:
- ./.volumes:/var/lib/postgresql/data
service:
build: .
container_name: mathesar_service
environment:
- MODE=${MODE-PRODUCTION}
command: dockerize -wait tcp://db:5432 -timeout 30s ./run.sh
Expand Down
4 changes: 2 additions & 2 deletions mathesar_ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ If you want to add or remove packages, or bascially run any npm action, **always
You can connect to the container and open the ui folder by running:

```bash
docker exec -it mathesar_service_1 /bin/bash
docker exec -it mathesar_service /bin/bash
cd mathesar_ui
```

Expand All @@ -71,7 +71,7 @@ For guidelines on component development, refer [README of components](https://gi
You can start storybook in dev mode by connecting to the container and then running `npm run storybook`:

```bash
docker exec -it mathesar_service_1 /bin/bash
docker exec -it mathesar_service /bin/bash

root@c273da65c52d:/code/mathesar_ui$ cd mathesar_ui && npm run storybook
```
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ env =
DJANGO_DATABASE_URL=postgres://mathesar:mathesar@db:5432/mathesar_django
MATHESAR_DATABASES=(mathesar_db_test|postgres://mathesar:mathesar@db:5432/mathesar_db_test)
TEST=True
MODE=DEVELOPMENT
3 changes: 3 additions & 0 deletions tests/test_base_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_base_page(page):
page.goto('http://localhost:8000')
assert page.inner_text('h1') == 'Welcome to Mathesar!'