-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master2release' into release
- Loading branch information
Showing
73 changed files
with
4,369 additions
and
895 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ on: | |
|
||
jobs: | ||
stale: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/stale@v4 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,41 +37,41 @@ desire with a good editor: | |
|
||
To build development images and run the containers: | ||
|
||
docker-compose up -d --build | ||
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:8111`. | ||
variable and start a django built-in server at `http://localhost:8011`. | ||
|
||
Run the django database migrations. | ||
|
||
docker-compose exec app python manage.py migrate | ||
docker compose exec app python manage.py migrate | ||
|
||
And collect the static files (CSS, JS etc): | ||
|
||
docker-compose run app python manage.py collectstatic --noinput | ||
docker compose run app python manage.py collectstatic --noinput | ||
|
||
You can check if everything seems to work correctly using the | ||
`status` command: | ||
|
||
docker-compose exec app python manage.py status | ||
docker compose exec app python manage.py status | ||
|
||
Now you can get started by adding the first user that would also be a super user: | ||
|
||
docker-compose run app python manage.py createsuperuser --username super_user --email [email protected] | ||
docker compose run app python manage.py createsuperuser --username super_user --email [email protected] | ||
|
||
### Tests | ||
|
||
To run all the unit and functional tests (on a throwaway test | ||
database and a throwaway test storage directory): | ||
|
||
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 | ||
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`) | ||
|
||
docker-compose run app python manage.py test qfieldcloud.core.tests.test_permission | ||
docker compose run app python manage.py test qfieldcloud.core.tests.test_permission | ||
|
||
### Debugging | ||
|
||
|
@@ -88,10 +88,9 @@ debugpy.wait_for_client() # optional | |
``` | ||
|
||
Or alternativley, prefix your commands with `python -m debugpy --listen 0.0.0.0:5680 --wait-for-client`. | ||
```shell | ||
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 | ||
``` | ||
|
||
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`): | ||
``` | ||
|
@@ -203,11 +202,11 @@ Create the directory for qfieldcloud logs and supervisor socket file | |
|
||
Run and build the docker containers | ||
|
||
docker-compose up -d --build | ||
docker compose up -d --build | ||
|
||
Run the django database migrations | ||
|
||
docker-compose exec app python manage.py migrate | ||
docker compose exec app python manage.py migrate | ||
|
||
|
||
## Create a certificate using Let's Encrypt | ||
|
@@ -243,15 +242,14 @@ Based on this example | |
|
||
Docker logs are managed by docker in the default way. To read the logs: | ||
|
||
docker-compose logs | ||
docker compose logs | ||
|
||
|
||
For great `nginx` logs, use: | ||
|
||
QFC_JQ='[.ts, .ip, (.method + " " + (.status|tostring) + " " + (.resp_time|tostring) + "s"), .uri, "I " + (.request_length|tostring) + " O " + (.resp_body_size|tostring), "C " + (.upstream_connect_time|tostring) + "s", "H " + (.upstream_header_time|tostring) + "s", "R " + (.upstream_response_time|tostring) + "s", .user_agent] | @tsv' | ||
docker compose logs nginx -f --no-log-prefix | grep ':"nginx"' | jq -r $QFC_JQ | ||
|
||
|
||
### Geodb | ||
|
||
The geodb (database for the users projects data) is installed on | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,110 @@ | ||
########### | ||
# BUILDER # | ||
########### | ||
########################## | ||
# BUILDER # | ||
########################## | ||
|
||
# pull a builder image, the same as the base | ||
FROM python:3.10.8-slim-buster as build | ||
|
||
# Disable annoying pip version check, we don't care if pip is slightly older | ||
ARG PIP_DISABLE_PIP_VERSION_CHECK 1 | ||
|
||
# Do not create and use redundant cache dir in the current user home | ||
ARG PIP_NO_CACHE_DIR 1 | ||
|
||
# install psycopg2 requirements | ||
RUN apt update && apt install -y libpq-dev python3-dev gcc | ||
|
||
# install dependencies | ||
COPY ./requirements.txt . | ||
RUN pip3 install -r requirements.txt | ||
|
||
# save 60 MB of data... Safe to delete according to botocore contributor https://github.com/boto/botocore/issues/1629#issuecomment-451309885 | ||
RUN ls -Q /usr/local/lib/python3.10/site-packages/botocore/data | grep -xv "endpoints.json" | xargs rm -rf | ||
|
||
########################## | ||
# BASE # | ||
########################## | ||
|
||
# pull official base image | ||
FROM python:3.8.0-buster as builder | ||
FROM python:3.10.8-slim-buster as base | ||
|
||
# set work directory | ||
WORKDIR /usr/src/app | ||
|
||
# set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
# check `build` stage for more info | ||
# NOTE while using ARG would be more appropriate, the following vars would have to be redifined for each build stage. | ||
ENV PIP_DISABLE_PIP_VERSION_CHECK 1 | ||
ENV PIP_NO_CACHE_DIR 1 | ||
|
||
# install dependencies | ||
RUN apt update \ | ||
&& apt install -y netcat python3-gdal | ||
RUN apt update && apt-get install -y \ | ||
# GeoDjango as recommended at https://docs.djangoproject.com/en/4.1/ref/contrib/gis/install/geolibs/#installing-geospatial-libraries | ||
binutils libproj-dev gdal-bin | ||
|
||
# install dependencies | ||
COPY ./requirements.txt . | ||
RUN pip install -r requirements.txt | ||
# copy the dependencies | ||
COPY --from=build /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/ | ||
|
||
# install debug dependencies | ||
ARG DEBUG_BUILD | ||
RUN if [ "$DEBUG_BUILD" = "1" ]; then pip install debugpy; fi | ||
RUN if [ "$DEBUG_BUILD" = "1" ]; then pip3 install debugpy; fi | ||
|
||
# copy project | ||
COPY . . | ||
# add app group | ||
RUN addgroup --system app && adduser --system app --ingroup app | ||
|
||
# create the appropriate directories | ||
RUN mkdir staticfiles | ||
RUN mkdir mediafiles | ||
|
||
# chown all the files to the app user | ||
RUN addgroup --system app && adduser --system app --ingroup app | ||
RUN chown -R app:app . | ||
# create an empty JSON fixture for the sole purpose of Django's testserver | ||
RUN echo '{}' > fixture.json | ||
|
||
# Do not uncomment unless you want to share the user id between the host and the container | ||
# RUN groupmod -g 1000 app | ||
# RUN usermod -u 1000 app | ||
|
||
# change to the app user | ||
COPY ./entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
########################## | ||
# WEBSERVER RUNTIME # | ||
########################## | ||
|
||
# a separate stage for webserver runtime environment | ||
FROM base as webserver_runtime | ||
COPY ./requirements_runtime.txt . | ||
RUN pip3 install -r requirements_runtime.txt | ||
EXPOSE 8000 | ||
|
||
COPY . . | ||
RUN chown -R app:app . | ||
USER app | ||
|
||
########################## | ||
# WEBSERVER TEST # | ||
########################## | ||
|
||
# a separate stage for webserver test environment | ||
FROM base as webserver_test | ||
COPY ./requirements_test.txt . | ||
RUN pip3 install -r requirements_test.txt | ||
EXPOSE 8000 | ||
|
||
# create an empty JSON fixture for the sole purpose of Django's testserver | ||
RUN echo '{}' > fixture.json | ||
COPY . . | ||
RUN chown -R app:app . | ||
USER app | ||
|
||
# run entrypoint.prod.sh | ||
COPY ./entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
########################## | ||
# WORKER WRAPPER RUNTIME # | ||
########################## | ||
|
||
# a separate stage for worker wrapper runtime environment | ||
FROM base as worker_wrapper_runtime | ||
COPY ./requirements_worker_wrapper.txt . | ||
RUN pip3 install -r requirements_worker_wrapper.txt | ||
|
||
COPY . . | ||
RUN chown -R app:app . | ||
USER app |
Oops, something went wrong.