Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Aug 12, 2022
2 parents e08e0bb + 5a05309 commit 6dcd380
Show file tree
Hide file tree
Showing 86 changed files with 5,837 additions and 1,181 deletions.
15 changes: 9 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ENVIRONMENT=test

QFIELDCLOUD_HOST=localhost
DJANGO_SETTINGS_MODULE=qfieldcloud.settings
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 0.0.0.0
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 0.0.0.0 app

SECRET_KEY=change_me

Expand Down Expand Up @@ -78,25 +78,28 @@ QFIELDCLOUD_RIBBON_HTML=<a class="qfc-ribbon" href="https://qfield.cloud/tos" ta
# Timeout in seconds to wait for a job container to finish, otherwise terminate it.
QFIELDCLOUD_WORKER_TIMEOUT_S=60

# QFieldCloud URL used within the worker as configuration for qfieldcloud-sdk
QFIELDCLOUD_WORKER_QFIELDCLOUD_URL=http://app:8000/api/v1/

# The Django development port. Not used in production.
# DEFAULT: 8111
DJANGO_DEV_PORT=8111
# DEFAULT: 8011
DJANGO_DEV_PORT=8011

GUNICORN_TIMEOUT_S=300
GUNICORN_MAX_REQUESTS=300
GUNICORN_WORKERS=3
GUNICORN_THREADS=3

# Not used in production.
# DEFAULT: 8112
SMTP4DEV_WEB_PORT=8112
# DEFAULT: 8012
SMTP4DEV_WEB_PORT=8012

# Not used in production.
# DEFAULT: 25
SMTP4DEV_SMTP_PORT=25

# Not used in production.
# DEFAULT: 43
# DEFAULT: 143
SMTP4DEV_IMAP_PORT=143

COMPOSE_PROJECT_NAME=qfieldcloud
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ jobs:
- name: Export the env variables file
run: |
cp .env.example .env
sed -ri 's/^COMPOSE_FILE=(.*)/COMPOSE_FILE=\1:docker-compose.override.test.yml/g' .env
eval $(egrep "^[^#;]" .env | xargs -d'\n' -n1 | sed -E 's/(\w+)=(.*)/export \1='"'"'\2'"'"'/g')
- name: Pull docker containers
run: docker-compose pull
- name: Build and run docker containers
run: |
docker-compose up -d --build
- name: Migrate
run: |
docker-compose run app python manage.py migrate
- name: Run unit and integration tests
run: |
docker-compose run app python manage.py test -v2 qfieldcloud
docker-compose run app python manage.py test --keepdb -v2 qfieldcloud
- name: "failure logs"
if: failure()
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ To build development images and run the containers:
docker-compose up -d --build

It will read the `docker-compose*.yml` files specified in the `COMPOSE_FILE`
variable and start a django built-in server at `http://localhost:8000`.
variable and start a django built-in server at `http://localhost:8111`.

Run the django database migrations.

Expand All @@ -64,7 +64,10 @@ Now you can get started by adding the first user that would also be a super user
To run all the unit and functional tests (on a throwaway test
database and a throwaway test storage directory):

docker-compose run app python manage.py test
export COMPOSE_FILE=docker-compose.yml:docker-compose.override.local.yml:docker-compose.override.test.yml
docker-compose up -d
docker-compose run app python manage.py migrate
docker-compose run app python manage.py test --keepdb

To run only a test module (e.g. `test_permission.py`)

Expand All @@ -79,15 +82,15 @@ If using the provided docker-compose overrides for developement, `debugpy` is in
You can debug interactively by adding this snipped anywhere in the code.
```python
import debugpy
debugpy.listen(("0.0.0.0", 5678))
debugpy.listen(("0.0.0.0", 5680))
print("debugpy waiting for debugger... 🐛")
debugpy.wait_for_client() # optional
```

