Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
rails new --api してからやったこと 〜2017年・夏〜 / EC Tech M...
Search
Kōhei Yamamoto
August 02, 2017
Technology
0
680
rails new --api してからやったこと 〜2017年・夏〜 / EC Tech MTG 3
EC Tech MTG #3(GMOペパボEC事業部の社内勉強会)のための資料です
Kōhei Yamamoto
August 02, 2017
Tweet
Share
More Decks by Kōhei Yamamoto
See All by Kōhei Yamamoto
一休.comレストランのRustバックエンド開発の様子
kymmt90
14
9.3k
レガシーWebアプリケーションの性能とコードの健全性をインクリメンタルに改善する / pepabotech-20211209
kymmt90
1
1.2k
コードレビュー座学 / About code reviews
kymmt90
0
6.4k
ペパボのWebサービス 開発スタイル / Web services development at GMO Pepabo
kymmt90
2
520
GraphQL and Schema-First Development
kymmt90
4
3.7k
EC新サービスにおけるスキーマファースト開発 / Schema First Development in the New EC Service
kymmt90
1
2k
カテゴリ階層の拡張を目的とした階層的トピックモデル / A hierarchical topic model for expanding category hierarchies
kymmt90
0
370
Other Decks in Technology
See All in Technology
技術ブログや登壇資料を秒で作るコツ伝授します
minorun365
PRO
16
4.4k
標準ライブラリの奥深アップデートを掘り下げよう!
logica0419
2
390
FastConnect の冗長性
ocise
0
7.1k
SHIFTの課題と目指したい組織像 / 20240827 Rinto Ikenoue
shift_evolve
0
140
Discover Your Tailored Platform Strategy with Real-World Practice
hhiroshell
1
130
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
0
13k
脆弱星に導かれて
nishimunea
1
1.5k
[RSJ24] Object Retrieval in Large-Scale Indoor Environments Using Dense Text with a Multi-Modal Large Language Model
keio_smilab
PRO
0
220
実践的なバグバウンティ入門
scgajge12
4
2.1k
Binary Authorizationと友達になろう / Let's be friends with Binary Authorization
iselegant
2
130
[RSJ24] Object Segmentation from Open-Vocabulary Manipulation Instructions Based on Optimal Transport Polygon Matching with Foundation Models
keio_smilab
PRO
0
120
Namespace, Now and Then
tagomoris
0
170
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
363
22k
Into the Great Unknown - MozCon
thekraken
28
1.4k
Navigating Team Friction
lara
183
13k
Optimising Largest Contentful Paint
csswizardry
28
2.7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
662
120k
Fireside Chat
paigeccino
31
2.9k
Unsuck your backbone
ammeep
667
57k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
25
1.3k
No one is an island. Learnings from fostering a developers community.
thoeni
18
2.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
32k
Transcript
ʙɾՆʙ !LZNNU(.01FQBCP *OD &$5FDI.5( rails new --api͔ͯ͠Β ͬͨ͜ͱ
͢͜ͱ w3BJMTͰ"1*αʔόΛ࡞Δʹ͋ͨͬͯɺ։ൃੜ࢈ੑΛ্͛ΔͨΊʹ ͬͨ͜ͱΛհ͠·͢ wΰʔϧ w"1*ͳͲ։ൃ࣌ʹҰൠʹߟ͑ΔͱΑͦ͞͏ͳ͜ͱ͕ΒΛͬͯΒ͏ wຊࢿྉ3BJMTΛྫʹ͋͛ͯઆ໌͠·͕͢ߟ͔͑ͨԠ༻Ͱ͖ͦ͏
എܠ w+40/Λฦ͢8FC"1*αʔό Λ৽نʹॻ͘͜ͱʹͳͬͨ wϑϩϯτΤϯυͷ4JOHMF1BHF"QQMJDBUJPO 41" ͕͏ wΏ͘Ώ͘ެ։"1*ͱ͍ͨ͠ w3BJMTͰ։ൃͯ͠)FSPLVͷ্Ͱಈ͔͢ •$ rails
new <app_name> --api -d postgresql ͍͍ػձͳͷͰ։ൃָ͕ʹͳΔڥΛ࡞Γ͍ͨ ࠓޙ"1*ͱݺͼ·͢
ͬͨ͜ͱҰཡ w%PDLFSͰ։ൃڥ࡞ wελϒαʔόͷੜ wίʔσΟϯάنͷࣗಈνΣοΫ
%PDLFSͰ։ൃڥ࡞
%PDLFSͰ։ൃڥ࡞ʛ8IZ wݸਓ1$ͷڥʹΑͬͯɺ։ൃڥͷηοτΞοϓ͕ͳ͔ͳ͔͏·͘ ͍͔ͳ͍͜ͱ͕͋ͬͨ wྫɿOBUJWFFYUFOTJPOΛ͏HFNΛσβΠφ͞Μͷ1$ Πϯετʔϧ͠Α͏ͱࣦͯ͠ഊ͠ଓ͚Δ wϓϩμΫτ։ൃͰσβΠφͱΤϯδχΞͷ྆ํ͕։ൃڥΛ͏ w͔ΜͨΜʹηοτΞοϓͰ͖ɺ͏·͘ಈ͔ͳ͍ͱ͖ͷݪҼΓ͚͕ ָͳ։ൃڥʹ͔ͨͬͨ͠
Dockerfile FROM ruby:2.4.1 ENV APP_HOME /usr/src/app RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME COPY Gemfile \ Gemfile.lock \ $APP_HOME/ ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \ BUNDLE_JOBS=4 "1*Λ্ཱͪ͛ΔͨΊͷڥΛ%PDLFS Πϝʔδͱͯ͠࡞͢Δ %PDLFS)VC͔Βऔಘͨ͠3VCZͷެࣜ ΠϝʔδΛͱʹɺΠϝʔδʹ3BJMTͷ ΞϓϦΛઃஔ͢ΔσΟϨΫτϦΛ४උ
docker-compose.yml version: '3' services: db: image: postgres:9.6.3 app: &app_base build:
. # build a container from Dockerfile command: bin/rails s -b '0.0.0.0' depends_on: - db spring: <<: *app_base command: bin/spring server %# 3BJMT 4QSJOHͦΕͧΕͷ ίϯςφΛ্ཱͪ͛ΔͨΊͷઃ ఆϑΝΠϧʢࠨਤൈਮʣ app͖͞΄Ͳͷ DockerfileΛͱʹͨ͠3BJMT Λಈ͔͢ίϯςφ db্ཱ͕͕ͪͬͨ͋ͱʹapp Λ্ཱͪ͛Δ db1PTUHSF42-ͷެࣜ ΠϝʔδΛͦͷ··ར༻ͨ͠ ίϯςφ
"1*ͷηοτΞοϓ $ git clone
[email protected]
:foo/bar.git && cd ./bar $ docker-compose
run --rm app bundle install $ docker-compose run --rm app bin/rake db:setup $ docker-compose up # start db, app, spring εςοϓͰηοτΞοϓͰ͖Δ
bin/setup chdir APP_ROOT do puts '== Installing dependencies ==' system!
'docker-compose run --rm app bundle install' puts "\n== Preparing database ==" system! 'docker-compose run --rm app bin/rake db:setup' puts "\n== Removing old logs and tempfiles ==" system! 'docker-compose run --rm app \ bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" system! 'docker-compose up' end 3BJMTͰೖͬͨΞϓϦͷॳظઃఆ ΛࣗಈԽ͢ΔͨΊͷεΫϦϓτ !LFODIBO͘Μ͞Μ͔Βbin/setup Ͱઌड़ͨ͠ηοτΞοϓΛ࣮ͯ͢ߦ ͢Δ ͨΊͷQVMMSFRVFTU͕ʂʂ ʢࠨਤൈਮʣ !POL͞ΜͷࢿྉͰհ͞Ε͍ͯͨํ๏ IUUQTXXXTMJEFTIBSFOFUUBLBGVNJPOBLB SBJMT
"1*ͷηοτΞοϓɾվ $ git clone
[email protected]
:foo/bar.git && cd ./bar $ bin/setup
εςοϓʹͳͬͨ
ελϒαʔόͷੜ
ελϒαʔόΛੜ͢Δʛ8IZ wόοΫΤϯυ൝ "1* ͱϑϩϯτΤϯυ൝ 41" Ͱ͔Εͯ։ൃ ͍ͯ͠Δ w"1*͕͠ͳ͍ͱ41"࡞Γʹ͍͘ w͔͠͠ฒߦͯ͠։ൃ͍ͨ͠ wαϯϓϧͷϨεϙϯεΛฦ͢ελϒαʔό͕΄͍͠
0QFO"1* paths: /products/{productId}: get: operationId: getProduct parameters: - in: path
name: id type: integer responses: '200': schema: type: object properties: product: type: object properties: name: type: string example: ͓ࡼ Χϥʔϛʔγϣοϓ"1*Ͱ෦తʹಋೖࡁΈ ͷ0QFO"1*Ͱ"1*༷Λઌʹॻ͘ ʢࠨਤൈਮʣ :".-Ͱॻ͍ͨ0QFO"1*ͰͷఆٛΛZBNM@SFG@SFTPMWFS Λ ͬͯ0QFO"1*ͱͯ͠WBMJEͳswagger.jsonʹม͠ɺ Ͳ͔͜ʹग़ྗ͓ͯ͘͠ IUUQTHJUIVCDPN+PFOPIZBNM@SFG@SFTPMWFS
4XBHHFS$PEFHFO $ docker pull swaggerapi/swagger-codegen-cli $ docker run -v ${PWD}:/local
\ swaggerapi/swagger-codegen-cli \ generate -l nodejs-server -i /path/to/swagger.json \ -o /local/stub_app 4XBHHFS$PEFHFO W Ͱɺఆٛͨ͠αϯϓϧϨεϙϯεΛฦͤΔͷ /PEF 4QSJOH.7$ͳͲʹݶΒΕ͍ͯΔͷͰɺࠓճnodejs-serverΛࢦఆ
ελϒαʔόͷ্ཱͪ͛ ʢNodeͷڥDockerͳͲͰ࡞͓ͬͯ͘ʣ $ npm start ʢҎԼผλʔϛφϧͰʣ $ curl http://localhost:3000/products/1 {
"product": { "name": "͓ࡼ" } } ͖ͳϨεϙϯεฦ͠์
ࢀߟʛ"1*ఆٛͷ։ൃϑϩʔ w0QFO"1*Ͱ"1*ఆٛΛՃ͢ΔQVMMSFRVFTUΛ࡞Δ w4XBHHFS&EJUPSΛ͏ͱTZOUBYDIFDLͬͯศར wॻ͖࣍ୈɺσεΫपลͰ։ൃਞΈΜͳ͕ू·ͬͯϨϏϡʔ wϑϩϯτΤϯυʗόοΫΤϯυ྆ํͷࢹͰϨϏϡʔͰ͖Δ w0,Ͱ͋ΕNBTUFSϚʔδ w͜ͷ࣌ͰελϒαʔόͰͦͷ"1*͕͑ΔΑ͏ʹͳΔ
ίʔσΟϯάنͷࣗಈνΣοΫ
ίʔσΟϯάنͷࣗಈνΣοΫʛ8IZ wίʔυϨϏϡʔͰઃܭϩδοΫͷϨϏϡʔʹूத͍ͨ͠ͷͰɺ ίʔσΟϯάελΠϧΛܾΊͯɺࣗಈͰͤΔΑ͏ʹ͍ͨ͠ wͨͩ͠ɺ3VCZʹ1)1ͷ143 1ZUIPOͷ1&1΄Ͳཱ֬ͨ͠ ίʔσΟϯάنඪ४ͳ͍
ίʔσΟϯάنʢϧʔϧʣͷઃܭ w3VCP$PQͰνΣοΫ͢Δ wϧʔϧͷݫີ͞ΛܾΊΔ wࣾطଘϓϩδΣΫτͷϧʔϧ!POL͞Μͷهࣄ Λࢀߟʹ ͠ͳ͕Βɺ؇Ίͷͷ͔Β࢝ΊΔ͜ͱʹͨ͠ w!ITCU͞ΜͷΞυόΠε͋ͬͯɺؾܰʹ.rubocop.ymlʹରͯ͠ QVMMSFRVFTUΛग़ͯ͠Β͏ํʹͨ͠ IUUQCMPHPOLOJOKBSVCPDPQHFUUJOHTUBSUFE
3VCP$PQͷϧʔϧྫ w3VCZJTUͳΒ΄΅͜͏ॻͩ͘Ζ͏ͱ͍͏ͷ͚ͩΛϧʔϧͱͯ͠ ͏ w͓અհͳͷΈ͕Θ͔Εͦ͏ͳͷͻͱ·ͣΘͳ͍ w͏ϧʔϧͷྫ wෆཁͳۭߦʗۭ֯നΛফ͢ wίϩϯʗΧϯϚͷ͏͠ΖɺதΧοίͷଆͳͲۭ֯നΛೖΕΔ wҾͳ͠ϝιουͷݺͼग़࣌͠ΧοίΛ͚ͭͳ͍
3VCP$PQͷ࣮ߦ wRuboCop::CLI#runΛͬͯ34QFDͷࣗಈςετͷͳ͔ͰνΣοΫ ͍ͯ͠Δ wࣗಈमਖ਼·Ͱ͍ͯ͠ͳ͍ w3VCZͷίʔυͯ͢ΛόονͰνΣοΫ͢ΔͷͰ͘ͳΔ w;ͩΜQSFDPNNJUIPPLͰνΣοΫͭͭ͠ɺNBTUFSʹରͯ͠ OJHIUMZDIFDL͢Δͱ͔
·ͱΊ
·ͱΊ w։ൃڥ୭ͷ1$্Ͱಉ͡ڥͰಈ͘Α͏ʹ͢Δͱศར w։ൃڥͰ͖Δ͚ͩগͳ͍εςοϓͰηοτΞοϓͰ͖Δͱศར wελϒαʔό࡞ͷΈΛ࡞͓ͬͯ͘ͱϑϩϯτΤϯυʗόοΫΤ ϯυͰฒྻʹ։ൃͰ͖ͯศར w͞Βʹ"1*ఆٛΛνʔϜͰϨϏϡʔ͢Δػձ͕૿͑ΔͷͰศར wࣗಈͰίʔσΟϯάنͷνΣοΫ͕ΔΑ͏ʹ͢Δͱศར
Ҿ͖ଓ͖͍ͬͯ͘͜ͱ w"1*༷ͱ࣮ͷ͍͋ͩͷڍಈͷဃΛ͙ w0QFO"1* 34QFD "QJWPSF wػೳʗύϑΥʔϚϯεͷܧଓతվળͷޮԽ w5BDIJLPNB HFNEJ⒎ͰHFNͷܧଓతΞοϓσʔτ w/ ͷࣗಈݕग़
w$*ͷҡ࣋