Skip to content

Commit

Permalink
feat: Add Docker Compose support and instructions
Browse files Browse the repository at this point in the history
- Add Dockerfile, docker-compose.yml, entrypoint.sh, and .dockerignore
- Update README with instructions for Docker Compose
  • Loading branch information
blms committed Aug 31, 2021
1 parent 0bd3081 commit 25cb650
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 11 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.DS_Store
.git
.dockerignore
.vscode
.env

/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
/storage/*

/convert/node_modules
/client/node_modules
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1
FROM ruby:2.5.7 AS dm2-dev

# Install node.js and yarn
RUN apt-get update -qq && apt-get install -y curl sudo
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
RUN apt-get install -y nodejs
RUN npm install -g yarn

# Install bundler and API
ENV INSTALL_PATH /opt/app
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY . $INSTALL_PATH
RUN gem install bundler
RUN bundle install

# Add a script to be executed every time the container starts
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
EXPOSE 3001

# Install frontend
WORKDIR $INSTALL_PATH/client
RUN yarn install

# Run shell
CMD ["/bin/sh"]
70 changes: 59 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,30 @@ DM2 was developed under the direction of Martin Foys and his team at the Univers

DM2 design was inspired by the DM project (https://github.com/performant-software/DM) developed originally at Drew University by Martin Foys and others.


Technical Overview
- [Technical overview](#technical-overview)
- [Heroku installation](#heroku-installation)
* [Create app](#create-app)
* [Provision resources](#provision-resources)
* [Configuration variables](#configuration-variables)
* [Set up database](#set-up-database)
- [Local installation](#local-installation)
* [With Docker Compose](#with-docker-compose)
* [With Heroku local development environment](#with-heroku-local-development-environment)
* [Manually](#manually)
- [Active Storage](#active-storage)

Technical overview
---------------

DM2 is a single page React application backed by a Ruby on Rails server running a Postgres database. It uses ActiveStorage for image uploads and ImageMagick for image processing. It utilizes the SendGrid service for outbound SMTP and Amazon S3 for image storage. It has been developed within the Heroku (heroku.com) environment but has no Heroku specific dependencies. Issues are tracked and relases are issued on the GitHub repo at https://github.com/performant-software/dm-2 .
DM2 is a single page React application backed by a Ruby on Rails server running a Postgres database. It uses ActiveStorage for image uploads and ImageMagick for image processing. It utilizes the SendGrid service for outbound SMTP and Amazon S3 for image storage. It has been developed within the Heroku (heroku.com) environment but has no Heroku specific dependencies. Issues are tracked and releases are issued on the [DM2 GitHub repo](https://github.com/performant-software/dm-2).


Heroku Installation
Heroku installation
-------------

### Create app

To install DM2 on Heroku, create a new app and point it at this respository, using the following command with the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli):
To install DM2 on Heroku, create a new app and point it at this repository, using the following command with the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli):

```sh
heroku create --stack heroku-18
Expand Down Expand Up @@ -112,12 +123,50 @@ heroku run rails db:migrate && heroku run rails db:seed

DM2 should now be up and running on your Heroku instance!

The first user account created is automatically given admin powers. Thereafter, that user can grant other users access and privledges using the Admin menu in the top right corner of the interface.

The first user account created is automatically given admin powers. Thereafter, that user can grant other users access and privileges using the Admin menu in the top right corner of the interface.

Heroku Local Development Environment
Local installation
-------------

### With Docker Compose

DM2 can be installed quickly using Docker Compose. The only requirements are [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) themselves.

First, clone the repo from GitHub, `cd` into the repo directory, and copy the sample environment variables into `.env` and `config/application.yml`.

```sh
git clone https://github.com/performant-software/dm-2.git
cd dm-2
cp .env.sample .env
cp config/application.sample.yml config/application.yml
```

Edit the environment variables as necessary. The sample values are all standard for a development environment, except for those left blank: `SECRET_KEY_BASE` should be a secure encryption key, and `SENDGRID_PASSWORD` should be a SendGrid API Key. For more information about these variables, see above section on [configuration variables](#configuration-variables).

Then, use Docker Compose to build the necessary Docker images:
```sh
docker-compose build
```

Run any pending database migrations:
```sh
docker-compose run --rm rails db:migrate
```

And finally, boot the application:
```sh
docker-compose up
```

After boot completes, the app should be up and running on `localhost:3000`.

You may stop the application at any time by opening another shell in the same `dm-2` directory and running:
```sh
docker-compose down
```

### With Heroku local development environment

DM2 is a pretty standard Ruby on Rails 5.x application. It uses a PostgreSQL and has been developed using PostgreSQL v11.1. It was developed using Ruby 2.5.7 and Bundler 2.2.23. Setting up PostgresSQL, Ruby, and Bundler are beyond the scope of this README, but plenty of information is available online about these tools.

Once the dependencies mentioned above are installed, please follow these steps:
Expand Down Expand Up @@ -159,10 +208,9 @@ Note that this runs two servers, one on port 3000 for Ruby on Rails and one on 3

Please note that the development environment stores files on local disk in the /storage directory by default. You can configure different storage solutions in config/storage.yml. See the Rails ActiveStorage documentation for more details.

Installation without Heroku Toolset
-------------
### Manually

Installation without the Heroku tool set is possible but requires setup specific to your enviroment. Follow the steps given above, except when it comes time to run the application, run the client and the server with these commands:
Installation without Docker or the Heroku toolset is possible but requires setup specific to your environment. Follow the steps given above, except when it comes time to run the application, run the client and the server with these commands:

To run the client:

Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.9"
services:
db:
image: postgres:11.12
environment:
POSTGRES_USER: dm2_staging
POSTGRES_PASSWORD: dm2_staging_password
command: postgres -c listen_addresses='*'
volumes:
- ./tmp/db:/var/lib/postgresql/data
app:
build: .
command: bash -c "rm -f tmp/pids/server.pid && cd /opt/app && foreman start -f Procfile.dev"
volumes:
- .:/opt/app
ports:
- "3001:3001"
- "3000:3000"
depends_on:
- db
env_file:
- .env
environment:
DATABASE_URL: postgres://dm2_staging:dm2_staging_password@db
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /opt/app/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

0 comments on commit 25cb650

Please sign in to comment.