Upgrade to Pro — share decks privately, control downloads, hide ads and more …

rails new --api してからやったこと 〜2017年・夏〜 / EC Tech M...

rails new --api してからやったこと 〜2017年・夏〜 / EC Tech MTG 3

EC Tech MTG #3(GMOペパボEC事業部の社内勉強会)のための資料です

Kōhei Yamamoto

August 02, 2017
Tweet

More Decks by Kōhei Yamamoto

Other Decks in Technology

Transcript

  1. 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ͷ
 ΞϓϦΛઃஔ͢ΔσΟϨΫτϦΛ४උ
  2. 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 Λ্ཱͪ͛Δ db͸1PTUHSF42-ͷެࣜ
 ΠϝʔδΛͦͷ··ར༻ͨ͠
 ίϯςφ
  3. "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 εςοϓͰηοτΞοϓͰ͖Δ
  4. 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
  5. 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
  6. 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Λࢦఆ