Permalink
Browse files

Merge pull request #218 from rporres/moar-docker

Separate docker compose environments and added documentation
  • Loading branch information...
numeroteca committed Dec 14, 2018
2 parents 2cd70b0 + 782ff16 commit 79de1c2041573e16b8aec53a2a43ce6ebedee020
@@ -0,0 +1,6 @@
.git
docker-compose.yml
doc
*.md
docker-ruby
docker-compose-files

This file was deleted.

Oops, something went wrong.
@@ -11,7 +11,15 @@ More Info

You can find more information and examples at http://pageonex.com or at [the blog](http://montera34.org/pageonex/)

Running pageonex
----------------

Pageonex is an open-source project. If you don't want to use the hosted version of pageonex at http://pageonex.com you have a few options to run it yourself.

* [You can run pageonex locally using docker-compose and our generated images](docs/docker/running-pageonex-locally-with-docker-compose.md). This is the easiest way.
* [You can run pageonex locally using docker-compose and building locally the docker images](doc/docker/development-with-docker-compose.md). This is recommended if you want to do some development.
* [You can install pageonex locally compiling in your system all the needed files](doc/local-install.md). This option is more advanced and it is only recommended if you're doing heavy development.
* [You can use our Docker images to deploy pageonex against your mysql database](doc/docker/running-pageonex-in-your-environment.md). This is an advanced setup that it is useful if you're planning to maintain your own pageonex production environment.

Collaborators
-------------

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,49 @@
# Developing pageonex with docker-compose

If you need to do development in pageonex without the hassle of installing all the dependencies you can use our [docker-compose-build file](/docker-compose-build.yml) which builds the application from scratch.

* In order to start the pageonex and mysql containers, run from the root of this repository:
```
docker-compose -f docker-compose-build.yml up -d --build
```

* To create the initial database:
```
docker-compose -f docker-compose-build.yml exec app_build rake db:migrate --trace
```

* To get a the rails console (See [INSTALL.md](/doc/INSTALL.md) for instructions on creating an admin user)
```
docker-compose -f docker-compose-build.yml exec app_build rails console
```

* To load the list of newspapers into the data baserun:
```
docker-compose -f docker-compose-build.yml exec app_build rake scraping:update_media --trace
```

* If you make changes in the app and you want to rebuild your container
```
docker-compose -f docker-compose-build.yml up -d --build
```

* If you want to log in the mysql database
```
docker-compose -f docker-compose-build.yml exec app_build mysql -u root --password=root dc-dev
```

* If you want to inspect the logs
```
docker-compose -f docker-compose-build.yml logs
```

* If you want to shut down everything
```
docker-compose -f docker-compose-build.yml stop
```

* If you want to remove everything and have a new and clean environment
```
docker-compose -f docker-compose-build.yml rm -s -v
docker volume rm build_db_data build_app_data
```
@@ -0,0 +1,38 @@
# Runining pageonex in your environment

