diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..e8dab1b --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,22 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es6": true, + "jquery": true + }, + "extends": [ + "eslint:recommended", + "jquery" + ], + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parserOptions": { + "ecmaVersion": 2018 + }, + "rules": { + "camelcase": "off" + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index df2b934..b81d19d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *~ +node_modules/ *.pyc db.sqlite3 +install.log reports +src diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a92dbea..39c3e77 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,12 +2,25 @@ default_language_version: # force all unspecified python hooks to run python3 python: python3 repos: +- repo: https://github.com/asottile/reorder_python_imports + rev: v1.9.0 + hooks: + - id: reorder-python-imports + exclude: migrations/ + args: ["--py37-plus"] - repo: https://github.com/psf/black rev: stable - args: -t py37 hooks: - id: black - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.3.0 hooks: - id: flake8 + - id: requirements-txt-fixer +- repo: https://github.com/pre-commit/mirrors-eslint + rev: v6.8.0 + hooks: + - id: eslint + args: ['--fix'] + additional_dependencies: + - eslint-config-jquery diff --git a/.tmux.conf b/.tmux.conf new file mode 100644 index 0000000..61b9f4e --- /dev/null +++ b/.tmux.conf @@ -0,0 +1,91 @@ +#set-option -g default-shell /bin/zsh + +# Use Ctrl-a, like Screen +set -g prefix C-a +unbind C-b + + +# Start counting from 1 for windows and panes +set -g base-index 1 +set -g pane-base-index 1 + +bind C-a send-prefix + +bind | split-window -h +bind - split-window -v + +bind e detach +bind x kill-pane +bind & kill-window + +set-option -g allow-rename off + +#vim moves +bind h select-pane -L +bind j select-pane -D +bind k select-pane -U +bind l select-pane -R + +bind r source-file ~/.tmux.conf \; display "Configuration reloaded!" + +#Toogle +bind -r C-h select-window -t :- +bind -r C-l select-window -t :+ + +#set -g mouse-select-pane on +#set -g mouse-resize-pane on +#set -g mouse-select-pane on +#set -g mode-mouse on + +set -g monitor-activity off +set -g visual-activity off + +bind-key * list-clients + +setw -g automatic-rename +set-option -g set-titles on + +set -g history-limit 10000 + +set -g status-keys vi +set -g mode-keys vi + +set -sg escape-time 0 + +unbind q +bind q confirm kill-session +bind Q confirm kill-server + +unbind d +bind -r d resize-pane -D 5 +bind -r u resize-pane -U 5 + +#set -g status-utf8 on +set -g status-right "#S:#I.#P" +set -g status-justify left +set-option -g status-position top + +if-shell "if [[ `tmux -V | cut -d' ' -f2` -lt 2.0 ]]; then true; else false; fi" \ + 'set -g status-utf8 on; \ + set -g mouse-select-pane on; \ + set -g mouse-resize-pane on; \ + set -g mouse-select-pane on; \ + set -g mode-mouse on;' + +# +## THEME +## +# +## Colors make life better +set -g default-terminal "screen-256color" +# +set -g status-fg colour253 # lightgrey +set -g status-bg colour234 # darkgrey + +## Status bar info +#set -g status-utf8 on +set -g status-left "#[fg=red]($SERVER)⚡ [#I]" +set -g status-right "[#I] #[fg=yellow]#S:#I:#P #[fg=green]%H:%M %d-%h" +set -g status-justify left +set-option -g status-position top + diff --git a/Makefile b/Makefile index ff5801e..f2aa646 100644 --- a/Makefile +++ b/Makefile @@ -42,28 +42,34 @@ shell: venv_prod ################################### -run_dev: +run_dev: venv_dev IP=$(shell ip a show dev eth0 scope global | grep inet | awk '{print $$2}' | cut -d/ -f1); \ + source $(VAR_DIR)/venv_dev/bin/activate && \ ./manage.py runserver_plus $$IP:8000 --settings="repoapi.settings.dev" -worker_dev: +worker_dev: venv_dev + source $(VAR_DIR)/venv_dev/bin/activate && \ DJANGO_SETTINGS_MODULE=repoapi.settings.dev \ $(VAR_DIR)/venv_dev/bin/celery -A repoapi worker \ --loglevel=info -monitor_dev: +monitor_dev: venv_dev IP=$(shell ip a show dev eth0 scope global | grep inet | awk '{print $$2}' | cut -d/ -f1); \ + source $(VAR_DIR)/venv_dev/bin/activate && \ DJANGO_SETTINGS_MODULE=repoapi.settings.dev \ $(VAR_DIR)/venv_dev/bin/celery -A repoapi flower \ --address=$$IP --port=5555 --settings="repoapi.settings.dev" -makemigrations_dev: +makemigrations_dev: venv_dev + source $(VAR_DIR)/venv_dev/bin/activate && \ ./manage.py makemigrations --settings="repoapi.settings.dev" -migrate_dev: +migrate_dev: venv_dev + source $(VAR_DIR)/venv_dev/bin/activate && \ ./manage.py migrate --settings="repoapi.settings.dev" -shell_dev: +shell_dev: venv_dev + source $(VAR_DIR)/venv_dev/bin/activate && \ ./manage.py shell --settings="repoapi.settings.dev" ################################### diff --git a/README.md b/README.md index 0caf9e4..1776103 100644 --- a/README.md +++ b/README.md @@ -19,47 +19,80 @@ On your desktop, install pre-commit tool [pre-commit](https://pre-commit.com/) ------------------------------------- - * apt install build-essential python3-dev python3-virtualenvwrapper virtualenvwrapper + * sudo apt install build-essential python3-dev python3-virtualenvwrapper virtualenvwrapper npm + * sudo npm install -g eslint + * npm install eslint-config-jquery * mkvirtualenv repos-scritps --python=python3 * pip3 install pre-commit * pre-commit install -Inside the repoapi-stretch container run: +virtualenv +---------- +Inside the repoapi-buster container run: - $ export VAR_DIR=/tmp/repoapi - $ make venv_dev - $ source ${VAR_DIR}/venv_dev/bin/activate +``` + $ make venv_dev + $ source /var/lib/repoapi/venv_dev/bin/activate + (venv_dev)$ +``` Create DB -========= +--------- To ensure `db.sqlite3` exists as needed: - (repoapi)$ ./manage.py migrate --settings="repoapi.settings.dev" + ``` + (venv_dev)$ ./manage.py migrate --settings="repoapi.settings.dev" + ``` + or + ``` + $ make migrate_dev + ``` Create superuser -================ +---------------- - (repoapi)$ ./manage.py createsuperuser --settings="repoapi.settings.dev" + ``` + (venv_dev)$ ./manage.py createsuperuser --settings="repoapi.settings.dev" + ``` -Run test server -================ +Tmux +---- -If you want to run it on a specific IP, use: +Use tmux inside repoapi-buster container so you can execute both dev server and worker + + +Run dev server +-------------- - (repoapi)$ IP=172.17.0.3 # adjust as needed - (repoapi)$ ./manage.py runserver_plus $IP:8000 --settings="repoapi.settings.dev" +If you want to run it on a specific IP, use: + ``` + (venv_dev)$ IP=172.17.0.3 # adjust as needed + (venv_dev)$ ./manage.py runserver_plus $IP:8000 --settings="repoapi.settings.dev" + ``` or just: + ``` + $ make run_dev + ``` + +Run dev worker +-------------- - (repoapi)$ make run_dev +``` + $ make worker_dev +``` Tests -===== +----- - (repoapi)$ ./manage.py test +``` + (venv_dev)$ ./manage.py test +``` Reports -======= +------- - (repoapi)$ ./manage.py jenkins +``` + (venv_dev)$ ./manage.py jenkins +``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f4c5929 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[tool.black] +line-length = 79 +py37 = true +exclude = ''' +/( + migrations + | __pycache__ +)/ +''' diff --git a/requirements/common.txt b/requirements/common.txt index df7af61..387deac 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -1,17 +1,18 @@ +celery Django==1.11.28 -django-extensions -yuicompressor django-assets +django-celery-beat +django-celery-results +django-extensions +django-filter +django-jsonify +django-rest-swagger djangorestframework>=3.6,<3.7 drfapikey -django-rest-swagger +flower markdown -django-filter +python-debian +PyYAML six>=1.9 webassets -celery -django-celery-beat -django-celery-results -flower -django-jsonify -python-debian +yuicompressor diff --git a/t/Dockerfile b/t/Dockerfile index ffc8888..89952a1 100644 --- a/t/Dockerfile +++ b/t/Dockerfile @@ -5,18 +5,18 @@ FROM docker.mgm.sipwise.com/sipwise-buster:latest # is updated with the current date. It will force refresh of all # of the base images and things like `apt-get update` won't be using # old cached versions when the Dockerfile is built. -ENV REFRESHED_AT 2020-02-20 +ENV REFRESHED_AT 2020-02-21 RUN apt-get update RUN apt-get install --assume-yes python3 python3-dev \ - python3-pip python3-virtualenv virtualenv sqlite3 git screen + python3-pip python3-virtualenv virtualenv sqlite3 git tmux # Get pip to download and install requirements: ADD requirements/*.txt /tmp/ RUN pip3 install -r /tmp/test.txt RUN echo './t/testrunner' >>/root/.bash_history - +ADD .tmux.conf /root/.tmux.conf RUN apt-get clean WORKDIR /code/