Skip to content

Commit

Permalink
Merge pull request #1 from hrk-m/feature/init-setting
Browse files Browse the repository at this point in the history
Rails 7 (api モード)+MySQL 8.0.16のDocker環境を構築
  • Loading branch information
hrk-m committed Apr 7, 2023
2 parents 6adecc0 + 6783c40 commit 179a0bd
Show file tree
Hide file tree
Showing 51 changed files with 961 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
@@ -0,0 +1,6 @@
/log/*
!/log/.keep
/tmp
/.bundle
/vendor
/_opt
4 changes: 4 additions & 0 deletions .envrc.sample
@@ -0,0 +1,4 @@
# MySQL
export DATABASE_USERNAME='root'
export DATABASE_PASSWORD='pass'
export DATABASE_HOST='mysql'
7 changes: 7 additions & 0 deletions .gitattributes
@@ -0,0 +1,7 @@
# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
32 changes: 32 additions & 0 deletions .gitignore
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

# Ignore master key for decrypting credentials and more.
/config/master.key

# 環境設定
.envrc
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
ruby-3.1.2
28 changes: 28 additions & 0 deletions Dockerfile
@@ -0,0 +1,28 @@
FROM ruby:3.1.2

ENV TZ Asia/Tokyo
ENV APP_ROOT /usr/src/app
ENV BUILD_PACKAGES="vim mariadb-client"

WORKDIR $APP_ROOT

RUN \
apt-get update -qq && apt-get install -y $BUILD_PACKAGES --no-install-recommends && \
apt-get clean && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* /tmp/* /var/tmp/*

COPY Gemfile $APP_ROOT/
COPY Gemfile.lock $APP_ROOT/
RUN \
echo 'gem: --no-document' >> ~/.gemrc && \
cp ~/.gemrc /etc/gemrc && \
chmod uog+r /etc/gemrc && \
bundle config build.nokogiri --use-system-libraries && \
bundle config jobs 4 && \
bundle install && \
rm -rf ~/.gem

COPY . $APP_ROOT/

EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]
48 changes: 48 additions & 0 deletions Gemfile
@@ -0,0 +1,48 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.2"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4"

# Use mysql as the database for Active Record
gem "mysql2", "~> 0.5"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem "rack-cors"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

169 changes: 169 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,169 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.4)
actionpack (= 7.0.4)
activesupport (= 7.0.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.4)
actionpack (= 7.0.4)
activejob (= 7.0.4)
activerecord (= 7.0.4)
activestorage (= 7.0.4)
activesupport (= 7.0.4)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.4)
actionpack (= 7.0.4)
actionview (= 7.0.4)
activejob (= 7.0.4)
activesupport (= 7.0.4)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.4)
actionview (= 7.0.4)
activesupport (= 7.0.4)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.4)
actionpack (= 7.0.4)
activerecord (= 7.0.4)
activestorage (= 7.0.4)
activesupport (= 7.0.4)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.4)
activesupport (= 7.0.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.4)
activesupport (= 7.0.4)
globalid (>= 0.3.6)
activemodel (7.0.4)
activesupport (= 7.0.4)
activerecord (7.0.4)
activemodel (= 7.0.4)
activesupport (= 7.0.4)
activestorage (7.0.4)
actionpack (= 7.0.4)
activejob (= 7.0.4)
activerecord (= 7.0.4)
activesupport (= 7.0.4)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
bootsnap (1.15.0)
msgpack (~> 1.2)
builder (3.2.4)
concurrent-ruby (1.1.10)
crass (1.0.6)
debug (1.7.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
erubi (1.11.0)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
io-console (0.5.11)
irb (1.5.1)
reline (>= 0.3.0)
loofah (2.19.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.8.0)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.16.3)
msgpack (1.6.0)
mysql2 (0.5.4)
net-imap (0.3.1)
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.13.10-x86_64-linux)
racc (~> 1.4)
puma (5.6.5)
nio4r (~> 2.0)
racc (1.6.1)
rack (2.2.4)
rack-test (2.0.2)
rack (>= 1.3)
rails (7.0.4)
actioncable (= 7.0.4)
actionmailbox (= 7.0.4)
actionmailer (= 7.0.4)
actionpack (= 7.0.4)
actiontext (= 7.0.4)
actionview (= 7.0.4)
activejob (= 7.0.4)
activemodel (= 7.0.4)
activerecord (= 7.0.4)
activestorage (= 7.0.4)
activesupport (= 7.0.4)
bundler (>= 1.15.0)
railties (= 7.0.4)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
railties (7.0.4)
actionpack (= 7.0.4)
activesupport (= 7.0.4)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
reline (0.3.1)
io-console (~> 0.5)
thor (1.2.1)
timeout (0.3.1)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.6)

PLATFORMS
x86_64-linux

DEPENDENCIES
bootsnap
debug
mysql2 (~> 0.5)
puma (~> 5.0)
rails (~> 7.0.4)
tzinfo-data

RUBY VERSION
ruby 3.1.2p20

BUNDLED WITH
2.3.7
36 changes: 34 additions & 2 deletions README.md
@@ -1,2 +1,34 @@
# rails7-api-with-GraphQL
# rails7-api-with-GraphQL
## 環境
- Ruby version
- 3.1.2
- MySQL
- 8.0.16
- System dependencies
[Docker](https://docs.docker.com/docker-for-mac/install/)を使って開発環境を立ち上げる

- Configuration

### Ports

| service | port |
| -------- | ---- |
| api | 3000 |
| mysql | 3306 |

#### 環境変数

データベースの接続情報などは環境変数を利用しています。

[direnv](https://github.com/direnv/direnv)を利用する場合は `/.envrc.sample` を参考に `/.envrc` で指定してください。

### 立ち上げ

```
docker-compose up --build -d
```

### データベースのセットアップ

```
docker-compose exec api bin/rails db:create db:migrate
```
6 changes: 6 additions & 0 deletions Rakefile
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"

Rails.application.load_tasks
4 changes: 4 additions & 0 deletions app/channels/application_cable/channel.rb
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
4 changes: 4 additions & 0 deletions app/channels/application_cable/connection.rb
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
Empty file added app/controllers/concerns/.keep
Empty file.
7 changes: 7 additions & 0 deletions app/jobs/application_job.rb
@@ -0,0 +1,7 @@
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked

# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
Empty file added app/models/concerns/.keep
Empty file.
13 changes: 13 additions & 0 deletions app/views/layouts/mailer.html.erb
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>

<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.erb
@@ -0,0 +1 @@
<%= yield %>
4 changes: 4 additions & 0 deletions bin/rails
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require "rails/commands"

0 comments on commit 179a0bd

Please sign in to comment.