plastic_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6da9466a21fafd8f0adf91a52a0cdc8a8c3292774a46e983963c47d39e9084f8
4
+ data.tar.gz: ad73731d007875b4e2ccf5df6f2a029e0457071cefadc29a749d570d7ac0806d
5
+ SHA512:
6
+ metadata.gz: 72062d13c60db678f6af2acd78e9d6cf9735590a35d0d86e11eb9552446700d84540140f12d8237e8da16505c4f332f05046f8b16a99449b68df6cbb250f49e5
7
+ data.tar.gz: 072b6fc02654c3476ce558723ede41157fc93a24c4a9342f224d1ff5de919cbd556a1efa91f2bd7bd1864231e45e604a3acecde713beebfb7efdafae87349b90
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .DS_Store
10
+ Gemfile.lock
11
+ .ruby-version
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at gohannnotomo@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in plastic_rails.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Koki Hashimoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Plastic Rails
2
+ docker上にRuby on Railsの環境を一発で作るスクリプト
3
+
4
+ プラレールのように自分用のレールを引こう
5
+
6
+ ## Requirements
7
+ - Docker
8
+ - Docker Compose
9
+ - ruby
10
+
11
+ ## install
12
+
13
+ ```
14
+ gem install plastic_rails
15
+ ```
16
+
17
+ ## 環境の作成
18
+ 以下の手順を実行すると http://localhost:3000 でrailsのテストページが表示できるようになる。
19
+
20
+ - rails new済のDockerコンテナを作成する
21
+ - `plastic_rails new <APP_NAME>`
22
+ - コンテナのシェルにログインする
23
+ - `cd <APP_NAME>; docker-compose exec web bash; `
24
+ - コンテナ上でRails serverを起動する
25
+ - `rails s -b 0.0.0.0`
26
+
27
+ ## 環境の操作
28
+ 環境を作成した後は以下のコマンドで環境を操作する。
29
+
30
+ - コンテナ停止(<APP_NAME>ディレクトリで)
31
+ - `docker-compose stop`
32
+ - コンテナ削除(<APP_NAME>ディレクトリで)
33
+ - `docker-compose down`
34
+ - 削除したコンテナを再セットアップ
35
+ - `./setup.sh`
36
+
37
+ ## Plastic Rails自体の開発・デバッグ
38
+ ### デバッグ環境(Vagrant)作成
39
+ - あらかじめ、VirtualboxとVagrantをインストールしておく。
40
+ - Vagrantfileをダウンロード
41
+ ```
42
+ curl https://gist.githubusercontent.com/koki-h/8a2990ac49f37124dc90523ef1e635ed/raw/c9cd49f79d1b27c12441a344dbd980ac71e9aacc/Vagrantfile > Vagrantfile
43
+ ```
44
+ - Virtualbox起動。最初からrequirementsが入ったVirtualboxができる
45
+ ```
46
+ $ vagrant up
47
+ ```
48
+ - `vagrant ssh` で virtualboxにログインし、適当なディレクトリで `git clone https://github.com/koki-h/plastic_rails.git` する。
49
+ - セットアップ実行
50
+ ```
51
+ $ cd plastic_rails
52
+ $ ./bin/setup
53
+ ```
54
+
55
+
56
+ ### Vagrant環境での実行方法
57
+ ```
58
+ $ plastic_rails new <APP_NAME> --db_path=<DB_PATH>
59
+ ```
60
+ Plastic RailsをVirtualboxの共有ディレクトリにインストールした場合は --db-path オプションでDBファイルのパスを共有ディレクトリ以外に指定する。(そうしないとパーミッションの関係でMySqlサーバが起動しない)
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/koki-h/plastic_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
+
76
+ ## Code of Conduct
77
+
78
+ Everyone interacting in the PlasticRails project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/koki-h/plastic_rails/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "plastic_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "plastic_rails"
4
+ PlasticRails::PlaRails.start(ARGV)
@@ -0,0 +1,42 @@
1
+ require "thor"
2
+ require "plastic_rails/version"
3
+ require "plastic_rails/fileutils"
4
+
5
+ module PlasticRails
6
+ class Error < StandardError; end
7
+
8
+ class PlaRails < Thor
9
+ TMPL_DIR=File.dirname(__FILE__)
10
+ p TMPL_DIR
11
+ desc "new APPNAME", "create a Rails application skelton with Docker container."
12
+ option :db_path, :default => "./db/mysql/volumes"
13
+ def new(appname)
14
+ execute("cp -a #{TMPL_DIR}/tmpl #{appname}")
15
+ Dir.chdir(appname)
16
+
17
+ # DBのファイルパスを設定する
18
+ FileUtils.sed("docker-compose.yml",/%DB_PATH%/,options[:db_path])
19
+
20
+ # Dockerイメージビルド&rails new (working_dirは `/apps`)
21
+ execute("./build.sh #{appname}")
22
+
23
+ # working_dirをrailsアプリのディレクトリに変更する
24
+ FileUtils.sed("docker-compose.yml",/(working_dir: \/apps\/)/,'\1' + appname)
25
+
26
+ # Railsアプリの設定(`bundle install`, `rails db:setup` など)
27
+ system("./setup.sh")
28
+ end
29
+
30
+ desc "login", "log in Rails container related to current directory."
31
+ def login
32
+ execute("docker-compose exec web bash")
33
+ end
34
+
35
+ private
36
+
37
+ def execute(cmd)
38
+ puts cmd
39
+ system(cmd)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ module FileUtils
2
+ def self.sed(file, pattern, replacement)
3
+ File.open(file, "r") do |f_in|
4
+ buf = f_in.read
5
+ buf.gsub!(pattern, replacement)
6
+ File.open(file, "w") do |f_out|
7
+ f_out.write(buf)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,3 @@
1
+ module PlasticRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
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/
File without changes
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,28 @@
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/
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rails', '~> 6.0.0'
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,54 @@
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'] %>
@@ -0,0 +1,19 @@
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"
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "plastic_rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "plastic_rails"
8
+ spec.version = PlasticRails::VERSION
9
+ spec.authors = ["Koki Hashimoto"]
10
+ spec.email = ["gohannnotomo@gmail.com"]
11
+
12
+ spec.summary = %q{docker上にRuby on Railsの環境を一発で作るスクリプト}
13
+ spec.description = %q{プラレールのように自分用のレールを引こう}
14
+ spec.homepage = "http://github.com/koki-h/plastic_rails"
15
+ spec.license = "MIT"
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
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler"
40
+ spec.add_development_dependency "rake"
41
+ spec.add_runtime_dependency "thor"
42
+ end
@@ -0,0 +1,37 @@
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/
File without changes
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,28 @@
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/
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rails', '~> 6.0.0'
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,54 @@
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'] %>
@@ -0,0 +1,19 @@
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"
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plastic_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Koki Hashimoto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: プラレールのように自分用のレールを引こう
56
+ email:
57
+ - gohannnotomo@gmail.com
58
+ executables:
59
+ - plastic_rails
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/plastic_rails
72
+ - lib/plastic_rails.rb
73
+ - lib/plastic_rails/fileutils.rb
74
+ - lib/plastic_rails/version.rb
75
+ - lib/tmpl/Dockerfile
76
+ - lib/tmpl/apps/.keep
77
+ - lib/tmpl/build.sh
78
+ - lib/tmpl/docker-compose.yml
79
+ - lib/tmpl/init/Gemfile
80
+ - lib/tmpl/init/application_template/template.rb
81
+ - lib/tmpl/init/application_template/template/config/database.yml
82
+ - lib/tmpl/setup.sh
83
+ - 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
+ homepage: http://github.com/koki-h/plastic_rails
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.1.4
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: docker上にRuby on Railsの環境を一発で作るスクリプト
115
+ test_files: []