Skip to content

Commit 45e7c0a

Browse files
committed
feat: Add ability to generate config files
1 parent 9719b49 commit 45e7c0a

File tree

5 files changed

+132
-1
lines changed

5 files changed

+132
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,24 @@ dip --help
8080
dip SUBCOMMAND --help
8181
```
8282

83-
### dip.yml
83+
### dip generate
84+
85+
If your project has a typical schema, dip can generate all necessary config files with a single command.
86+
Available generators you can find at [here](lib/dip/generators)
87+
88+
```sh
89+
dip generate ruby/gem --ruby 2.6 --bundler 2.0.2 --postgres 11.4
90+
91+
dip generate ruby/rails --ruby 2.6 --bundler 2.0.2 --node 11 --yarn 1.13.0 --postgres 11.4 --redis 4 --webpacker --selenium
92+
```
93+
94+
You can omit any of above options. To list all available generator's options:
95+
96+
```sh
97+
dip generate [STACK] --help
98+
```
99+
100+
### dip file reference
84101

85102
The configuration file `dip.yml` should be placed in a project root directory.
86103
Also, in some cases, you may want to change the default config path by providing an environment variable `DIP_FILE`.

lib/dip/cli.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ def provision
7878
end
7979
end
8080

81+
desc "generate STACK [OPTIONS]", "Generate config files for a given stack"
82+
def generate(stack, *argv)
83+
# TODO: Add ability to download stack from any github repository.
84+
require_relative "generators/#{stack}/generator.rb"
85+
86+
Dip::Generator.start(argv)
87+
end
88+
8189
require_relative 'cli/ssh'
8290
desc "ssh", "ssh-agent container commands"
8391
subcommand :ssh, Dip::CLI::SSH
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Dip
4+
class Generator < Thor::Group
5+
include Thor::Actions
6+
7+
class_option :ruby, default: "latest"
8+
class_option :postgres, default: false
9+
class_option :appraisal, default: false
10+
11+
def self.source_root
12+
File.join(__dir__, "templates")
13+
end
14+
15+
def create_docker_compose_config
16+
template("docker-compose.yml.tt", File.join("tmp", "docker-compose.yml"))
17+
end
18+
19+
def create_dip_config
20+
template("dip.yml.tt", File.join("tmp", "dip.yml"))
21+
end
22+
end
23+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: '2'
2+
3+
environment:
4+
BUNDLE_GEMFILE: /app/Gemfile
5+
6+
compose:
7+
files:
8+
- docker-compose.yml
9+
10+
interaction:
11+
app:
12+
service: app
13+
subcommands:
14+
bash:
15+
command: /usr/bin/bash
16+
console:
17+
command: ./bin/console
18+
clean:
19+
command: rm -rf Gemfile.lock<%= " gemfiles/*.gemfile.*" if options["appraisal"] %>
20+
21+
bundle:
22+
service: app
23+
command: bundle
24+
25+
<%- if options["appraisal"] -%>
26+
appraisal:
27+
service: app
28+
command: bundle exec appraisal
29+
30+
<%- end -%>
31+
rspec:
32+
service: app
33+
<%- if options["appraisal"] -%>
34+
command: bundle exec appraisal bundle exec rspec
35+
<%- else -%>
36+
command: bundle exec rspec
37+
<%- end -%>
38+
39+
rubocop:
40+
service: app
41+
command: bundle exec rubocop
42+
compose_run_options: [no-deps]
43+
44+
provision:
45+
- dip app clean
46+
- dip bundle install
47+
<%- if options["appraisal"] -%>
48+
- dip appraisal install
49+
<%- end -%>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: '3.4'
2+
3+
services:
4+
app:
5+
image: ruby:<%= options["ruby"] %>
6+
environment:
7+
BUNDLE_PATH: /bundle
8+
BUNDLE_CONFIG: /app/.bundle/config
9+
<%- if options["postgres"] -%>
10+
DB_HOST: db
11+
DB_NAME: docker
12+
DB_USERNAME: postgres
13+
<%- end -%>
14+
command: bash
15+
working_dir: /app
16+
volumes:
17+
- .:/app:cached
18+
- bundler_data:/bundle
19+
tmpfs:
20+
- /tmp
21+
<%- if options["postgres"] -%>
22+
depends_on:
23+
- db
24+
<%- end -%>
25+
26+
<%- if options["postgres"] -%>
27+
db:
28+
image: postgres:<%= options["postgres"] %>
29+
environment:
30+
- POSTGRES_DB=docker
31+
32+
<%- end -%>
33+
volumes:
34+
bundler_data:

0 commit comments

Comments
 (0)