Skip to content

Instantly share code, notes, and snippets.

@artofhuman
Last active September 20, 2017 06:18
Show Gist options
  • Save artofhuman/3b250a619cfb4791f8a24fa6cc84d0b3 to your computer and use it in GitHub Desktop.
Save artofhuman/3b250a619cfb4791f8a24fa6cc84d0b3 to your computer and use it in GitHub Desktop.
Makefile for simplify usage Docker and Docker Compose for Rails app with webpack
version: '2.1'
services:
app:
build: '.'
image: project_app
command: 'bash'
environment:
- SSH_AUTH_SOCK=/ssh/auth/sock
volumes:
- '.:/app'
- ssh-data:/ssh:ro
- bundler-data:/usr/local/bundle
web:
extends:
service: app
command: 'bash -c "rm -f /var/run/rails.pid && bundle exec rails s -b 0.0.0.0 --pid /var/run/rails.pid"'
ports:
- '3000:3000'
- '3035:3035'
depends_on:
- pg
labels:
com.dnsdock.name: "ndb"
com.dnsdock.image: ""
pg:
image: 'postgres:9.6'
volumes:
- pg-data:/var/lib/postgresql/data
volumes:
pg-data:
driver: local
ssh-data:
external:
name: ssh_data
bundler-data:
external:
name: bundler_data
FROM ruby:2.4.1-slim
RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends \
apt-transport-https \
curl
RUN curl --silent --location https://deb.nodesource.com/setup_8.x | bash - && \
curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update -qq \
&& apt-get install -y --no-install-recommends \
nodejs \
yarn \
make \
gcc \
g++ \
locales \
pkg-config \
libxml2-dev \
libxslt-dev \
libcurl3-dev \
libpq-dev \
libgmp3-dev \
postgresql-client \
git-core \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& truncate -s 0 /var/log/*log
WORKDIR /app
RAILS_ENV ?= development
RUN := run --rm
DOCKER_COMPOSE_RUN := docker-compose $(RUN)
default: compose-test
test:
bundle exec rspec ${T}
deploy:
${DOCKER_COMPOSE_RUN} --no-deps app bundle exec cap production deploy
rollback:
${DOCKER_COMPOSE_RUN} --no-deps app bundle exec cap production deploy:rollback
compose-web:
${DOCKER_COMPOSE_RUN} --service-ports web
compose-db-prepare: compose-db-create compose-db-migrate
compose-db-create:
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=${RAILS_ENV}" web bundle exec rake db:create
compose-db-migrate:
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=development" web bundle exec rake db:migrate
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=test" web bundle exec rake db:migrate
compose-db-rollback:
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=development" web bundle exec rake db:rollback
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=test" web bundle exec rake db:rollback
compose-db-console:
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=${RAILS_ENV}" web bundle exec rails dbconsole
compose-rails-console:
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=${RAILS_ENV}" web bundle exec rails c
compose-bash:
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=${RAILS_ENV}" web bash
compose-down:
docker-compose down
compose-rails-generate:
${DOCKER_COMPOSE_RUN} web bundle exec rails g ${CMD}
compose-bundle:
${DOCKER_COMPOSE_RUN} web bundle ${CMD}
compose-test:
${DOCKER_COMPOSE_RUN} -e "RAILS_ENV=test" web bundle exec rspec ${T}
compose-build:
docker-compose build
compose-rebuild:
docker-compose build --force-rm --no-cache
.PHONY: test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment