Skip to content
Permalink
Browse files

examples: add docker env config

  • Loading branch information...
palkan committed Jul 11, 2019
1 parent f16c401 commit 1ff4a7756262da4ca41b2c4ce6adbdc614a622aa
@@ -56,6 +56,7 @@ They're not universal enough to be extracted into libraries (some depend on part
## Examples

- [CircleCI](./examples/circleci) — example CircleCI configuration files
- [Docker for Dev](./examples/dockerdev) — example Docker for development configuration

## Resources/Guides

@@ -0,0 +1,26 @@
-- Don't display the "helpful" message on startup.
\set QUIET 1

-- Allow specifying the path to history file via `PSQL_HISTFILE` env variable
-- (and fallback to the defaukt $HOME/.psql_history otherwise)
\set HISTFILE `[[ -z $PSQL_HISTFILE ]] && echo $HOME/.psql_history || echo $PSQL_HISTFILE`

-- 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
@@ -0,0 +1 @@
vim
@@ -0,0 +1,50 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION

ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG YARN_VERSION

# Add PostgreSQL to sources list
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

# Add NodeJS to sources list
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -

# Add Yarn to the sources list
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

# Install dependencies
COPY .dockerdev/Aptfile /tmp/Aptfile
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 \
$(cat /tmp/Aptfile | xargs) && \
apt-get clean && \
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

# Upgrade RubyGems and install required Bundler version
RUN gem update --system && \
gem install bundler:$BUNDLER_VERSION

# Create a directory for the app code
RUN mkdir -p /app

WORKDIR /app
@@ -0,0 +1,3 @@
# Docker for development setup

TBD
@@ -0,0 +1,55 @@
version: '2'

environment:
RAILS_ENV: development

compose:
files:
- docker-compose.yml

interaction:
bash:
service: backend
command: /bin/bash
compose_run_options: [no-deps]

bundle:
service: backend
command: bundle
compose_run_options: [no-deps]

rake:
service: backend
command: bundle exec rake

rails:
service: backend
command: bundle exec rails
subcommands:
s:
service: rails
compose_run_options: [service-ports]

rspec:
service: backend
environment:
RAILS_ENV: test
command: bundle exec rspec

rubocop:
service: backend
command: bundle exec rubocop
compose_run_options: [no-deps]

psql:
service: postgres
command: psql -h postgres -U postgres -d example_app_dev

'redis-cli':
service: redis
command: redis-cli -h redis

provision:
- dip compose down --volumes
- dip compose up -d postgres redis
- dip bash -c ./bin/setup
@@ -0,0 +1,100 @@
version: '3.4'

services:
app: &app
build:
context: .
dockerfile: ./.dockerdev/Dockerfile
args:
RUBY_VERSION: '2.6.3'
PG_MAJOR: '11'
NODE_MAJOR: '11'
YARN_VERSION: '1.13.0'
BUNDLER_VERSION: '2.0.2'
image: example-dev:1.0.0
tmpfs:
- /tmp

backend: &backend
<<: *app
stdin_open: true
tty: true
volumes:
- .:/app:cached
- rails_cache:/app/tmp/cache
- bundle:/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
- .dockerdev/.psqlrc:/root/.psqlrc:ro
environment:
- NODE_ENV=development
- RAILS_ENV=${RAILS_ENV:-development}
- REDIS_URL=redis://redis:6379/
- DATABASE_URL=postgres://postgres:postgres@postgres:5432
- BOOTSNAP_CACHE_DIR=/bundle/bootsnap
- WEBPACKER_DEV_SERVER_HOST=webpacker
- WEB_CONCURRENCY=1
- HISTFILE=/app/log/.bash_history
- PSQL_HISTFILE=/app/log/.psql_history
- EDITOR=vi
depends_on:
- postgres
- redis

runner:
<<: *backend
command: /bin/bash
ports:
- '3000:3000'
- '3002:3002'

rails:
<<: *backend
command: bundle exec rails server -b 0.0.0.0
ports:
- '3000:3000'

sidekiq:
<<: *backend
command: bundle exec sidekiq -C config/sidekiq.yml

postgres:
image: postgres:11.1
volumes:
- .psqlrc:/root/.psqlrc:ro
- postgres:/var/lib/postgresql/data
- ./log:/root/log:cached
environment:
- PSQL_HISTFILE=/root/log/.psql_history
ports:
- 5432

redis:
image: redis:3.2-alpine
volumes:
- redis:/data
ports:
- 6379

webpacker:
<<: *app
command: ./bin/webpack-dev-server
ports:
- '3035:3035'
volumes:
- .:/app:cached
- bundle:/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
environment:
- NODE_ENV=${NODE_ENV:-development}
- RAILS_ENV=${RAILS_ENV:-development}
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0

volumes:
postgres:
redis:
bundle:
node_modules:
rails_cache:
packs:

0 comments on commit 1ff4a77

Please sign in to comment.
You can’t perform that action at this time.