Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasham committed Dec 18, 2016
2 parents 0f84003 + a102117 commit 1b3eb17
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ MAINTAINER Tinpee <[email protected]>

ADD . /src
WORKDIR /src
RUN pip install flask gunicorn \
&& cp cards-jwasham.db cards.db
RUN pip install flask gunicorn

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

VOLUME /src/db

EXPOSE 8000
CMD ["/entrypoint.sh"]

Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Don't be like me.
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
- `wsgy.py` is the entry point. It calls `flash_cards.py`
- `wsgi.py` is the entry point. It calls `flash_cards.py`
- 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:
Expand Down Expand Up @@ -80,6 +80,24 @@ __Make sure you already installed [docker](https://www.docker.com)__
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. Go your browser and type `http://localhost:8000`
1. To back up your cards db, run `docker cp cs-flash-cards:/src/cards.db /path/to/save`
__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 :<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 convenient, if you don't have `cards.db`, this container will auto copy a new one from `cards-jwasham.db`. So you don't need to `initdb`.
### How to backup data ?
We just need store `cards.db` file, and don't need any sql command.
- If you run container with `-v <folder_db>:/src/db` just go to `folder_db` and store `cards.db` anywhere you want.
- Without `-v flag`. Type: `docker cp <name_of_container>:/src/db/cards.db /path/to/save`
### How to restore data ?
- Delete old container (not image): `docker rm cs-flash-cards`
- Build a new one with `-v flag`:
`docker run -d -p 8000:8000 --name cs-flash-cards -v <path_to_folder_contains_cards_db>:/src/db cs-flash-cards`
- Voila :)
*Happy learning!*
Empty file added db/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash

if [ ! -f /src/db/cards.db ]; then
cp cards-jwasham.db /src/db/cards.db
fi

export CARDS_SETTINGS=/src/config.txt
gunicorn --bind 0.0.0.0:8000 flash_cards:app
2 changes: 1 addition & 1 deletion flash_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Load default config and override config from an environment variable
app.config.update(dict(
DATABASE=os.path.join(app.root_path, 'cards.db'),
DATABASE=os.path.join(app.root_path, 'db', 'cards.db'),
SECRET_KEY='development key',
USERNAME='admin',
PASSWORD='default'
Expand Down

0 comments on commit 1b3eb17

Please sign in to comment.