-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from evilmartians/chore/docker
Docker for development
- Loading branch information
Showing
10 changed files
with
406 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- Don't display the "helpful" message on startup. | ||
\set QUIET 1 | ||
|
||
-- psql writes to a temporary file before then moving that temporary file on top of the old history file | ||
-- a bind mount of a file only bind mounts the inode, so a rename like this won't ever work | ||
\set HISTFILE /var/log/psql_history/.psql_history | ||
|
||
-- Show how long each query takes to execute | ||
\timing | ||
|
||
-- Use best available output format | ||
\x auto | ||
|
||
-- Verbose error reports | ||
\set VERBOSITY verbose | ||
|
||
-- If a command is run more than once in a row, | ||
-- only store it once in the history | ||
\set HISTCONTROL ignoredups | ||
\set COMP_KEYWORD_CASE upper | ||
|
||
-- By default, NULL displays as an empty space. Is it actually an empty | ||
-- string, or is it null? This makes that distinction visible | ||
\pset null '[NULL]' | ||
|
||
\unset QUIET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
Pry.config.history.should_save = true | ||
Pry.config.history.file = "#{__dir__}/log/.pry_history" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
ARG RUBY_VERSION | ||
FROM ruby:${RUBY_VERSION}-stretch | ||
|
||
ARG PG_MAJOR | ||
ARG NODE_MAJOR | ||
ARG BUNDLER_VERSION | ||
ARG YARN_VERSION | ||
|
||
# PG | ||
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_MAJOR} > /etc/apt/sources.list.d/pgdg.list | ||
|
||
# Node | ||
RUN curl -sL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash - | ||
|
||
# Yarn | ||
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ | ||
&& echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list | ||
|
||
# Other dependencies | ||
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ | ||
build-essential \ | ||
postgresql-client-${PG_MAJOR} \ | ||
nodejs \ | ||
yarn=${YARN_VERSION}-1 \ | ||
less \ | ||
vim && \ | ||
apt-get clean && \ | ||
rm -rf /var/cache/apt/archives/* && \ | ||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ | ||
truncate -s 0 /var/log/*log | ||
|
||
# Configure bundler and PATH | ||
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 /app/bin:$BUNDLE_BIN:$PATH | ||
|
||
RUN gem update --system && \ | ||
gem install bundler:${BUNDLER_VERSION} | ||
|
||
RUN mkdir -p /app | ||
|
||
WORKDIR /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
version: '4.1' | ||
|
||
interaction: | ||
bash: | ||
description: Open a Bash shell | ||
service: backend | ||
command: /bin/bash | ||
compose_run_options: [no-deps] | ||
|
||
bundle: | ||
description: Run Bundler commands | ||
service: backend | ||
command: bundle | ||
|
||
yarn: | ||
description: Run Yarn commands | ||
service: backend | ||
command: yarn | ||
|
||
rake: | ||
description: Run Rake commands | ||
service: backend | ||
command: bundle exec rake | ||
|
||
rails: | ||
description: Run Rails commands | ||
service: backend | ||
command: bundle exec rails | ||
subcommands: | ||
s: | ||
description: Run Rails server available at http://localhost:3000 | ||
service: rails | ||
compose: | ||
run_options: [service-ports, use-aliases] | ||
|
||
sidekiq: | ||
description: Run Sidekiq worker | ||
service: backend | ||
command: bundle exec sidekiq | ||
|
||
rspec: | ||
description: Run RSpec commands within test environment | ||
service: backend | ||
environment: | ||
RAILS_ENV: test | ||
command: bundle exec rspec | ||
|
||
rubocop: | ||
description: Lint ruby files | ||
service: backend | ||
command: bundle exec rubocop | ||
compose: | ||
run_options: [no-deps] | ||
|
||
psql: | ||
description: Open a Postgres console | ||
service: postgres | ||
default_args: evil_chat_development | ||
command: psql -h postgres -U postgres | ||
|
||
'redis-cli': | ||
description: Open a Redis console | ||
service: redis | ||
command: redis-cli -h redis | ||
|
||
provision: | ||
- dip compose down --volumes | ||
- dip compose up -d postgres redis | ||
- dip bash -c "./bin/setup" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
version: '3.4' | ||
|
||
services: | ||
app: &app | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile | ||
args: | ||
RUBY_VERSION: '2.6' | ||
PG_MAJOR: '10' | ||
NODE_MAJOR: '11' | ||
BUNDLER_VERSION: '2.0.2' | ||
YARN_VERSION: '1.19.1' | ||
image: brainwashing-dev:1.0.0 | ||
volumes: | ||
- .:/app:cached | ||
tmpfs: | ||
- /tmp | ||
|
||
backend: &backend | ||
<<: *app | ||
stdin_open: true | ||
tty: true | ||
command: /bin/bash | ||
volumes: | ||
- .:/app:cached | ||
# We store Rails cache and gems in volumes to get speed up on Docker for Mac | ||
- rails_cache:/app/tmp/cache | ||
- bundle:/bundle | ||
environment: | ||
HISTFILE: /app/log/.bash_history | ||
MALLOC_ARENA_MAX: 2 | ||
WEB_CONCURRENCY: 1 | ||
EDITOR: vim | ||
RAILS_ENV: ${RAILS_ENV:-development} | ||
DATABASE_URL: postgres://postgres:postgres@postgres:5432 | ||
REDIS_URL: redis://redis:6379/ | ||
WEBPACKER_DEV_SERVER_HOST: webpacker | ||
DISABLE_SPRING: 1 | ||
depends_on: | ||
- postgres | ||
- redis | ||
|
||
rails: | ||
<<: *backend | ||
command: bundle exec rails server -b 0.0.0.0 | ||
ports: | ||
- '3000:3000' | ||
depends_on: | ||
- postgres | ||
- redis | ||
- webpacker | ||
|
||
webpacker: | ||
<<: *app | ||
command: ./bin/webpack-dev-server | ||
ports: | ||
- '3035:3035' | ||
volumes: | ||
- .:/app:cached | ||
- bundle:/bundle | ||
environment: | ||
NODE_ENV: development | ||
RAILS_ENV: ${RAILS_ENV:-development} | ||
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0 | ||
|
||
postgres: | ||
image: postgres:12 | ||
volumes: | ||
- postgres:/var/lib/postgresql/data | ||
- .docker/.psqlrc:/root/.psqlrc:ro | ||
- ./log:/var/log/psql_history | ||
ports: | ||
- 5432 | ||
|
||
redis: | ||
image: redis:4 | ||
volumes: | ||
- redis:/data | ||
ports: | ||
- 6379 | ||
|
||
volumes: | ||
bundle: | ||
postgres: | ||
redis: | ||
rails_cache: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Docker on Dip Development Configuration | ||
|
||
We have development [Docker configuration]((./docker.md). | ||
|
||
In addition to it you can also use [`dip`](https://github.com/bibendi/dip) – CLI that gives the "native" interaction with applications configured with Docker Compose. It is for the local development only. In practice, it creates the feeling that you work without containers. | ||
|
||
To install `dip` copy and run the command below: | ||
|
||
```sh | ||
gem install dip | ||
``` | ||
|
||
or | ||
|
||
```sh | ||
brew install bibendi/dip/dip | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
# list available commands | ||
dip ls | ||
|
||
# provision application | ||
dip provision | ||
|
||
# run web app with all debuging capabilities (i.e. `binding.pry`) | ||
dip rails s | ||
|
||
# run rails console | ||
dip rails c | ||
|
||
# run migrations | ||
dip rake db:migrate | ||
|
||
# pass env variables into application | ||
dip VERSION=20100905201547 rake db:migrate:down | ||
|
||
# simply launch bash within app directory | ||
dip bash | ||
|
||
# Additional commands | ||
|
||
# update gems or packages | ||
dip bundle install | ||
|
||
# run psql console | ||
dip psql | ||
|
||
# run redis console | ||
dip redis-cli | ||
|
||
# run tests | ||
dip rspec spec/path/to/single/test.rb:23 | ||
|
||
# shutdown all containers | ||
dip down | ||
``` | ||
|
||
Dip can be easily integrated into ZSH (especially if used `agnostic` theme) or Bash shell. | ||
So, there is allow us using all above commands without `dip` prefix. And it looks like we are not using Docker at all (really that's not true). | ||
|
||
```sh | ||
eval "$(dip console)" | ||
|
||
rails c | ||
rails s | ||
rspec spec/test_spec.rb:23 | ||
psql evilmartians_development | ||
VERSION=20100905201547 rake db:migrate:down | ||
rake routes | grep blog | ||
``` | ||
|
||
But after we get out to somewhere from the project's directory, then all Dip's aliases will be cleared. And if we get back, then Dip's aliases would be restored. |
Oops, something went wrong.