-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix setup for development with docker
- Loading branch information
Showing
9 changed files
with
240 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM ruby:2.3 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# Install dependencies | ||
RUN deps='libmagic-dev xvfb qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x' && \ | ||
apt-get update && \ | ||
apt-get install --no-install-recommends -y $deps && \ | ||
rm -Rf /var/lib/apt/lists/* /var/cache/apt/* | ||
|
||
ENV PORT=3000 \ | ||
SMTP_SERVER_PORT=2525 \ | ||
RAILS_ENV=development \ | ||
RAILS_LOG_TO_STDOUT=true \ | ||
RAILS_SERVE_STATIC_FILES=true \ | ||
\ | ||
BUNDLE_PATH=/home/app/bundle \ | ||
BUNDLE_APP_CONFIG=/home/app/bundle/config | ||
|
||
# Run app and all commands as user 'app'. This avoids changing permissions | ||
# for files in mounted volume. Symlink for similarity with production image. | ||
RUN adduser --gecos GECOS --disabled-password --shell /bin/bash app && \ | ||
mkdir -p /home/app/src && ln -s /home/app/src /usr/src/app | ||
USER app | ||
|
||
# Copy files needed for installing gem dependencies, and install them. | ||
COPY Gemfile Gemfile.lock ./ | ||
COPY plugins ./plugins | ||
RUN bundle config build.nokogiri "--use-system-libraries" && \ | ||
bundle install -j 4 | ||
|
||
# Copy the application code | ||
COPY . ./ | ||
|
||
EXPOSE 3000 | ||
|
||
# cleanup, and by default start web process from Procfile | ||
ENTRYPOINT ["./docker-entrypoint.sh"] | ||
CMD ["./proc-start", "web"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ Xvfb $DISPLAY -nolisten tcp & | |
XVFB_PID=$! | ||
|
||
# Start tests | ||
rspec | ||
rspec $@ | ||
|
||
# Cleanup | ||
kill $XVFB_PID |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Foodsoft on Docker | ||
|
||
This document explains setting up Foodsoft with Docker for development. | ||
system. Another option is to run it [within an existing system](SETUP_DEVELOPMENT.md). | ||
If instead you just want to run Foodsoft without changing its code, please refer to | ||
[hosting](https://foodcoops.github.io/foodsoft-hosting/) or | ||
[deployment](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes). | ||
|
||
|
||
## Requirements | ||
|
||
* Docker (=> 1.9.1) | ||
* Docker Compose (=> 1.4) | ||
* Nothing more, no Ruby, MySQL, Redis etc! | ||
|
||
For installing instructions see https://docs.docker.com/installation/. | ||
Docker runs on every modern Linux kernel, but also with a little help on MacOS | ||
and Windows! | ||
|
||
## Setup | ||
|
||
Then setup foodsoft development (this will take some time, containers needs | ||
to be pulled from docker registry and a lot dependencies needs to be installed) | ||
|
||
docker-compose -f docker-compose-dev.yml run web rake foodsoft:setup_development | ||
|
||
Do not enable mailcatcher, because this is already included as a docker image. | ||
|
||
To avoid having to pass the `-f` argument all the time, it is recommended to setup | ||
an alias, e.g. by adding the following line to your ~/.bashrc | ||
|
||
alias docker-compose-dev='docker-compose -f docker-compose-dev.yml' | ||
|
||
then reload it by executing `. ~/.bashrc`. Following commands assume this is setup. | ||
|
||
|
||
## Usage | ||
|
||
Start containers (in foreground, stop them with `Ctrl-C`) | ||
|
||
docker-compose-dev up | ||
|
||
Run a rails/rake command | ||
|
||
docker-compose-dev run --rm web rake db:migrate | ||
|
||
Open a rails console | ||
|
||
docker-compose-dev run --rm web rails c | ||
|
||
Setup the test database | ||
|
||
docker-compose-dev run --rm web rake db:setup RAILS_ENV=test DATABASE_URL=mysql2://root:secret@mariadb/test | ||
|
||
Run the tests | ||
|
||
docker-compose-dev run --rm web ./bin/test | ||
|
||
Jump in a running container for debugging. | ||
|
||
docker exec -ti foodsoft_web_1 bash | ||
|
||
|
||
## Notes | ||
|
||
### Receiving mails | ||
|
||
Go to [http://localhost:1080](http://localhost:1080) | ||
|
||
### Gemfile updates | ||
|
||
As the gem bundle is stored in a volume, you can run | ||
|
||
docker-compose-dev run web bundle install | ||
docker-compose-dev restart web worker | ||
|
||
Do this each time you update your `Gemfile`. | ||
|
||
### Database configuration | ||
|
||
To make this easier we use the environment variable `DATABASE_URL` | ||
(and `TEST_DATABASE_URL` when using the testing script). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,62 @@ | ||
Running Foodsoft in production | ||
============================== | ||
# Deployment | ||
|
||
As you might have noticed, documentation is scarce and insufficient. If you | ||
intend to deploy foodsoft in production, we would love to guide you through the | ||
process. You can contact the mailing list | ||
[foodsoft-discuss](http://foodsoft.51229.x6.nabble.com/foodsoft-discuss-f5.html). | ||
The recommended way to run Foodsoft in production is using docker. Alternative options are | ||
discussed [in the wiki](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes). If you | ||
have any questions, please contact the mailing list [foodsoft-discuss](http://foodsoft.51229.x6.nabble.com/foodsoft-discuss-f5.html). | ||
|
||
## Docker | ||
|
||
_This section is a work in progress._ | ||
|
||
### Build | ||
|
||
You can use the [official production docker image](https://hub.docker.com/r/foodcoops/foodsoft/). | ||
If you want to build the image yourself instead, run: | ||
|
||
docker build --tag foodsoft:latest --rm . | ||
|
||
### Run (basic) | ||
|
||
You'll need to set at least the following environment variables: | ||
|
||
* `SECRET_KEY_BASE` - random string of 30+ characters, try `rake secret` | ||
* `DATABASE_URL` - pointing to your MySQL installation (`mysql2://user:pass@mysql.host/foodsoftdb?encoding=utf8`) | ||
* `REDIS_URL` - pointing to your Redis instance (`redis://redis.host:6379`) | ||
|
||
You'll also need to supply the Foodsoft configuration file, for example by | ||
mounting it as a volume. Copy `config/app_config.yml.SAMPLE` to `config/app_config.yml` | ||
and customize the settings. | ||
|
||
Then run the webserver, exposing port 3000 on the current host: | ||
|
||
docker run --name foodsoft_web -p 3000 \ | ||
-e SECRET_KEY_BASE -e DATABASE_URL -e REDIS_URL -e RAILS_FORCE_SSL=false \ | ||
-v `pwd`/config/app_config.yml:/usr/src/app/config/app_config.yml:ro \ | ||
foodsoft:latest | ||
|
||
This should get you started. But first you'll need to populate the database: | ||
|
||
docker run --name foodsoft_setup --rm \ | ||
-e SECRET_KEY_BASE -e DATABASE_URL -e REDIS_URL \ | ||
-v `pwd`/config/app_config.yml:/usr/src/app/config/app_config.yml:ro \ | ||
foodsoft:latest bundle exec rake db:setup | ||
|
||
To run the worker (recommended!), supply a different command | ||
(see [Procfile](../Procfile) for other types): | ||
|
||
docker run --name foodsoft_worker \ | ||
-e SECRET_KEY_BASE -e DATABASE_URL -e REDIS_URL \ | ||
-v `pwd`/config/app_config.yml:/usr/src/app/config/app_config.yml:ro \ | ||
foodsoft:latest ./proc-start worker | ||
|
||
To also run the cronjobs, start the previous command but substituting | ||
`mail` with `cron`. That should give you the ingredients for a production-setup. | ||
With the help of a front-end webserver doing ssl, of course. | ||
|
||
|
||
### Run (docker-compose) | ||
|
||
In practice, you'd probably want to use docker-compose. If you know Docker well enough, | ||
you'll have no problem to set this up. For inspiration, look at the | ||
[foodcoops.net production setup](https://github.com/foodcoops/foodcoops.net). | ||
|
||
Please see our wiki page: [Deployment notes](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes). |
Oops, something went wrong.