Skip to content

Instantly share code, notes, and snippets.

@palkan

palkan/dip.yml Secret

Last active August 28, 2023 11:27
Show Gist options
  • Save palkan/e0befcf3bcf3393f4db2090b2288a408 to your computer and use it in GitHub Desktop.
Save palkan/e0befcf3bcf3393f4db2090b2288a408 to your computer and use it in GitHub Desktop.
Reusable Docker development environment with Dip
version: '5.0'
compose:
files:
- ./.dip/docker-compose.base.yml
- ./.dip/docker-compose.databases.yml
- ./.dip/docker-compose.ruby.yml
- ./.dip/docker-compose.node.yml
- ./.dip/docker-compose.erlang.yml
project_name: shared_dip_env
interaction:
ruby: &ruby
description: Open Ruby service terminal
service: ruby
command: /bin/bash
subcommands:
server:
description: Open Ruby service terminal terminal with ports exposed (9292 -> 19292, 3000 -> 13000, 8080 -> 18080)
compose:
run_options: [service-ports]
jruby:
<<: *ruby
service: jruby
'ruby:latest':
<<: *ruby
service: ruby-latest
psql:
description: Run psql console
service: postgres
command: psql -h postgres -U postgres
createdb:
description: Run PostgreSQL createdb command
service: postgres
command: createdb -h postgres -U postgres
'redis-cli':
description: Run Redis console
service: redis
command: redis-cli -h redis
node:
description: Open Node service terminal
service: node'
command: /bin/bash
erl:
description: Open Erlang service terminal
service: erlang
command: /bin/bash
version: '2.4'
# Here we only declare a volume
volumes:
history:
version: '2.4'
services:
postgres:
image: postgres:11.7
volumes:
- history:/usr/local/hist
- ./.psqlrc:/root/.psqlrc:ro
- postgres:/var/lib/postgresql/data
environment:
PSQL_HISTFILE: /usr/local/hist/.psql_history
POSTGRES_PASSWORD: postgres
PGPASSWORD: postgres
ports:
- 5432
redis:
image: redis:5-alpine
volumes:
- redis:/data
ports:
- 6379
healthcheck:
test: redis-cli ping
interval: 1s
timeout: 3s
retries: 30
volumes:
postgres:
redis:
version: '2.4'
services:
erlang: &erlang
image: erlang:23
volumes:
- ${PWD}:/${PWD}:cached
- rebar_cache:/rebar_data
- history:/usr/local/hist
- ./.bashrc:/root/.bashrc:ro
environment:
REBAR_CACHE_DIR: /rebar_data/.cache
REBAR_GLOBAL_CONFIG_DIR: /rebar_data/.config
# That's an imortant trick: we want to keep all the deps
# and the compiled files in a volume for better performance.
# We use a unique folder for each project (based on the host path).
REBAR_BASE_DIR: /rebar_data/.project-cache${PWD}
HISTFILE: /usr/local/hist/.bash_history
PROMPT_DIRTRIM: 2
PS1: '[\W]\! '
working_dir: ${PWD}
tmpfs:
- /tmp
volumes:
rebar_cache:
version: '2.4'
services:
node: &node
image: node:14
volumes:
- ${PWD}:/${PWD}:cached
- npm_data:${NPM_CONFIG_PREFIX}
- history:/usr/local/hist
- ./.bashrc:/root/.bashrc:ro
environment:
NPM_CONFIG_PREFIX: ${NPM_CONFIG_PREFIX}
HISTFILE: /usr/local/hist/.bash_history
PROMPT_DIRTRIM: 2
PS1: '[\W]\! '
working_dir: ${PWD}
tmpfs:
- /tmp
# Install Docsify first:
# dip compose run node npm i docsify-cli -g
docsify:
<<: *node
working_dir: ${NPM_CONFIG_PREFIX}/bin
command: docsify serve ${PWD}/docs -p 5000 --livereload-port 55729
ports:
- 5000:5000
- 55729:55729
volumes:
npm_data:
version: '2.4'
services:
ruby: &ruby
command: bash
image: ruby:2.7
volumes:
# That's all the magic!
- ${PWD}:/${PWD}:cached
- bundler_data:/usr/local/bundle
- history:/usr/local/hist
# I also mount different configuration files
# for better DX
- ./.bashrc:/root/.bashrc:ro
- ./.irbrc:/root/.irbrc:ro
- ./.pryrc:/root/.pryrc:ro
environment:
DATABASE_URL: postgres://postgres:postgres@postgres:5432
REDIS_URL: redis://redis:6379/
HISTFILE: /usr/local/hist/.bash_history
LANG: C.UTF-8
PROMPT_DIRTRIM: 2
PS1: '[\W]\! '
# Plays nice with gemfiles/*.gemfile files for CI
BUNDLE_GEMFILE: ${BUNDLE_GEMFILE:-Gemfile}
# And that's the second part of the spell
working_dir: ${PWD}
ports:
- 19292:9292
- 13000:3000
- 18080:8080
tmpfs:
- /tmp
jruby:
<<: *ruby
image: jruby:latest
volumes:
- ${PWD}:/${PWD}:cached
- bundler_jruby:/usr/local/bundle
- history:/usr/local/hist
- ./.bashrc:/root/.bashrc:ro
- ./.irbrc:/root/.irbrc:ro
- ./.pryrc:/root/.pryrc:ro
ruby-latest:
<<: *ruby
image: rubocophq/ruby-snapshot:latest
volumes:
- ${PWD}:/${PWD}:cached
- bundler_data_edge:/usr/local/bundle
- history:/usr/local/hist
- ./.bashrc:/root/.bashrc:ro
- ./.irbrc:/root/.irbrc:ro
- ./.pryrc:/root/.pryrc:ro
volumes:
bundler_data:
bundler_jruby:
bundler_data_edge:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment