Giter VIP home page Giter VIP logo

flix-containerized's Introduction

Heroku and Rails for Windows users

who want to be Linux users


Description

Skeleton docker/rails application for use with Pragmatic Studios Flix exercise

Requirements

Instructions

Create a file within your app's root directory named Dockerfile (no file extension, just "Dockerfile") Copy the following into your dockerfile and save.

FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /<your app name>
WORKDIR /{your app name>
COPY Gemfile /<your app name>/Gemfile
COPY Gemfile.lock /<your app name>/Gemfile.lock
RUN bundle install
COPY . /<your app name>

From within ${your_app}/config, find and rename database.yml to old_database.yml Create a new file of the same name, in the same location. Save both files for now. Within your application's root directory, create a file named docker-compose.yml Copy the following into docker-compose.yml and save.

version: '3'
services:
  db:
    image: postgres
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/<your app name>
    ports:
      - "3000:3000"
    depends_on:
      - db

Open your new database.yml file, and, after replacing with your application's name in both locations, save it with the following contents:

default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password:
  pool: 5

development:
  <<: *default
  database: <your app name>_development


test:
  <<: *default
  database: <your app name>_test

From your command line, run

docker-compose up --build

At this point you should see something similar to the following:

Starting rails_db_1 ...
Starting rails_db_1 ... done
Recreating rails_web_1 ...
Recreating rails_web_1 ... done
Attaching to rails_db_1, rails_web_1
db_1   | LOG:  database system was shut down at 2017-06-07 19:12:02 UTC
db_1   | LOG:  MultiXact member wraparound protections are now enabled
db_1   | LOG:  database system is ready to accept connections
db_1   | LOG:  autovacuum launcher started
web_1  | => Booting Puma
web_1  | => Rails 5.0.0.1 application starting in development on http://0.0.0.0:3000
web_1  | => Run `rails server -h` for more startup options
web_1  | Puma starting in single mode...
web_1  | * Version 3.9.1 (ruby 2.3.3-p222), codename: Private Caller
web_1  | * Min threads: 5, max threads: 5
web_1  | * Environment: development
web_1  | * Listening on tcp://0.0.0.0:3000
web_1  | Use Ctrl-C to stop

โ— In a separate terminal โ— run:

docker-compose run web rails db:create

You should then see something like this:

Starting rails_db_1 ... done
Created database 'flix_development'
Created database 'flix_test'

From here, stop your server. To do this, run:

    docker-compose down

from your original terminal. You can just ctrl-c to exit, as usual, but this is known to cause the error:

web_1 | A server is already
running. Check /flix/tmp/pids/server.pid.

when attempting to restart your server. If that's the case, just remove the aforementioned pid file and you're on your way.

Restarting your application

docker-compose up

from within your project's root directory (i.e. make sure you can see your dockerfile when checking your directory) In another terminal, run docker-compose run web rails db:create


At this point, you should be able to view your application in the browser, just as if you were running it without docker.

flix-containerized's People

Contributors

jaycb3 avatar jcbennett3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.