Skip to content

Commit

Permalink
Feature/image backup (#320)
Browse files Browse the repository at this point in the history
* Update sample_env_file_for_docker.list (#314)

* Create backups.md

* adding healthcheck to docker compose files and adding docs on how to take image backups

* updating quickstart with image backup

* updating gitignore
  • Loading branch information
RyanNoelk authored Jan 24, 2018
1 parent 9acbda5 commit b772cdf
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ static-files/
database/
frontend/build/
frontend/jest/
site-media/
openeats.sql

servies/static-files/
servies/side-media/
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
api:
build: api/
Expand Down
9 changes: 7 additions & 2 deletions docker-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
api:
image: openeats/api
Expand All @@ -8,7 +8,8 @@ services:
- static-files:/code/static-files
- site-media:/code/site-media
depends_on:
- db
db:
condition: service_healthy
env_file:
env_prod.list
node:
Expand All @@ -20,6 +21,10 @@ services:
env_prod.list
db:
image: mariadb
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 20
env_file:
env_prod.list
nginx:
Expand Down
9 changes: 7 additions & 2 deletions docker-stage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
api:
build: api/
Expand All @@ -8,7 +8,8 @@ services:
- static-files:/code/static-files
- site-media:/code/site-media
depends_on:
- db
db:
condition: service_healthy
env_file:
env_stg.list
node:
Expand All @@ -22,6 +23,10 @@ services:
env_stg.list
db:
image: mariadb
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 20
env_file:
env_stg.list
nginx:
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions docs/Running_the_App.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

The recommended way to run this app is with docker. You can install docker [here](https://www.docker.com/products/overview). If you are not familiar with docker you can read more about it on [their website](https://www.docker.com/what-docker).

If you are looking to run the app without docker, see the instructions [here](Running_without_Docker.md)

### Running the app with docker for production

If you are looking to run this in production, there is no need to clone the repo.
Expand All @@ -12,7 +10,7 @@ First, create two files:
- docker-prod.yml - This file can be found in the in the root directory of the repo.
- env_prod.list - The settings file [sample_env_file_for_docker.list](sample_env_file_for_docker.list) can be used as an example.

The `docker-prod.yml` contains the list of images and commands to run the app. It come with an nginx reverse proxy that by default will run on port 80. You will most likely want to change the port that nginx runs on as well as use a fix tag for the image. By default all are set to latest.
The `docker-prod.yml` contains the list of images and commands to run the app. It comes with an nginx reverse proxy that by default will run on port 80. You will most likely want to change the port that nginx runs on as well as use a fix tag for the image. By default, all are set to latest.

#### Configure the environment file
Most of the settings in your `env_prod.list` can stay the same as `env_stg.list` that is in this repo. There are a few config settings that need to be changed for most configurations. See [Setting_up_env_file.md](Setting_up_env_file.md) for a complete description of the environment variables.
Expand Down
18 changes: 18 additions & 0 deletions docs/Taking_Backups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Backing up Your Data

The following commands can be used to take backups of your data. These commands are automatically run when you upgrade to a newer version as well.


#### Backing up recipes images:

Replace `/dir/on/local/system/` with the location where you would like your images.
```sh
docker cp openeats_api_1:/code/site-media/ /dir/on/local/system/
```

#### Backing up database:

Places a sql dump of the database on your current working directory.
```sh
docker exec openeats_db_1 sh -c 'exec mysqldump openeats -uroot -p"$MYSQL_ROOT_PASSWORD"' > openeats.sql
```
2 changes: 1 addition & 1 deletion docs/sample_env_file_for_docker.list
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ API_PORT=8000
DJANGO_SECRET_KEY=sdfsadfas32e98zsdvhhsnz6udvbksjdhfi4galshjfg
DJANGO_SETTINGS_MODULE=base.settings
DJANGO_DEBUG=False
ALLOWED_HOST='my.domain.com'
ALLOWED_HOST=my.domain.com
HTTP_X_FORWARDED_PROTO=true

# Node config
Expand Down
17 changes: 16 additions & 1 deletion quick-start.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# encoding: utf-8

from time import sleep
from os import getcwd
from subprocess import call, Popen, PIPE


Expand All @@ -28,7 +29,7 @@ def start_containers():
)
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
if output and not err:
print("Take a database backup (saving as openeats.sql)...")
print("Taking a database backup (saving as openeats.sql)...")
call(
'docker exec openeats_db_1 sh -c ' +
'\'exec mysqldump openeats -uroot -p"$MYSQL_ROOT_PASSWORD"\'' +
Expand All @@ -40,6 +41,20 @@ def start_containers():
call(['docker-compose', '-f', 'docker-prod.yml', 'up', '-d', 'db'])
sleep(45)

p = Popen(
['docker', 'ps', '-q', '-f', 'name=openeats_api_1'],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE
)
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
if output and not err:
print("Taking a image backup save to 'site-media'...")
call(
'docker cp openeats_api_1:/code/site-media/ ' + getcwd(),
shell=True
)

call(['docker-compose', '-f', 'docker-prod.yml', 'stop', 'nginx'])
call(['docker-compose', '-f', 'docker-prod.yml', 'stop', 'api'])
call(['docker-compose', '-f', 'docker-prod.yml', 'stop', 'node'])
Expand Down

0 comments on commit b772cdf

Please sign in to comment.