Or alternativley, prefix your commands with `python -m debugpy --listen 0.0.0.0:5678 --wait-for-client`.
Or alternativley, prefix your commands with `python -m debugpy --listen 0.0.0.0:5680 --wait-for-client`.
```shell
docker-compose run app -p 5678:5678 python -m debugpy --listen 0.0.0.0:5678 --wait-for-client manage.py test
docker-compose run worker_wrapper -p 5679:5679 python -m debugpy --listen 0.0.0.0:5679 --wait-for-client manage.py test
docker-compose run app -p 5680:5680 python -m debugpy --listen 0.0.0.0:5680 --wait-for-client manage.py test
docker-compose run worker_wrapper -p 5681:5681 python -m debugpy --listen 0.0.0.0:5681 --wait-for-client manage.py test
```

Then, configure your IDE to connect (example given for VSCode's `.vscode/launch.json`, triggered with `F5`):
Expand All @@ -100,7 +103,7 @@ Then, configure your IDE to connect (example given for VSCode's `.vscode/launch.
"type": "python",
"request": "attach",
"justMyCode": false,
"connect": {"host": "localhost", "port": 5678},
"connect": {"host": "localhost", "port": 5680},
"pathMappings": [{
"localRoot": "${workspaceFolder}/docker-app/qfieldcloud",
"remoteRoot": "/usr/src/app/qfieldcloud"
Expand All @@ -111,7 +114,7 @@ Then, configure your IDE to connect (example given for VSCode's `.vscode/launch.
"type": "python",
"request": "attach",
"justMyCode": false,
"connect": {"host": "localhost", "port": 5679},
"connect": {"host": "localhost", "port": 5681},
"pathMappings": [{
"localRoot": "${workspaceFolder}/docker-app/qfieldcloud",
"remoteRoot": "/usr/src/app/qfieldcloud"
Expand All @@ -121,6 +124,8 @@ Then, configure your IDE to connect (example given for VSCode's `.vscode/launch.
}
```

Note if you run tests using the `docker-compose.test.yml` configuration, the `app` and `worker-wrapper` containers expose ports `5680` and `5681` respectively.


## Add root certificate

Expand Down
3 changes: 3 additions & 0 deletions docker-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ USER app

EXPOSE 8000

# create an empty JSON fixture for the sole purpose of Django's testserver
RUN echo '{}' > fixture.json

# run entrypoint.prod.sh
COPY ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker-app/qfieldcloud/authentication/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_token(

class TokenAuthentication(DjangoRestFrameworkTokenAuthentication):
"""
Multi toke authentication based on simple token based authentication.
Multi token authentication based on simple token based authentication.
Clients should authenticate by passing the token key in the "Authorization"
HTTP header, prepended with the string "Token ". For example:
Authorization: Token 401f7ac837da42b97f613d789819ff93537bee6a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2.12 on 2022-03-09 15:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("authentication", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="authtoken",
name="client_type",
field=models.CharField(
choices=[
("browser", "Browser"),
("cli", "Command line interface"),
("sdk", "SDK"),
("qfield", "QField"),
("qfieldsync", "QFieldSync"),
("worker", "Worker"),
("unknown", "Unknown"),
],
default="unknown",
max_length=32,
),
),
]
1 change: 1 addition & 0 deletions docker-app/qfieldcloud/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ClientType(models.TextChoices):
SDK = "sdk", _("SDK")
QFIELD = "qfield", _("QField")
QFIELDSYNC = "qfieldsync", _("QFieldSync")
WORKER = "worker", _("Worker")
UNKNOWN = "unknown", _("Unknown")

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from django.utils.timezone import datetime, now
from qfieldcloud.authentication.models import AuthToken
from qfieldcloud.core.models import User
from qfieldcloud.core.tests.utils import setup_subscription_plans
from rest_framework.test import APITransactionTestCase

logging.disable(logging.CRITICAL)


class QfcTestCase(APITransactionTestCase):
def setUp(self):
setup_subscription_plans()

# Create a user
self.user1 = User.objects.create_user(username="user1", password="abc123")

Expand Down
Loading

0 comments on commit 6dcd380

Please sign in to comment.