README: Add docker-compose usage and fix some markdown issues

This commit is contained in:
Markus Hofbauer
2021-05-02 12:38:30 +02:00
parent 66c4f0dbb3
commit 8d76d1b8df

View File

@@ -14,10 +14,12 @@ This is a little website I've put together to allow me to easily make flash card
- bitwise operations - bitwise operations
Will be able to use it on: Will be able to use it on:
- desktop
- mobile (phone and tablet) - desktop
- mobile (phone and tablet)
It uses: It uses:
- Python 3 - Python 3
- Flask - Flask
- SQLite - SQLite
@@ -77,7 +79,7 @@ Thanks [@eyedol](https://github.com/eyedol)
- This is my systemd file `/etc/systemd/system/flash_cards.service`: [view](flash_cards.service) - This is my systemd file `/etc/systemd/system/flash_cards.service`: [view](flash_cards.service)
- you can see the paths where I installed it, and the name of my virtualenv directory - you can see the paths where I installed it, and the name of my virtualenv directory
- when done with tutorial: - when done with tutorial:
``` ```shell
sudo systemctl restart flash_cards sudo systemctl restart flash_cards
sudo systemctl daemon-reload sudo systemctl daemon-reload
``` ```
@@ -92,42 +94,52 @@ Thanks [@eyedol](https://github.com/eyedol)
*Provided by [@devyash](https://github.com/devyash) - devyashsanghai@gmail.com - Reach out to this contributor if you have trouble.* *Provided by [@devyash](https://github.com/devyash) - devyashsanghai@gmail.com - Reach out to this contributor if you have trouble.*
1. Install dependencies: 1. Install dependencies:
1. Install [Python ](https://www.python.org/download/releases/2.7/) 1. Install [Python](https://www.python.org/download/releases)
2. Add python as environment variable [windows](http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7) 1. Add python as environment variable [windows](http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7)
3. To install pip, securely download [get-pip.py](https://bootstrap.pypa.io/get-pip.py) 1. To install pip, securely download [get-pip.py](https://bootstrap.pypa.io/get-pip.py)
4. Run ```python get-pip.py```in terminal 1. Run `python get-pip.py` in terminal
5. Add pip to your PATH system variable [windows](https://stackoverflow.com/questions/23708898/pip-is-not-recognized-as-an-internal-or-external-command) 1. Add pip to your PATH system variable [windows](https://stackoverflow.com/questions/23708898/pip-is-not-recognized-as-an-internal-or-external-command)
6. Run ``` pip install -r requirements.txt``` in terminal after going to correct folder 1. Run `pip install -r requirements.txt` in terminal after going to correct folder
2. Open flash_cards.py and uncomment the line 52-55 beginning from ``` @app.route('/initdb')``` 1. Open flash_cards.py and uncomment the line 52-55 beginning from `@app.route('/initdb')`
3. Type ```python flash_cards.py``` - if you get error for flask then use ```python -m pip install Flask``` first then run ```flash_card.py``` file 1. Type `python flash_cards.py` - if you get error for flask then use `python -m pip install Flask` first then run `flash_card.py` file
4. Open localhost:5000/initdb 1. Open localhost:5000/initdb
5. Login using id:USERNAME='admin', PASSWORD='default. 1. Login using id:USERNAME='admin', PASSWORD='default'.
6. Comment the line 52-55 in flash_cards.py 1. Comment the line 52-55 in flash_cards.py
NOTE: If you wish to use John's flash cards then also do following steps: **NOTE:** If you wish to use John's flash cards then also do following steps:
1. Copy db files such as ```cards-jwasham-extreme``` OR ```cards-jwasham``` and paste them in db folder
2. Edit file ```flash_cards.py``` line 11 and replace cards with any of the other database files 1. Copy db files such as `cards-jwasham-extreme` OR `cards-jwasham` and paste them in db folder
3. Repeat the above steps from step 3 1. Edit file `flash_cards.py` line 11 and replace cards with any of the other database files
Every time you wish to run your db just open folder in terminal and run ```python flash_cards.py``` 1. Repeat the above steps from step 3
Every time you wish to run your db just open folder in terminal and run `python flash_cards.py`
## How to run with Docker ## How to run with Docker
*Provided by [@Tinpee](https://github.com/tinpee) - tinpee.dev@gmail.com - Reach out to this contributor if you have trouble.* *Provided by [@Tinpee](https://github.com/tinpee) - tinpee.dev@gmail.com - Reach out to this contributor if you have trouble.*
__Make sure you already installed [docker](https://www.docker.com)__ __Make sure you already installed [docker](https://www.docker.com) and optionally [docker-compose](https://docs.docker.com/compose/install/)__
1. Clone project to any where you want and go to source folder. 1. Clone project to any where you want and go to source folder.
1. Edit the config.txt file. Change the secret key, username and password. The username and password will be the login 1. Edit the `config.txt` file. Change the secret key, username and password. The username and password will be the login for your site. There is only one user - you.
for your site. There is only one user - you. 1. Build image:
1. Build image: `docker build . -t cs-flash-cards` - Docker: `docker build . -t cs-flash-cards`
1. Run container: `docker run -d -p 8000:8000 --name cs-flash-cards cs-flash-cards` - Compose: `docker-compose build`
1. Run container:
- Docker: `docker run -d -p 8000:8000 --name cs-flash-cards cs-flash-cards`
- Compose: `docker-compose up`
1. Go your browser and type `http://localhost:8000` 1. Go your browser and type `http://localhost:8000`
__If you already had a backup file `cards.db`. Run following command:__ __If you already had a backup file `cards.db`. Run following command:__
*Note: We don't need to rebuild image, just delete old container if you already built.* *Note: We don't need to rebuild image, just delete old container if you already built.*
`docker run -d -p 8000:8000 --name cs-flash-cards -v <path_to_folder_contains_cards_db>:/src/db cs-flash-cards`.
`<path_to_folder_contains_cards_db>`: is the full path contains `cards.db`. ```shell
Example: `/home/tinpee/cs-flash-cards/db`, and `cards.db` is inside this folder. docker run -d -p 8000:8000 --name cs-flash-cards -v <path_to_folder_contains_cards_db>:/src/db cs-flash-cards
```
- `<path_to_folder_contains_cards_db>`: is the full path contains `cards.db`.
- Example: `/home/tinpee/cs-flash-cards/db`, and `cards.db` is inside this folder.
For convenience, if you don't have `cards.db`, this container will auto copy a new one from `cards-empty.db`. For convenience, if you don't have `cards.db`, this container will auto copy a new one from `cards-empty.db`.
@@ -148,7 +160,8 @@ We just need store `cards.db` file, and don't need any sql command.
- first install [heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) - first install [heroku CLI](https://devcenter.heroku.com/articles/heroku-cli)
- change `entrypoint.sh` - change `entrypoint.sh`
```
```shell
- export CARDS_SETTINGS=/src/config.txt - export CARDS_SETTINGS=/src/config.txt
gunicorn --bind 0.0.0.0:$8000 flash_cards:app gunicorn --bind 0.0.0.0:$8000 flash_cards:app
+ export CARDS_SETTINGS=/src/config.txt + export CARDS_SETTINGS=/src/config.txt
@@ -173,4 +186,3 @@ heroku open --app your-app-name
Check out the demo! Check out the demo!
*Happy learning!* *Happy learning!*