Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose config for developing and running tests #1125

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,5 +1,10 @@
FROM ruby:2.6.0

ARG PG_VERSION=9.6

RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_VERSION > /etc/apt/sources.list.d/pgdg.list

# Make nodejs and yarn as dependencies
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
@@ -8,24 +13,27 @@ RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources
# Install dependencies and perform clean-up
RUN apt-get update -qq && apt-get install -y \
build-essential \
less \
vim \
postgresql-client-$PG_VERSION \
nodejs \
yarn \
&& apt-get -q clean \
&& rm -rf /var/lib/apt/lists

WORKDIR /usr/src/app
ENV RAILS_ENV development

# Installing Ruby dependencies
COPY Gemfile* ./
RUN gem install bundler
RUN bundle install --jobs 20 --retry 5

# Install JavaScript dependencies
COPY yarn.lock ./
ENV YARN_INTEGRITY_ENABLED "false"
RUN yarn install && yarn check --integrity
ENV LANG=C.UTF-8 \
GEM_HOME=/bundle \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3
ENV BUNDLE_PATH $GEM_HOME
ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH \
BUNDLE_BIN=$BUNDLE_PATH/bin
ENV PATH $BUNDLE_BIN:$PATH

ENTRYPOINT ["bundle", "exec"]
ADD https://github.com/krallin/tini/releases/download/v0.18.0/tini /tini

This comment has been minimized.

Copy link
@maestromac

maestromac Jan 17, 2019

Collaborator

Tini's documentation stated that

NOTE: If you are using Docker 1.13 or greater, Tini is included in Docker itself. This includes all versions of Docker CE. To enable Tini, just pass the --init flag to docker run.

Does that apply here?

RUN chmod +x /tini

CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"]
WORKDIR /app
ENTRYPOINT ["/tini", "--"]
@@ -184,10 +184,17 @@ Our docker implementation is incomplete and may not work smoothly. Please kindly
1. `git clone git@github.com:thepracticaldev/dev.to.git`
1. Set environment variables above as described in the "Basic Installation"
1. run `docker-compose build`
1. run `docker-compose run web rails db:setup`
1. run `docker-compose run web yarn install`
1. run `docker-compose up`
1. run `docker-compose run app ./bin/setup`
1. run `docker-compose up` to run all services (including jobs) or `docker-compose up web webpacker` for run only web.
1. That's it! Navigate to `localhost:3000`
run `docker-compose run app something` to run rake tasks, rubocop etc, g.e.: `docker-compose run app bundle exec rubocop` or `docker-compose run app bundle exec rails db`

Run tests with docker:

```
RAILS_ENV=test docker-compose run app bundle exec rake db:test:prepare
RAILS_ENV=test docker-compose run app bundle exec rspec
```

#### Starting the application

@@ -36,7 +36,4 @@ chdir APP_ROOT do

puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"

puts "\n== Restarting application server =="
system! "bin/rails restart"
end
@@ -1,29 +1,57 @@
version: "3"
services:
web: &rails_base
app: &app
build:
dockerfile: Dockerfile
dockerfile: ./Dockerfile
context: .
ports:
- "3000:3000"
depends_on:
- db
environment:
RAILS_ENV: development
DATABASE_URL: postgres://postgres:mysecretpassword@db:5432/postgres
YARN_INTEGRITY_ENABLED: "false"
RAILS_ENV: ${RAILS_ENV:-development}
DATABASE_URL: postgres://postgres:mysecretpassword@db:5432/devto_${RAILS_ENV:-development}
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: "true"
WEBPACKER_DEV_SERVER_HOST: webpacker

volumes:
- .:/usr/src/app
- .:/app:cached
- bundle:/bundle
- node_modules:/app/node_modules
- assets:/app/public/assets
- packs:/app/public/packs
- packs_test:/app/public/packs-test

web:
<<: *app
ports:
- "3000:3000"
command: bundle exec rails server -b 0.0.0.0 -p 3000

jobs:
ports: []
<<: *rails_base
<<: *app
command: rails jobs:work

webpacker:
ports: []
<<: *rails_base
ports:
- '3035:3035'
<<: *app
environment:
- NODE_ENV=development
- RAILS_ENV=${RAILS_ENV:-development}
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
command: ./bin/webpack-dev-server

db:
image: postgres
volumes:
- postgres:/var/lib/postgresql/data
ports:
- "5432:5432"

volumes:
bundle:
postgres:
node_modules:
assets:
packs:
packs_test:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.