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

Firestore東京リージョン利用に伴う Firebaseプロジェクト移行手順 / alu-firestore #アル

Hikaru Tooyama
February 18, 2019

Firestore東京リージョン利用に伴う Firebaseプロジェクト移行手順 / alu-firestore #アル

Hikaru Tooyama

February 18, 2019
Tweet

More Decks by Hikaru Tooyama

Other Decks in Business

Transcript

  1. 1
    Firestore౦ژϦʔδϣϯར༻ʹ൐͏
    FirebaseϓϩδΣΫτҠߦखॱ

    Ξϧגࣜձࣾɹԕࢁߊ !WFYVT

    View full-size slide

  2. 2
    ࣗݾ঺հ
    - Ξϧגࣜձࣾ ԕࢁߊ (@vexus2)
    - ݱ৬Ͱ͸ VP of Product
    - ݩʑBackend(Ruby/PHP)͕ͩ࠷ۙ͸FrontendدΓ
    - TypeScript / Vue / Nuxt / Firebase ͳͲ
    - Firebaseྺ͸1೥6ϲ݄͘Β͍
    - ຊ൪ӡ༻ྺ͸8ϲ݄͘Β͍
    - झຯ͸ϚϯΨΛಡΉ͜ͱ

    View full-size slide

  3. 3
    ࣗݾ঺հ
    ແྉͰఏڙ͞Ε͍ͯΔອըΛूΊͨʮອըϏϨοδʯΛݸਓͰӡӦɻ
    ϐʔΫ࣌ͷաڈ30೔ؒͰ1060ສPV͕͋ΓɺͦͷޙΞϧ΁Ϧϒϥϯυɻ
    Xxx
    ίϛϡχςΟ
    GoogleͰʮອըଜʯͰݕࡧ͢Δͱ1Ґʹ
    Yahoo!χϡʔεͷτοϓʹ(هࣄݩɿITmedia)

    View full-size slide

  4. 4
    Ξϧͱ͸ʁ
    W

    View full-size slide

  5. 5
    ࠓ೔࿩͢಺༰ͷલఏ঺հ
    Ξϧ͸ɺϚϯΨϑΝϯͷͨΊʹɺϚϯΨΛൃݟͰ͖ΔศརͳαʔϏεΛఏڙ͢Δ
    ϚϯΨ୳͠ͷ৘ใαʔϏεͰ͢ɻ
    iOS/Web൛ΛͦΕͧΕఏڙதɻ

    View full-size slide

  6. 6
    ౦ژϦʔδϣϯ΁ͷҠߦ
    W

    View full-size slide

  7. 7
    Firestoreͷલఏ

    View full-size slide

  8. 8
    ؆қͳϕϯνϚʔΫ
    ଌఆ೔͸2019/1/25
    ࣮ߦ؀ڥ ॳճ 2ճ໨Ҏ߱
    us-central
    1݅औಘ 892.3ms 202.3ms
    20݅औಘ(SubCollection) 864ms 260.8ms
    asia-northeast1
    1݅औಘ 370.3ms 125.6ms
    20݅औಘ(SubCollection) 461.3ms 156.4ms
    ࠃ಺ͰαʔϏεΛల։͢Δ্Ͱ͸1ඵͰ΋ૣ͘TokyoϦʔδϣϯʹ
    Ҡߦ͢Δʹӽͨ͜͠ͱ͸ͳ͍͕ɺ໘౗ͳͱ͜Ζ͕͍͔ͭ͋͘Δɻ
    ࢼߦճ਺100ճఔ౓ͷ؆қతͳϕϯνϚʔΫͰͷฏۉ஋ɻ
    ࣮ߦωοτϫʔΫ؀ڥͳͲʹΑͬͯมΘΔ͕ࢀߟ·Ͱɻ

    View full-size slide

  9. 9
    Firestoreͷલఏ
    1. Cloud FirestoreͷσϑΥϧτϦʔδϣϯ͸ us-centralɻ

    βҎલ͔Β࢖༻͍ͯ͠ΔϓϩδΣΫτ͸શ෦͜ͷঢ়ଶɻ
    2. FirestoreͷϦʔδϣϯ͸

    ʮFirebaseϓϩδΣΫτʯͷ࡞੒࣌

    ͷΈมߋՄೳ
    3. Firestore͸1ͭͷϓϩδΣΫτʹ͖ͭ

    1͔ͭ͠࡞੒Ͱ͖ͳ͍
    (GCPͷϓϩδΣΫτʹ΋ඥ෇͍͍ͯΔ)
    FirestoreͷϦʔδϣϯΛมߋ͢ΔͨΊʹ͸
    FirebaseϓϩδΣΫτΛ࡞Γ௚͢ඞཁ͕͋Δ

    View full-size slide

  10. 10
    खॱͱ΍Δ͜ͱ
    W

    View full-size slide

  11. 11
    ϓϩδΣΫτҠߦ·Ͱͷશମ૾
    - GCPϢʔβͳͲͷ੔ཧɺҠߦ
    - PubSub, Cloud Scheduler, BigQueryͳͲ࢖༻͍ͯ͠ΔGCPαʔϏεͷҠߦ
    - ΞϓϦଆͷॾʑ޲͖ઌมߋͨ͠ঢ়ଶͰΞϓϦ৹ࠪΛ௨͓ͯ͘͠

    - Force UpdateͳͲͷ࢓૊Έ͸େৎ෉͔ʁ΋ཁ֬ೝ
    - Cloud StorageͷҠߦઌͷBucketΛ࡞͓ͬͯ͘
    - ϓϩδΣΫτҠߦʹ൐͏Ϣʔβ੍໿ͷ֬ೝ
    - ϝϯςφϯε࣌ؒͷࠂ஌
    - σʔλྔʹ΋ΑΔ͕Ұ൪ֻ͕͔࣌ؒΔͷ͸FirestoreͷσʔλҠߦ
    ࣄલʹ΍Δ͜ͱ
    ϝϯςφϯεதʹ΍Δ͜ͱ
    - Firestore AuthͷσʔλҠߦ
    - FirestoreͷσʔλͷҠߦ
    - Cloud StorageͷσʔλҠߦ
    - CDNͷOriginͷઃఆͳͲ΋͋Ε͹๨Εͣʹ
    - Cloud FunctionsͷσϓϩΠ
    - ϝϯςφϯεऴྃ࣌ͷForce Update

    View full-size slide

  12. 12
    ϓϩδΣΫτҠߦʹ൐͏Ϣʔβ੍໿ͷ֬ೝ
    - Firebase Authentication͸Import/Export͕Ͱ͖ΔͷͰ৽ϓϩδΣΫτͰ΋Ҡ
    ߦલͱಉ͡ϢʔβͰϩάΠϯ͕Ͱ͖Δ(ιʔγϟϧϩάΠϯؚΉ)
    - ͨͩ͠ɺϩάΠϯঢ়ଶ͕Ҿ͖ܧ͕Εͳ͍ͨΊಗ໊(Anonymous)Ϣʔβͷσʔ
    λ͸࣮࣭ফ͑Δ
    - ·ͨɺϨΞέʔε͕ͩʢΞϧͷΑ͏ʹʣGoogleϩάΠϯʹ௥ՃͰGmailͳͲ
    ͷݖݶΛऔಘ͍ͯ͠Δ৔߹ɺ৽ϓϩδΣΫτҠߦޙʹ࠶౓શϢʔβʹݖݶ
    ֬ೝը໘ΛܦͯaccessTokenΛऔಘ͢Δඞཁ͕͋Δɻ
    ಗ໊Ϣʔβ͕ϝϯςҠલͷσʔλ͕࢖͑ͳ͘ͳͬͯ΋໰୊ͳ͍͔ɺ

    ໰୊͕͋ΔΑ͏Ͱ͋Ε͹ҠߦલʹଞϩάΠϯͤ͞Δ͜ͱͰ

    σʔλ͕ফ͑ͳ͘ͳΔΑ͏௨஌ظؒΛઃ͚ΔඞཁͳͲݕ౼͢Δ

    View full-size slide

  13. 13
    Firestore AuthͷσʔλҠߦ
    - جຊతʹ͸Exportͯ͠Import͢Δ͚ͩɻ
    - લड़ͷͱ͓Γಗ໊ϩάΠϯ͸ϩάΠϯঢ়ଶ͕Ҿ͖ܧ͛ͳ͍ͷͰɺʢ৽ϓϩδΣ
    Ϋτʹಗ໊ϢʔβͷϊΠζΛ࣋ͪࠐΈͨ͘ͳ͍৔߹͸ʣExport͞ΕͨJSON
    ͷத਎͔Βಗ໊ϢʔβͷσʔλΛ࡟আͯ͠΋ྑ͍ɻ
    $ firebase auth:export firebase-auth-users.json --format json --project چFirebaseϓϩδΣΫτ
    $ firebase auth:import firebase-auth-users.json --project ৽FirebaseϓϩδΣΫτ
    https://gist.github.com/vexus2/d5eecdc76cf94526645656c7a01f87c9

    View full-size slide

  14. 14
    FirestoreͷσʔλͷExport/Import
    چFirestore→GCSʹσʔλΛExportɺGCS→৽Firestoreʹ
    Import͢Δɻ
    ͨͩ͠ɺಉҰϦʔδϣϯͷGCS͔Β͔͠Import/ExportͰ
    ͖ͳ͍ͷͰBucketΛ2ͭ༻ҙ͢Δඞཁ͕͋Δɻ
    چFirestore

    (us-central)
    ৽Firestore

    (asia-northeast1)
    gs://
    backup-us

    (us-central1)
    gs://
    backup-asia

    (asia-northeast1)

    View full-size slide

  15. 15
    FirestoreͷσʔλͷExport/Import
    $ gcloud beta firestore export gs://backup-us --project چFirebaseϓϩδΣΫτ
    $ gsutil ls -a gs://backup-us | tail -n1 # όοΫΞοϓϑΝΠϧ֬ೝ
    $ gsutil cp -r `gsutil ls -a gs://backup-us | tail -n1` gs://backup-asia
    $ gsutil ls -a gs://backup-asia | tail -n1 # όοΫΞοϓϑΝΠϧ֬ೝ
    $ gcloud beta firestore import `gsutil ls -a gs://backup-asia | tail -n1` --project ৽Firebaseϓϩδ
    ΣΫτ
    https://gist.github.com/vexus2/d5eecdc76cf94526645656c7a01f87c9

    View full-size slide

  16. 17
    ·ͱΊ
    - ʢࣗࣾͷαʔϏε͕ʣຊ൪ϩʔϯνલͳΒɺҠߦ͸ʮ͍͑΍ͬʯͰҰؾʹ
    ΍ͬͪΌ͏ͷ͕ಘࡦɻ
    - طʹϩʔϯνޙͳΒɺ૿͍͑ͯ͘طଘσʔλͱͷ੔߹ੑΛ୲อ͢ΔͨΊʹϝ
    ϯςφϯεΛೖΕͯҠߦ͢Δͷ͕ݱ࣮తɻ
    - ਖ਼௚΍Δ͜ͱ͸ଟ͍͠ߟྀࣄ߲΋ଟ͍ͷͰେม͕ͩɺ΍ΔՁ஋͸े෼ʹ͋
    Δɻ

    View full-size slide