If you want to create your own deployment of pageonex, the easiest way to do it is to use one of our [docker images](https://hub.docker.com/r/pageonex/pageonex/tags) and connect it to the database. These are the main configuration areas:

## Rails environment configuration

You need to set the `RAILS_ENV` to `production`

## Database access configuration

Pageonex has been mainly tested with mysql, so this is our recommendation. Due to [this issue](https://github.com/montera34/pageonex/issues/212), mysql <= 5.6 is required

There are a few env variables that should be set to customize your database access:

* `DATABASE_ADAPTER`: This should be set to `mysql2`
* `DATABASE_USERNAME`: The database user to accesss
* `DATABASE_PASSWORD`: The password corresponding to above user
* `DATABASE_HOST`: Database address
* `DATABASE_PORT`: Database port
* `DATABASE_NAME`: Database name in above host:port

See [database.yml](/config/database.yml) for more settings and default values.

## Filesystem mounts

There are a few mount points to be set in order to avoid writes in the container filesystem which would lead to data loss and performance degradation:

* kiosko images: `/workspace/app/assets/images/kiosko`
* threads images: `/workspace/app/assets/images/threads`
* temp files: `/workspace/tmp`

## Rake tasks

These should be run on deployment:

* Database schema creation/modification: `db:migrate`
* Media list: `scraping:update_media`
* Assets precompilation: `bundle exec rake assets:precompile`
@@ -0,0 +1,62 @@
# Running pageonex locally with docker compose

You can test locally pageonex using [docker compose](https://docs.docker.com/compose/). Just running

```
docker-compose up
```

you will get

* A mysql database running [the official mysql image](https://hub.docker.com/_/mysql/)
* All the migration and admin tasks run
* A pageonex server running [the lastest pageonex image](https://hub.docker.com/r/pageonex/pageonex)
* All data stored in separate volumes that will remain even if you delete your application's containers

Once everything is running correctly, you can access the application from your browser in http://localhost:3000

## Tasks

### How to run in detached mode

In order to run docker-compose in background and have the shell available, please use detached mode
```
docker-compose up -d
```

### How to see logs

Logs are not shown in the screen in detached mode, you can inspect them using
```
docker-compose logs
```

### How to access the rails console

In case you want to further inspect the application, you can run
```
docker-compose exec app rails console
```

### How to access the database

In case you want to further inspect the database, you can run
```
docker-compose exec mysql mysql -u root -h localhost --password=root dc-prod
```

### How to shut it down

If you want to shut down everything, keeping volumes and images for a quick start
```
docker-compose stop
```

### How to delete everything and start from scratch

You may want to start fresh. You have to make sure that all related images, containers are both stopped and deleted and volumes are deleted
```
docker-compose stop
docker-compose rm
docker volume rm pageonex_app_kiosko_images pageonex_app_threads_images pageonex_db_data pageonex_app_tmp_dir
```
File renamed without changes.
@@ -0,0 +1,42 @@
version: '3'
volumes:
build_db_data:

services:
mysql_build:
image: mysql:5.6.40
restart: always
ports:
- "23306:23306"
volumes:
- build_db_data:/var/lib/mysql
- ./docker-compose-files/pageonex-build.cnf:/etc/mysql/conf.d/pageonex-build.cnf
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=dc-dev

app_build:
build: .
environment:
- RAILS_ENV=development
- DATABASE_ADAPTER=mysql2
- DATABASE_USERNAME=root
- DATABASE_PASSWORD=root
- DATABASE_HOST=mysql_build
- DATABASE_PORT=23306
- DATABASE_NAME=dc-dev
depends_on:
- "mysql_build"
ports:
- '3000:3000'
links:
- "mysql_build"
volumes:
- .:/workspace
- ./docker-compose-files/wrap-start-app.sh:/usr/local/bin/wrap-start-app.sh
working_dir: /workspace
command:
- wrap-start-app.sh
- mysql_build
- root
- "bundle exec puma -C config/puma.rb"
@@ -0,0 +1,2 @@
[mysqld]
port=23306
@@ -8,14 +8,16 @@ password="$2"
shift; shift
cmd="$@"

exec 2>&1

rm -f /workspace/tmp/pids/server.pid

port=${DATABASE_PORT:-3306}

until mysql -u root --port $port --password=$password -h $host -e "SELECT 1"; do
>&2 echo "Mysql is unavailable - sleeping"
echo "Mysql is unavailable - sleeping"
sleep 1
done

>&2 echo "Mysql is up - executing command"
exec $cmd
echo "Mysql is up - executing command"
exec bash -c "$cmd"
@@ -1,51 +1,46 @@
version: '2'
version: '3'
volumes:
db_data:
app_kiosko_images:
app_threads_images:
app_tmp_dir:

services:
mysql:
image: mysql:5.6.40
image: "mysql:5.6.40"
restart: always
ports:
- "13306:13306"
volumes_from:
- dbdata
volumes:
- ./docker-files/pageonex.cnf:/etc/mysql/conf.d/pageonex.cnf
- db_data:/var/lib/mysql
- ./docker-compose-files/pageonex.cnf:/etc/mysql/conf.d/pageonex.cnf
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=dev

dbdata:
image: tianon/true
volumes:
- /var/lib/mysql
- MYSQL_DATABASE=dc-prod

app:
build: .
image: pageonex/pageonex:latest
environment:
- RAILS_ENV=development
- RAILS_ENV=production
- DATABASE_ADAPTER=mysql2
- DATABASE_USERNAME=root
- DATABASE_PASSWORD=root
- DATABASE_HOST=mysql
- DATABASE_PORT=13306
- DATABASE_NAME=dev
- DATABASE_NAME=dc-prod
depends_on:
- "mysql"
ports:
- '3000:3000'
volumes_from:
- app_data
links:
- "mysql"
volumes:
- app_tmp_dir:/workspace/tmp
- app_kiosko_images:/workspace/app/assets/images/kiosko
- app_threads_images:/workspace/app/assets/images/threads
- ./docker-compose-files/wrap-start-app.sh:/usr/local/bin/wrap-start-app.sh
command:
- ./docker-files/cleanup-pid-file-and-wait-for-mysql.sh
- wrap-start-app.sh
- mysql
- root
- bundle
- exec
- puma
- -C
- "config/puma.rb"

app_data:
image: tianon/true
volumes:
- ".:/workspace"
- "bundle exec rake db:migrate --trace && bundle exec rake scraping:update_media && bundle exec rake assets:precompile --trace && bundle exec puma -C config/puma.rb"

0 comments on commit 79de1c2

Please sign in to comment.