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

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

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. 2 ࣗݾ঺հ - Ξϧגࣜձࣾ ԕࢁߊ (@vexus2) - ݱ৬Ͱ͸ VP of

    Product - ݩʑBackend(Ruby/PHP)͕ͩ࠷ۙ͸FrontendدΓ - TypeScript / Vue / Nuxt / Firebase ͳͲ - Firebaseྺ͸1೥6ϲ݄͘Β͍ - ຊ൪ӡ༻ྺ͸8ϲ݄͘Β͍ - झຯ͸ϚϯΨΛಡΉ͜ͱ
  2. 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ճఔ౓ͷ؆қతͳϕϯνϚʔΫͰͷฏۉ஋ɻ ࣮ߦωοτϫʔΫ؀ڥͳͲʹΑͬͯมΘΔ͕ࢀߟ·Ͱɻ
  3. 9 Firestoreͷલఏ 1. Cloud FirestoreͷσϑΥϧτϦʔδϣϯ͸ us-centralɻ
 βҎલ͔Β࢖༻͍ͯ͠ΔϓϩδΣΫτ͸શ෦͜ͷঢ়ଶɻ 2. FirestoreͷϦʔδϣϯ͸
 ʮFirebaseϓϩδΣΫτʯͷ࡞੒࣌


    ͷΈมߋՄೳ 3. Firestore͸1ͭͷϓϩδΣΫτʹ͖ͭ
 1͔ͭ͠࡞੒Ͱ͖ͳ͍ (GCPͷϓϩδΣΫτʹ΋ඥ෇͍͍ͯΔ) FirestoreͷϦʔδϣϯΛมߋ͢ΔͨΊʹ͸ FirebaseϓϩδΣΫτΛ࡞Γ௚͢ඞཁ͕͋Δ
  4. 11 ϓϩδΣΫτҠߦ·Ͱͷશମ૾ - GCPϢʔβͳͲͷ੔ཧɺҠߦ - PubSub, Cloud Scheduler, BigQueryͳͲ࢖༻͍ͯ͠ΔGCPαʔϏεͷҠߦ -

    ΞϓϦଆͷॾʑ޲͖ઌมߋͨ͠ঢ়ଶͰΞϓϦ৹ࠪΛ௨͓ͯ͘͠
 - Force UpdateͳͲͷ࢓૊Έ͸େৎ෉͔ʁ΋ཁ֬ೝ - Cloud StorageͷҠߦઌͷBucketΛ࡞͓ͬͯ͘ - ϓϩδΣΫτҠߦʹ൐͏Ϣʔβ੍໿ͷ֬ೝ - ϝϯςφϯε࣌ؒͷࠂ஌ - σʔλྔʹ΋ΑΔ͕Ұ൪ֻ͕͔࣌ؒΔͷ͸FirestoreͷσʔλҠߦ ࣄલʹ΍Δ͜ͱ ϝϯςφϯεதʹ΍Δ͜ͱ - Firestore AuthͷσʔλҠߦ - FirestoreͷσʔλͷҠߦ - Cloud StorageͷσʔλҠߦ - CDNͷOriginͷઃఆͳͲ΋͋Ε͹๨Εͣʹ - Cloud FunctionsͷσϓϩΠ - ϝϯςφϯεऴྃ࣌ͷForce Update
  5. 12 ϓϩδΣΫτҠߦʹ൐͏Ϣʔβ੍໿ͷ֬ೝ - Firebase Authentication͸Import/Export͕Ͱ͖ΔͷͰ৽ϓϩδΣΫτͰ΋Ҡ ߦલͱಉ͡ϢʔβͰϩάΠϯ͕Ͱ͖Δ(ιʔγϟϧϩάΠϯؚΉ) - ͨͩ͠ɺϩάΠϯঢ়ଶ͕Ҿ͖ܧ͕Εͳ͍ͨΊಗ໊(Anonymous)Ϣʔβͷσʔ λ͸࣮࣭ফ͑Δ -

    ·ͨɺϨΞέʔε͕ͩʢΞϧͷΑ͏ʹʣGoogleϩάΠϯʹ௥ՃͰGmailͳͲ ͷݖݶΛऔಘ͍ͯ͠Δ৔߹ɺ৽ϓϩδΣΫτҠߦޙʹ࠶౓શϢʔβʹݖݶ ֬ೝը໘ΛܦͯaccessTokenΛऔಘ͢Δඞཁ͕͋Δɻ ಗ໊Ϣʔβ͕ϝϯςҠલͷσʔλ͕࢖͑ͳ͘ͳͬͯ΋໰୊ͳ͍͔ɺ
 ໰୊͕͋ΔΑ͏Ͱ͋Ε͹ҠߦલʹଞϩάΠϯͤ͞Δ͜ͱͰ
 σʔλ͕ফ͑ͳ͘ͳΔΑ͏௨஌ظؒΛઃ͚ΔඞཁͳͲݕ౼͢Δ
  6. 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
  7. 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
  8. 18