- Clone GitLab Repo:
$ git clone https://gitlab.com/sbathgate/flask-tdd-docker.git
- Switch to project root:
$ cd flask-tdd-docker/
- Build the images:
$ docker-compose build
- Run the containers:
$ docker-compose up -d
- Create the database:
$ docker-compose exec users python manage.py recreate_db
- Seed the database:
$ docker-compose exec users python manage.py seed_db
βββ .gitignore
βββ .gitlab-ci.yml
βββ Dockerfile.deploy
βββ README.md
βββ docker-compose.yml
βββ makefile
βββ release.sh
βββ services
βββ client
β βββ .dockerignore
β βββ .eslintrc.json
β βββ .gitignore
β βββ Dockerfile
β βββ Dockerfile.ci
β βββ README.md
β βββ coverage
β βββ package-lock.json
β βββ package.json
β βββ public
β β βββ favicon.ico
β β βββ index.html
β β βββ logo192.png
β β βββ logo512.png
β β βββ manifest.json
β β βββ robots.txt
β βββ src
β βββ App.jsx
β βββ components
β β βββ About.jsx
β β βββ AddUser.jsx
β β βββ LoginForm.jsx
β β βββ Message.jsx
β β βββ NavBar.css
β β βββ NavBar.jsx
β β βββ RegisterForm.jsx
β β βββ UserStatus.jsx
β β βββ UsersList.jsx
β β βββ __tests__
β β β βββ About.test.jsx
β β β βββ AddUser.test.jsx
β β β βββ App.test.jsx
β β β βββ LoginForm.test.jsx
β β β βββ Message.test.jsx
β β β βββ NavBar.test.jsx
β β β βββ RegisterForm.test.jsx
β β β βββ UserStatus.test.jsx
β β β βββ UsersList.test.jsx
β β β βββ __snapshots__
β β β βββ About.test.jsx.snap
β β β βββ AddUser.test.jsx.snap
β β β βββ App.test.jsx.snap
β β β βββ LoginForm.test.jsx.snap
β β β βββ Message.test.jsx.snap
β β β βββ NavBar.test.jsx.snap
β β β βββ RegisterForm.test.jsx.snap
β β β βββ UserStatus.test.jsx.snap
β β β βββ UsersList.test.jsx.snap
β β βββ form.css
β βββ index.js
β βββ setupTests.js
βββ nginx
β βββ default.conf
βββ users
βββ .coverage
βββ .coveragerc
βββ .dockerignore
βββ Dockerfile
βββ Dockerfile.prod
βββ entrypoint.sh
βββ htmlcov
βββ manage.py
βββ project
β βββ __init__.py
β βββ api
β β βββ __init__.py
β β βββ auth.py
β β βββ ping.py
β β βββ users
β β βββ __init__.py
β β βββ admin.py
β β βββ crud.py
β β βββ models.py
β β βββ views.py
β βββ config.py
β βββ db
β β βββ Dockerfile
β β βββ create.sql
β βββ tests
β βββ __init__.py
β βββ conftest.py
β βββ pytest.ini
β βββ test_admin.py
β βββ test_auth.py
β βββ test_config.py
β βββ test_ping.py
β βββ test_user_model.py
β βββ test_users.py
β βββ test_users_unit.py
βββ requirements-dev.txt
βββ requirements.txt
βββ setup.cfg
$ export REACT_APP_USERS_SERVICE_URL=http://localhost:5001
$ docker-compose build
$ docker-compose up -d --build
$ docker-compose stop
$ docker-compose down
$ docker-compose exec client npm test
$ docker-compose exec client npm test --coverage
$ docker-compose exec client npm run prettier:check
$ docker-compose exec client npm run lint
$ docker-compose exec users python manage.py recreate_db
$ docker-compose exec users python manage.py seed_db
$ docker-compose exec users python -m pytest "project/tests" -p no:warnings
$ docker-compose exec users python -m pytest "project/tests" -p no:warnings --cov="project"
$ docker-compose exec users flake8 project
$ docker-compose exec users black project --check
$ docker-compose exec users /bin/sh -c "isort project/**/*.py --check-only"
$ docker-compose exec users black project
$ docker-compose exec users /bin/sh -c "isort project/**/*.py"
$ docker-compose exec users-db psql -U postgres
# \c users_dev
# select * from users;
$ docker-compose build --no-cache
$ docker rmi $(docker images -q)
- Configure singular setup.cfg for flake8, black and isort.
- Database migrations: Manage changes to the database through SQLAlchemy database migrations with the Flask-Migrate extension.
- Write test to ensure UserStatus redirects to login if invalid token.
- EXPLORE: For added protection, instead of storing refresh tokens in LocalStorage, how would you return tokens from the server in HttpOnly cookies? The Flask-JWT-Extended extension may be worth looking at.
- Add test to ensure message disappears when 1: a user click the 'x', 2: a new message is flashed, 3: three seconds pass
- Prevent currently logged in person from deleting themselves.
- Test coverage: Add more tests to increase the overall test coverage, making sure to cover any remaining edge cases.
- Unit tests: Add unit tests (via monkeypatch) to cover the auth routes.
- DRY out the code: There's plenty of places in the code base that could be refactored.
- Flask CORS: Instead of allowing requests from any domain, lock down the Flask service by only allowing requests that originate from the Heroku domain.
- Caching: Add caching (where appropriate) with Flask-Cache.
- Duplicate usernames: Prevent duplicate usernames in the database.
- Invalidate refresh tokens: Users can have a number of active refresh tokens. It may be worth controlling this to prevent abuse by only allowing a user to have a single refresh token at time. Create a database table for this and update the client and server-side logic.
- Blacklist tokens: You may want to create a database table for used access and refresh tokens to prevent abuse. Again, update the client and server-side as necessary.
- Role based authorization: Add role based authorization. Refer to the "Auth" section in Awesome Flask for more info.
- Cross tab logout: Incorporate cross browser tab logout by adding an event listener on the refresh token in LocalStorage.
- Transactional emailing: Add the ability to send transactional emails for email confirmation and password changes.
- Client side: Add the ability to update a user using the same modal configured for adding a user and prevent the currently logged in user from deleting themselves in the table.
- Hooks: Refactor the class-based React components to functions with React Hooks. Refer to Primer on React Hooks for more info on Hooks.
If you get a compilation error due to Module not found: Can't resolve 'temp'; try installing temp in the running container:
$ docker-compose exec client npm install react-router-dom