Skip to content

Commit

Permalink
Merge pull request #53 from dsc-umass/docker-refresh
Browse files Browse the repository at this point in the history
Adding Docker-Compose
  • Loading branch information
harsh183 authored Jun 30, 2020
2 parents 9e69298 + dc8a79b commit bbdb9bc
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 4 deletions.
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,71 @@ Project Matching is an open source project that helps teams/clubs help match the

### Prerequisites

Since this is a Rails Application it requires Ruby.
Since the applciation has been containerized through docker-compose, you would need docker-compose.

### Installing & Running the Container

To build the container(this is a one time build):

```
sudo docker-compose build
```

To run the container (everytime you want to start the application):

```
sudo docker-compose up
```

You can press ctrl/command + C on the terminal to stop the container.

### Accessing the Rails Container

To access the Rails Container:

```
sudo bash docker_shell.sh
```
If you want to access the rails console, then run the following command after the previous one:

```
rails c
```

### Accessing the Postgres Container

To access the Postgres Container:

```
sudo bash db_shell.sh
```

Then type:

```
psql project_matching_development projectmatch projectmatchpass
```

### Common Errors & FAQ

In case of a database not found or database not created error:

Access the Rails Container and run:

```
cd docker
bash db_setup.sh
```

If you want to reset the container and want to rebuild it, run:

```
sudo docker-compose down
```

and then rebuild it with docker-compose build

<!--
### Installing
Expand Down
7 changes: 4 additions & 3 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
pool: 5
username: projectmatch
password: projectmatchpass
host: postgres

development:
<<: *default
Expand Down
2 changes: 2 additions & 0 deletions db_shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker exec -it project-matching_postgres_1
# psql project_matching_development projectmatch projectmatchpass
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3"
services:
postgres:
image: postgres
environment:
- POSTGRES_USER=projectmatch
- POSTGRES_PASSWORD=projectmatchpass
volumes:
- ./db/postgres:/var/lib/postgresql/data
rails:
build:
context: .
dockerfile: docker/Dockerfile
depends_on:
- postgres
links:
- postgres
volumes:
- ./:/usr/src/app
ports:
- "3000:3000"

29 changes: 29 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ruby:2.7.0

# Installs dependencies to run Rails on the ruby:2.7.0 image
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
postgresql-client

# Configure the main working directory
WORKDIR /usr/src/app

# Copies the main application to run install dependencies and rake files
COPY . .

# Yarn installation
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update && apt-get install -y yarn
RUN yarn install

# Installs gems listed in the Gemfile.lock & Package.json
RUN bundle install

# Exposes the 3000 port to access it outside of the image
EXPOSE 3000

# Default command that runs when the container starts
CMD ["bash", "docker/docker_set_up.sh"]
4 changes: 4 additions & 0 deletions docker/db_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Database Setup
bundle exec rake db:create
bundle exec rake db:schema:load

3 changes: 3 additions & 0 deletions docker/docker_set_up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rm tmp/pids/server.pid
yarn install --check-files
bundle exec rails server -b 0.0.0.0
1 change: 1 addition & 0 deletions docker_shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose exec rails ${@:-/bin/bash}

0 comments on commit bbdb9bc

Please sign in to comment.