plastic_rails 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +22 -0
- data/README.md +24 -7
- data/lib/plastic_rails.rb +32 -5
- data/lib/plastic_rails/version.rb +1 -1
- data/{tmpl/apps/.keep → lib/tmpl/init/Gemfile.lock} +0 -0
- data/plastic_rails.gemspec +4 -17
- metadata +17 -23
- data/tmpl/Dockerfile +0 -37
- data/tmpl/build.sh +0 -20
- data/tmpl/docker-compose.yml +0 -28
- data/tmpl/init/Gemfile +0 -2
- data/tmpl/init/application_template/template.rb +0 -12
- data/tmpl/init/application_template/template/config/database.yml +0 -54
- data/tmpl/setup.sh +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90f7872cb0a90ce249ef6032210d9ef6e9dd0a4fd4db2b451c4a4c95447d0d68
|
4
|
+
data.tar.gz: 98304d1e9bddeae78bf548697aac75804f5b6841443e8b7d450b48cfaff2f7b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aff574d76f5ba7c0fa36cc8a29f01d6d5b64cd9dc48bbd18060fee392f78f65851ec71044e5ec892804322e75530fa6b7ac34aeb05b9025795f5261f51845b10
|
7
|
+
data.tar.gz: 04df7a51737a3d1f6b16290b0e01ba223ed8e80868fa3a687c1fb83a4319086c543161cd079ff7a2b45a1410fbd8c0c4be6c438b848e7ffb261b797ab9953c6b
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
plastic_rails (0.1.4)
|
5
|
+
thor (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
rake (13.0.1)
|
11
|
+
thor (1.0.1)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 2.1)
|
18
|
+
plastic_rails!
|
19
|
+
rake (~> 13.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# Plastic Rails
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/plastic_rails.svg)](https://badge.fury.io/rb/plastic_rails)
|
3
|
+
|
4
|
+
|
2
5
|
docker上にRuby on Railsの環境を一発で作るスクリプト
|
3
6
|
|
4
7
|
プラレールのように自分用のレールを引こう
|
5
8
|
|
9
|
+
|
6
10
|
## Requirements
|
7
11
|
- Docker
|
8
12
|
- Docker Compose
|
@@ -20,20 +24,33 @@ gem install plastic_rails
|
|
20
24
|
- rails new済のDockerコンテナを作成する
|
21
25
|
- `plastic_rails new <APP_NAME>`
|
22
26
|
- コンテナのシェルにログインする
|
23
|
-
- `cd <APP_NAME>;
|
27
|
+
- `cd <APP_NAME>; plastic_rails login; `
|
24
28
|
- コンテナ上でRails serverを起動する
|
25
29
|
- `rails s -b 0.0.0.0`
|
26
30
|
|
27
31
|
## 環境の操作
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
- `
|
32
|
-
-
|
33
|
-
- `
|
32
|
+
環境を作成した後は以下のコマンドで環境を操作する。(<APP_NAME>ディレクトリで実行する)
|
33
|
+
|
34
|
+
- コンテナ停止
|
35
|
+
- `plastic_rails stop`
|
36
|
+
- コンテナ削除
|
37
|
+
- `plastic_rails down`
|
38
|
+
- コンテナ起動
|
39
|
+
- `plastic_rails up`
|
34
40
|
- 削除したコンテナを再セットアップ
|
35
41
|
- `./setup.sh`
|
36
42
|
|
43
|
+
## カスタマイズ
|
44
|
+
DockerfileやRailsのテンプレートを修正することによって、作成する環境をカスタマイズできる。DBをデフォルトのMySQLから別のものに変更することなどが可能。
|
45
|
+
|
46
|
+
- デフォルトのテンプレートをコピー
|
47
|
+
- `plastic_rails copy_template <NEW_TEMPLATE>`
|
48
|
+
- <NEW_TEMPLATE> に デフォルトのテンプレート(DockerfileやRailsのアプリケーションテンプレート)が入ったディレクトリがコピーされる。
|
49
|
+
- テンプレートを修正する
|
50
|
+
- 修正したテンプレートを使用して環境を作成する
|
51
|
+
- `plastic_rails new <APP_NAME> --template=<NEW_TEMPLATE>`
|
52
|
+
|
53
|
+
|
37
54
|
## Plastic Rails自体の開発・デバッグ
|
38
55
|
### デバッグ環境(Vagrant)作成
|
39
56
|
- あらかじめ、VirtualboxとVagrantをインストールしておく。
|
data/lib/plastic_rails.rb
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
require "thor"
|
2
2
|
require "plastic_rails/version"
|
3
3
|
require "plastic_rails/fileutils"
|
4
|
+
THOR_SILENCE_DEPRECATION = true
|
4
5
|
|
5
6
|
module PlasticRails
|
6
7
|
class Error < StandardError; end
|
7
8
|
|
8
9
|
class PlaRails < Thor
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
DEFAULT_TEMPLATE_DIR = File.join(File.dirname(__FILE__) , "tmpl")
|
11
|
+
|
12
|
+
def self.exit_on_failure?
|
13
|
+
# コマンドが失敗したときに終了ステータス1を返すようにする設定
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "new [APPNAME]", "Create a Rails application skelton with Docker container."
|
12
18
|
option :db_path, :default => "./db/mysql/volumes"
|
19
|
+
option :template, :default => DEFAULT_TEMPLATE_DIR
|
13
20
|
def new(appname)
|
14
|
-
execute("cp -a #{
|
21
|
+
execute("cp -a #{options[:template]} #{appname}")
|
15
22
|
Dir.chdir(appname)
|
16
23
|
|
17
24
|
# DBのファイルパスを設定する
|
@@ -27,11 +34,31 @@ module PlasticRails
|
|
27
34
|
system("./setup.sh")
|
28
35
|
end
|
29
36
|
|
30
|
-
desc "login", "
|
37
|
+
desc "login", "Log in Rails container related to current directory."
|
31
38
|
def login
|
32
39
|
execute("docker-compose exec web bash")
|
33
40
|
end
|
34
41
|
|
42
|
+
desc "up", "Start up Rails container related to current directory."
|
43
|
+
def up
|
44
|
+
execute("docker-compose up -d")
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "stop", "Stop Rails container related to current directory."
|
48
|
+
def stop
|
49
|
+
execute("docker-compose stop")
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "down", "Stop and remove Rails container related to current directory."
|
53
|
+
def down
|
54
|
+
execute("docker-compose down")
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "copy_template [DEST_DIR]", "Copy the default template to any dir. (To use in `new` command with `--template` option.)"
|
58
|
+
def copy_template(dest_dir)
|
59
|
+
execute("cp -a #{DEFAULT_TEMPLATE_DIR} #{dest_dir}")
|
60
|
+
end
|
61
|
+
|
35
62
|
private
|
36
63
|
|
37
64
|
def execute(cmd)
|
File without changes
|
data/plastic_rails.gemspec
CHANGED
@@ -10,23 +10,10 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["gohannnotomo@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{docker上にRuby on Railsの環境を一発で作るスクリプト}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{docker上にRuby on Railsの環境を一発で作るスクリプト。プラレールのように自分用のレールを引こう。}
|
14
14
|
spec.homepage = "http://github.com/koki-h/plastic_rails"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
#
|
22
|
-
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
-
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
24
|
-
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
-
# else
|
26
|
-
# raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
-
# "public gem pushes."
|
28
|
-
# end
|
29
|
-
|
30
17
|
# Specify which files should be added to the gem when it is released.
|
31
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
19
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
@@ -36,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
36
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
24
|
spec.require_paths = ["lib"]
|
38
25
|
|
39
|
-
spec.add_development_dependency "bundler"
|
40
|
-
spec.add_development_dependency "rake"
|
41
|
-
spec.add_runtime_dependency "thor"
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
27
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
28
|
+
spec.add_runtime_dependency "thor", "~> 1.0"
|
42
29
|
end
|
metadata
CHANGED
@@ -1,58 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plastic_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koki Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '1.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
description:
|
54
|
+
version: '1.0'
|
55
|
+
description: docker上にRuby on Railsの環境を一発で作るスクリプト。プラレールのように自分用のレールを引こう。
|
56
56
|
email:
|
57
57
|
- gohannnotomo@gmail.com
|
58
58
|
executables:
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- CODE_OF_CONDUCT.md
|
65
65
|
- Gemfile
|
66
|
+
- Gemfile.lock
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
68
69
|
- Rakefile
|
@@ -77,18 +78,11 @@ files:
|
|
77
78
|
- lib/tmpl/build.sh
|
78
79
|
- lib/tmpl/docker-compose.yml
|
79
80
|
- lib/tmpl/init/Gemfile
|
81
|
+
- lib/tmpl/init/Gemfile.lock
|
80
82
|
- lib/tmpl/init/application_template/template.rb
|
81
83
|
- lib/tmpl/init/application_template/template/config/database.yml
|
82
84
|
- lib/tmpl/setup.sh
|
83
85
|
- plastic_rails.gemspec
|
84
|
-
- tmpl/Dockerfile
|
85
|
-
- tmpl/apps/.keep
|
86
|
-
- tmpl/build.sh
|
87
|
-
- tmpl/docker-compose.yml
|
88
|
-
- tmpl/init/Gemfile
|
89
|
-
- tmpl/init/application_template/template.rb
|
90
|
-
- tmpl/init/application_template/template/config/database.yml
|
91
|
-
- tmpl/setup.sh
|
92
86
|
homepage: http://github.com/koki-h/plastic_rails
|
93
87
|
licenses:
|
94
88
|
- MIT
|
data/tmpl/Dockerfile
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
FROM ruby:2.6.5-alpine3.9
|
2
|
-
|
3
|
-
RUN apk update
|
4
|
-
RUN apk upgrade
|
5
|
-
|
6
|
-
RUN apk add --no-cache \
|
7
|
-
bash git vim openssh openssl yarn sudo su-exec shadow tzdata \
|
8
|
-
mysql-client mysql-dev\
|
9
|
-
build-base libxml2-dev libxslt-dev
|
10
|
-
|
11
|
-
ARG UID=1000
|
12
|
-
ARG GID=1000
|
13
|
-
|
14
|
-
RUN mkdir /var/mail
|
15
|
-
RUN groupadd -g $GID devel
|
16
|
-
RUN useradd -u $UID -g devel -m devel
|
17
|
-
RUN echo "devel ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
18
|
-
|
19
|
-
# install rails
|
20
|
-
WORKDIR /tmp
|
21
|
-
COPY init/Gemfile /tmp/Gemfile
|
22
|
-
COPY init/Gemfile.lock /tmp/Gemfile.lock
|
23
|
-
RUN bundle install
|
24
|
-
|
25
|
-
COPY ./apps /apps
|
26
|
-
|
27
|
-
RUN apk add --no-cache openssl
|
28
|
-
|
29
|
-
WORKDIR /apps
|
30
|
-
|
31
|
-
USER devel
|
32
|
-
|
33
|
-
RUN openssl rand -hex 64 > /home/devel/.secret_key_base
|
34
|
-
RUN echo $'export SECRET_KEY_BASE=$(cat /home/devel/.secret_key_base)' \
|
35
|
-
>> /home/devel/.bashrc
|
36
|
-
|
37
|
-
COPY init/application_template/ /tmp/application_template/
|
data/tmpl/build.sh
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -eu
|
3
|
-
APPNAME=$1
|
4
|
-
BUILD_CMD="docker-compose build --no-cache --build-arg APPNAME=$APPNAME"
|
5
|
-
RUN_ON_WEB_CMD="docker-compose run --rm web"
|
6
|
-
OSTYPE=$(uname)
|
7
|
-
|
8
|
-
case "$OSTYPE" in
|
9
|
-
Darwin*)
|
10
|
-
$BUILD_CMD web
|
11
|
-
;;
|
12
|
-
Linux*)
|
13
|
-
$BUILD_CMD --build-arg UID=$(id -u) --build-arg GID=$(id -g) web
|
14
|
-
;;
|
15
|
-
*)
|
16
|
-
echo "Unknown OS Type: $OSTYPE"
|
17
|
-
;;
|
18
|
-
esac
|
19
|
-
|
20
|
-
$RUN_ON_WEB_CMD rails new $APPNAME --database=mysql --skip-bundle --skip-webpack-install -m /tmp/application_template/template.rb
|
data/tmpl/docker-compose.yml
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
version: '3'
|
2
|
-
services:
|
3
|
-
db:
|
4
|
-
image: mysql:5.7
|
5
|
-
environment:
|
6
|
-
MYSQL_USER: root
|
7
|
-
MYSQL_ROOT_PASSWORD: password
|
8
|
-
ports:
|
9
|
-
- '3316:3306'
|
10
|
-
volumes:
|
11
|
-
- %DB_PATH%:/var/lib/mysql
|
12
|
-
|
13
|
-
web:
|
14
|
-
build: .
|
15
|
-
command: /bin/sh
|
16
|
-
environment:
|
17
|
-
WEBPACKER_DEV_SERVER_HOST: "0.0.0.0"
|
18
|
-
RAILS_SERVE_STATIC_FILES: "1"
|
19
|
-
EDITOR: "vim"
|
20
|
-
volumes:
|
21
|
-
- ./apps:/apps
|
22
|
-
ports:
|
23
|
-
- "3000:3000"
|
24
|
-
- "3035:3035"
|
25
|
-
depends_on:
|
26
|
-
- db
|
27
|
-
tty: true
|
28
|
-
working_dir: /apps/
|
data/tmpl/init/Gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
@app_name = app_name
|
2
|
-
def source_paths
|
3
|
-
["#{__dir__}/template"]
|
4
|
-
end
|
5
|
-
|
6
|
-
# Database
|
7
|
-
inside 'config' do
|
8
|
-
remove_file "database.yml"
|
9
|
-
copy_file "database.yml"
|
10
|
-
gsub_file 'database.yml', /%APPNAME%/, @app_name
|
11
|
-
gsub_file 'database.yml', /%APPNAME_UPPERCASE%/, @app_name.upcase
|
12
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# MySQL. Versions 5.5.8 and up are supported.
|
2
|
-
#
|
3
|
-
# Install the MySQL driver
|
4
|
-
# gem install mysql2
|
5
|
-
#
|
6
|
-
# Ensure the MySQL gem is defined in your Gemfile
|
7
|
-
# gem 'mysql2'
|
8
|
-
#
|
9
|
-
# And be sure to use new-style password hashing:
|
10
|
-
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
|
11
|
-
#
|
12
|
-
default: &default
|
13
|
-
adapter: mysql2
|
14
|
-
encoding: utf8mb4
|
15
|
-
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
16
|
-
username: root
|
17
|
-
password: password
|
18
|
-
host: db
|
19
|
-
|
20
|
-
development:
|
21
|
-
<<: *default
|
22
|
-
database: %APPNAME%_development
|
23
|
-
|
24
|
-
# Warning: The database defined as "test" will be erased and
|
25
|
-
# re-generated from your development database when you run "rake".
|
26
|
-
# Do not set this db to the same as development or production.
|
27
|
-
test:
|
28
|
-
<<: *default
|
29
|
-
database: %APPNAME%_test
|
30
|
-
|
31
|
-
# As with config/credentials.yml, you never want to store sensitive information,
|
32
|
-
# like your database password, in your source code. If your source code is
|
33
|
-
# ever seen by anyone, they now have access to your database.
|
34
|
-
#
|
35
|
-
# Instead, provide the password as a unix environment variable when you boot
|
36
|
-
# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
37
|
-
# for a full rundown on how to provide these environment variables in a
|
38
|
-
# production deployment.
|
39
|
-
#
|
40
|
-
# On Heroku and other platform providers, you may have a full connection URL
|
41
|
-
# available as an environment variable. For example:
|
42
|
-
#
|
43
|
-
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
|
44
|
-
#
|
45
|
-
# You can use this database configuration with:
|
46
|
-
#
|
47
|
-
# production:
|
48
|
-
# url: <%= ENV['DATABASE_URL'] %>
|
49
|
-
#
|
50
|
-
production:
|
51
|
-
<<: *default
|
52
|
-
database: %APPNAME%_production
|
53
|
-
username: %APPNAME%
|
54
|
-
password: <%= ENV['%APPNAME_UPPERCASE%_DATABASE_PASSWORD'] %>
|
data/tmpl/setup.sh
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -eu
|
3
|
-
ESC="\e["
|
4
|
-
ESCEND=m
|
5
|
-
COLOR_OFF=$(printf ${ESC}${ESCEND})
|
6
|
-
COLOR_CMD=$(printf "${ESC}36;1;${ESCEND}") # front: cyan;bold
|
7
|
-
RUN_ON_WEB_CMD="docker-compose exec web"
|
8
|
-
#RUN_ON_WEB_CMD="docker-compose run --rm web"
|
9
|
-
function docker_run {
|
10
|
-
cmd=$1
|
11
|
-
echo ${COLOR_CMD}${cmd}${COLOR_OFF}
|
12
|
-
$RUN_ON_WEB_CMD $cmd
|
13
|
-
}
|
14
|
-
docker-compose up -d
|
15
|
-
docker_run "bundle install "
|
16
|
-
docker_run "yarn install --check-files"
|
17
|
-
docker_run "yarn upgrade"
|
18
|
-
docker_run "rails webpacker:install"
|
19
|
-
docker_run "rails db:setup"
|