From 8d76d1b8df43a4d0170a7ed26a7a46530c5a36d0 Mon Sep 17 00:00:00 2001 From: Markus Hofbauer Date: Sun, 2 May 2021 12:38:30 +0200 Subject: [PATCH] README: Add docker-compose usage and fix some markdown issues --- README.md | 92 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 3dfc6ab..a507f78 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,23 @@ This is a little website I've put together to allow me to easily make flash cards and quiz myself for memorization of: - General cs knowledge - - vocabulary - - definitions of processes - - powers of 2 - - design patterns + - vocabulary + - definitions of processes + - powers of 2 + - design patterns - Code - - data structures - - algorithms - - solving problems - - bitwise operations + - data structures + - algorithms + - solving problems + - bitwise operations Will be able to use it on: - - desktop - - mobile (phone and tablet) + +- desktop +- mobile (phone and tablet) It uses: + - Python 3 - Flask - SQLite @@ -56,7 +58,7 @@ My set includes a lot of obscure info from books I’ve read, Python trivia, mac I've added it to the project if you want it (**cards-jwasham-extreme.db**). You've been warned. -Please make your own set, and while you’re making them, only make cards for what you need to know. Otherwise, it gets out of hand. +Please make your own set, and while you’re making them, only make cards for what you need to know. Otherwise, it gets out of hand. ## How to convert to Anki or CSV @@ -69,7 +71,7 @@ Thanks [@eyedol](https://github.com/eyedol) ## How to run it on a server 1. Clone project to a directory on your web server. -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. 1. Follow this long tutorial to get Flask running. It was way more work than it should be: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-16-04 @@ -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) - you can see the paths where I installed it, and the name of my virtualenv directory - when done with tutorial: - ``` + ```shell sudo systemctl restart flash_cards 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.* 1. Install dependencies: - 1. Install [Python ](https://www.python.org/download/releases/2.7/) - 2. 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) - 4. 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) - 6. 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')``` -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 -4. Open localhost:5000/initdb -5. Login using id:USERNAME='admin', PASSWORD='default. -6. Comment the line 52-55 in flash_cards.py + 1. Install [Python](https://www.python.org/download/releases) + 1. Add python as environment variable [windows](http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7) + 1. To install pip, securely download [get-pip.py](https://bootstrap.pypa.io/get-pip.py) + 1. Run `python get-pip.py` in terminal + 1. Add pip to your PATH system variable [windows](https://stackoverflow.com/questions/23708898/pip-is-not-recognized-as-an-internal-or-external-command) + 1. Run `pip install -r requirements.txt` in terminal after going to correct folder +1. Open flash_cards.py and uncomment the line 52-55 beginning from `@app.route('/initdb')` +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 +1. Open localhost:5000/initdb +1. Login using id:USERNAME='admin', PASSWORD='default'. +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: -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 -3. 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``` +**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 +1. Edit file `flash_cards.py` line 11 and replace cards with any of the other database files +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 *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. 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. -1. Build image: `docker build . -t cs-flash-cards` -1. Run container: `docker run -d -p 8000:8000 --name cs-flash-cards cs-flash-cards` +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. +1. Build image: + - Docker: `docker build . -t 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` __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.* -`docker run -d -p 8000:8000 --name cs-flash-cards -v :/src/db cs-flash-cards`. -``: is the full path contains `cards.db`. -Example: `/home/tinpee/cs-flash-cards/db`, and `cards.db` is inside this folder. + +```shell +docker run -d -p 8000:8000 --name cs-flash-cards -v :/src/db cs-flash-cards +``` + +- ``: 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`. @@ -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) - change `entrypoint.sh` -``` + +```shell - export CARDS_SETTINGS=/src/config.txt gunicorn --bind 0.0.0.0:$8000 flash_cards:app + export CARDS_SETTINGS=/src/config.txt @@ -159,7 +172,7 @@ gunicorn --bind 0.0.0.0:$PORT flash_cards:app ```shell heroku login heroku container:login -heroku create +heroku create # Creating app... done, ⬢ your-app-name heroku container:push web --app your-app-name heroku container:release web --app your-app-name @@ -173,4 +186,3 @@ heroku open --app your-app-name Check out the demo! *Happy learning!* -