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
ソースコードを快適に引き継いでいくためにやりたいこと/jtf2021w-f5-hassaku-...
Search
hassaku63
January 24, 2021
Programming
1
1.3k
ソースコードを快適に引き継いでいくためにやりたいこと/jtf2021w-f5-hassaku-building-development-environment-with-docker-and-vscode
July Tech Festa 2021 Winter - Session F5
https://techfesta.connpass.com/event/193966/
hassaku63
January 24, 2021
Tweet
Share
More Decks by hassaku63
See All by hassaku63
成果のためのコミュニケーション - 語彙を育てよう -/communication-for-good-outcome-developing-vocabulary
hassaku63
5
270
AWS re:Invent 2023 ML/AI x SaaS セッション振り返り/saas-eng-meetup-6_hassaku63
hassaku63
0
180
202310_社内LT/20231012_lighting_talk
hassaku63
0
62
CDK Day 2023 - Configure cross-account deployment using CDK
hassaku63
0
1.1k
CDK 座談会企画 2023-07 - CDK のメリットを再発掘してみよう
hassaku63
0
180
Serverless Framework ユーザーが CDK に引っ越しして感じたハードルについて言語化してみる
hassaku63
1
3.7k
[AWS Dev Day 2022 Japan] B-4 サーバーレスな社内業務システムを稼働させて1年経ったので、今日までの足跡を語ろうと思う/footprint-of-in-house-system-developed-fully-serverless-on-aws
hassaku63
1
1.7k
AWS X-Ray SDK for Python を使ってトレーサビリティを向上してみよう/start-aws-xray-and-xray-sdk-for-python
hassaku63
1
1.3k
思想から馴染ませるユニットテストの話/let-change-your-viewpoint-about-unit-test
hassaku63
0
210
Other Decks in Programming
See All in Programming
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.9k
情報漏洩させないための設計
kubotak
5
1.3k
テストコード書いてみませんか?
onopon
2
340
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
590
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
28
4.2k
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
1.3k
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.3k
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
300
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.4k
Code Reviewing Like a Champion
maltzj
521
39k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Making Projects Easy
brettharned
116
6k
A better future with KSS
kneath
238
17k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
Into the Great Unknown - MozCon
thekraken
34
1.6k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Transcript
ιʔείʔυΛշదʹҾ͖ܧ͍Ͱ͍ͨ͘Ίʹ Γ͍ͨ͜ͱ @hassaku July Tech Festa 2021 Winter (2021.01.24) #JTF2021w_f
- ίϯςφͱ VSCode Λͬͯ։ൃڥΛշదʹ͢Δ -
ࠓ͍ͨ͜͠ͱ • VSCode ͱίϯςφΛͬͯ։ൃڥΛշదʹ͍ͨ͠ • ϩʔΧϧͰಈ͔ͤΔ։ൃڥΛखʹೖΕΔ • ͦͷଞɺVSCode ͰೖΕ͍ͯΔઃఆͷ
hassaku (twitter: @hassaku_63) Serverworks Co., Ltd. ࣾSE
Interested in: • AWS CDK • Serverless • Python •
TypeScript
࣮ફ AWS CDK - TypeScript Ͱ ΠϯϑϥΞϓϦʂ https://booth.pm/ja/items/1881928 2020.03 -
2020.04 ٕज़ॻయ Ԡԉࡇ (ٕज़ॻయ8)
Agenda 1. ॱௐʹҾ͖ܧ͛ͳ͔ͬͨࢥ͍ग़ 2. “ִ͞Εͨ” ։ൃڥ 3. Docker Componse 4.
VSCode Remote Container
ॱௐʹҾ͖ܧ͛ͳ͔ͬͨࢥ͍ग़ ※લϑϦɻϑΟΫγϣϯͰ͢
͋ΔͷʢՍۭʣ ࣾSE ࠓ͔ΒอकΑΖ͘͠Ͷ ػೳվमͱόάใࠂདྷͯΔ͔Β ͳΔͰΑΖ͘͠ͶɻͳΔͰ
Կ͔ΒΩϟονΞοϓ͢Δʁ 1. ۓٸੑ·ͨॏཁͷߴ͍ Issue ͷ֬ೝ 2. ΞϓϦέʔγϣϯͷѲ 1. υΩϡϝϯςʔγϣϯͷॴࡏ 2.
ߏɺιʔεͷཧղ 3. σϓϩΠํ๏ͷ֬ೝ 4. ࢹܥͷΈͷ༗ແ 3. ݕূڥͷௐୡ
ΞϓϦέʔγϣϯͷѲ ԿΛѲ͢Δ͔ʁ • શମߏਤ • ґଘؔʢ֎෦αʔϏεʗύοέʔδʣ • ΞϓϦʗϞδϡʔϧߏ • ओཁͳϢʔεέʔε
ΞϓϦέʔγϣϯͷѲ Ͳ͏ͬͯѲ͢Δ͔ʁ • υΩϡϝϯςʔγϣϯͷॴࡏΛ֬ೝ • ιʔεͷ֬ೝ • ϑϨʔϜϫʔΫͷґଘؔ • σΟϨΫτϦߏ
• ݕূڥΛ༻ҙͯ͠ಈ͔ͯ͠ΈΔ
ΞϓϦέʔγϣϯͷѲ Ͳ͏ͬͯѲ͢Δ͔ʁ • υΩϡϝϯςʔγϣϯͷॴࡏΛ֬ೝ • ιʔεͷ֬ೝ • ϑϨʔϜϫʔΫͷґଘؔ • σΟϨΫτϦߏ
• ݕূڥΛ༻ҙͯ͠ಈ͔ͯ͠ΈΔ
ʮಈ͔ͯ͠ΈΔʯ͜ͱͷ͠͞ • ͜Ε͕Ͱ͖Δͱ৭ʑḿΔɻ͘͢͝ḿΔ • ಈ࡞ͷΠϝʔδΛ͔ͭΈ͍͢ • ڍಈͷ࠶ݱݕূΛ͘͢͠ͳΔ • ֎෦Өڹ͕ѲͰ͖ͳ͍͏ͪᷖᮣʹಈ͔ͤͳ͍ •
ຊ൪ڥͷ֎෦αʔϏεΛݺͼग़ͯ͠͠·͏͔ʁ • σʔλετΞͷ • ͋Δఔͷσʔλ͕ͳ͍ͱ࣮ࡍͷڍಈʹ͍ۙಈ࡞͕ݟ͑ͳ͍ • ݕূதʹॻ͖͑ͨσʔλͷ෭࡞༻Ͱ࠶ݱੑ͕औΕͳ͘ͳΔ • ্هΛΫϦΞͯ͠ɺʮͪΌΜͱʯಈ͔͢·Ͱʹϋʔυϧ͕͋Δ • ʁʁʁʮಈͣ͘ͳͷʹɺͳΜ͔ݟΒ͵Τϥʔ͕ग़ͯࢭ·ͬͯ͠·͏ΜͰ͚͢Ͳɾɾɾʯ • ϩʔΧϧPCʹطʹೖ͍ͬͯΔґଘؔͷɻωΠςΟϒϥΠϒϥϦͳͲ • ్தͰݕূతͰΠϯετʔϧ͍ͯͨ͠ʢຊདྷෆཁͳʣґଘؔͷ͍ͤͰඍົʹڥࠩҟ͕͋ͬͨ
• ͜Ε͕Ͱ͖Δͱ৭ʑḿΔɻ͘͢͝ḿΔ • ಈ࡞ͷΠϝʔδΛ͔ͭΈ͍͢ • ڍಈͷ࠶ݱݕূΛ͘͢͠ͳΔ • ֎෦Өڹ͕ѲͰ͖ͳ͍͏ͪᷖᮣʹಈ͔ͤͳ͍ • ຊ൪ڥͷ֎෦αʔϏεΛݺͼग़ͯ͠͠·͏͔ʁ
• σʔλετΞͷ • ͋Δఔͷσʔλ͕ͳ͍ͱ࣮ࡍͷڍಈʹ͍ۙಈ࡞͕ݟ͑ͳ͍ • ݕূதʹॻ͖͑ͨσʔλͷ෭࡞༻Ͱ࠶ݱੑ͕औΕͳ͘ͳΔ • ্هΛΫϦΞͯ͠ɺʮͪΌΜͱʯಈ͔͢·Ͱʹϋʔυϧ͕͋Δ • ʁʁʁʮಈͣ͘ͳͷʹɺͳΜ͔ݟΒ͵Τϥʔ͕ग़ͯࢭ·ͬͯ͠·͏ΜͰ͚͢Ͳɾɾɾʯ • ϩʔΧϧPCʹطʹೖ͍ͬͯΔґଘؔͷɻωΠςΟϒϥΠϒϥϦͳͲ • ్தͰݕূతͰΠϯετʔϧ͍ͯͨ͠ʢຊདྷෆཁͳʣґଘؔͷ͍ͤͰඍົʹڥࠩҟ͕͋ͬͨ ʮಈ͔ͯ͠ΈΔʯ͜ͱͷ͠͞ ͜ͷΜͷਏΈΛίϯςφϕʔεͷ։ൃڥ ʢͱ VSCode Ͱʣܰݮ͍ͨ͠
“ִ͞Εͨ” ։ൃڥ
ؾ҆͘৮ΕΔڥ͕΄͍͠ • ֎෦Өڹ͕ͳ͍͜ͱΛ֬৴Ͱ͖Δ͜ͱ • ΞϓϦ͔Βͷ Outbound ੍͕ݶʗېࢭ͞Ε͍ͯΔ • DBͷσʔλৗʹҰఆͷεφοϓγϣοτΛอ͍ͬͯͯ΄͍͠ •
ݕূͷաఔͰมߋͨ͠σʔλϦηοτ͍ͨ͠
։ൃڥͱͯ͠ͷίϯςφ (docker) • ڥͷ࠶ݱੑ • ։ൃڥʗಈ࡞ڥ Dockerfile ʹهड़ͯ͠Ϗϧυ • Կ͍ࣺͯͰ͖Δ
• ϩʔΧϧPCͷڥࠩҟΛഉআ • DockreHub ͷެࣜΠϝʔδ͕ॆ࣮ • ༗໊Ͳ͜Ζ͍͍ͩͨ͋Δ • DBܥͷΠϝʔδ dump ͔ΒॳظσʔλΛऔΓࠐΉํ๏αϙʔτ • docker-compose • AP-DB ͷෳίϯϙʔωϯτͷߏͱΕΔ • N/W पΓͷઃఆ compose ͷઃఆϑΝΠϧͰهड़
docker-compose
ExampleʢDjango + PostgreSQLʣ $POUBJOFS "QQ $POUBJOFS %# Host machine Docker
#SJHEF *' /FUXPSL *' Internet access
ExampleʢDjango + PostgreSQLʣ $POUBJOFS "QQ $POUBJOFS %# Host machine Docker
#SJHEF *' /FUXPSL *' Internet access
ExampleʢDjango + PostgreSQLʣ $POUBJOFS "QQ $POUBJOFS %# Host machine Docker
#SJHEF *' /FUXPSL *' Internet access
Example σΟϨΫτϦߏ • config … ϓϩδΣΫτ • polls … Django
App • Dockerfile … ΞϓϦέʔγϣϯίϯςφ • docker-compose … ݕূڥ • requirements*.txt … ґଘؔ # project # djnago app dir
Example docker-compose.yml • services • db … PostgreSQL • app
… Django DevServer • networks • ϒϦοδ & ֎ͷ௨৴Λېࢭ
Example docker-compose.yml • services • db … PostgreSQL • app
… Django DevServer • networks • ϒϦοδ & ֎ͷ௨৴Λېࢭ ্ཱͪ͛Δ ίϯςφͷఆٛ
Example docker-compose.yml • services • db … PostgreSQL • app
… Django DevServer • networks • ϒϦοδ & ֎ͷ௨৴Λېࢭ ίϯςφͷ N/W
Example - docker-compose docker-compose.yml networks
Example - docker-compose docker-compose.yml services.db
Example - docker-compose docker-compose.yml services.app command: python3 manage.py \ runserver
\ —settings config.settings_local
Example - App settings_local.py
Example - App settings_local.py • docker-compose.yml ͷઃఆ༰ͱ ಉ͡ͷΛهड़ • DBͷϗετ໊
yml Ͱఆٛͨ͠ αʔϏε໊ (=db) ͰղܾՄೳ
Example Django settings settings_local.py • docker-compose.yml ͷઃఆ༰ͱ ಉ͡ͷΛهड़ • DBͷϗετ໊
yml Ͱఆٛͨ͠ αʔϏε໊ (=db) ͰղܾՄೳ
Example - Build & Run > docker-compose build > docker-compose
up -d > docker-compose ps
Tips(1) - DB migration docker-compose exec ίϚϯυͰ migrate ͢Δ >
docker-compose exec <service> <command> manage.py migration
Tips(1) - DB migration docker-compose exec ίϚϯυͰ migrate ͢Δ >
docker-compose exec <service> <command> https://matsuand.github.io/docs.docker.jp.onthefly/compose/reference/exec/ manage.py dbshell
Tips(2) - ॳظσʔλೖ ެࣜΠϝʔδ͕ೖํ๏Λఏڙ͍ͯ͠Δ Postgres Ͱɺ /docker-entrypoint-initdb.d/ Լʹ *.sql ·ͨ
*.sql.gz ܗࣜͷμϯϓΛஔ͓͚ͯ͠OK https://hub.docker.com/_/postgres # Initialization scripts
Tips(2) - ॳظσʔλೖ (sample) σΟϨΫτϦߏ
Tips(2) - ॳظσʔλೖ (sample) docker-compose.yml ʢൈਮʣ postgres/Dockerfile
VSCode - Remote Container
Remote Container https://code.visualstudio.com/docs/remote/containers • VSCode ͷ֦ுػೳ • VSCode ্Ͱίϯςφͷ։ൃڥΛಈ͔ͤΔ
ͳʹ͕خ͍͠ʁ • ·ͬ͞Βͳ VM ʹઐ༻ͷ։ൃڥΛ࡞ͬͯ։ൃͰ͖ΔΠϝʔδ • docker-compose ୯ମͷ߹ΞϓϦͷ࣮ߦڥͷΈίϯςφԽ͢Δ • VSCode
্ͷ࣮ߦίϯςΩετίϯςφͷதʹͳΔ • ΤσΟλɺλʔϛφϧͳͲ • VSCode ͷଞͷػೳ͕ซ༻Ͱ͖Δʢ֦ுػೳؚΉʣ • ίϯςφ্ͷ։ൃڥͰσόοΨ͕͑ΔΑ͏ʹͳΔ • Linter Git पลͷ֦ுػೳͳͲ
Remote Container ίϚϯυύϨοτ (Ctrl+P) Λ։͍ͯ “Add Development Container …” Λબ
ϕʔεʹ͢ΔڥΛબ (Python3 & PostgreSQL)
Remote Container ίϯςφڥΛϏϧυ … Rebuild Container ίϯςφڥͰ VSCode Λ։͖͢ …Open
Workspace in Container
Remote Container Remote Container ؔͷઃఆϑΝΠϧ͕ੜ͞ΕΔ # VSCode Remote Container ͷઃఆϑΝΠϧ
↓ ”Dev Container”
↑ ίϯςφͷ /workspace Ͱλʔϛφϧ͕ىಈ
Remote Container Remote Container ؔͷઃఆϑΝΠϧ͕ੜ͞ΕΔ # VSCode Remote Container ͷઃఆϑΝΠϧ
ੜ͞Ε֤ͨϑΝΠϧͷղઆ ʢVSCode ʹΓସ͑ʣ
༨ஊ όΠϒϧ͕طʹ͋ͬͨ Atsushi Morimoto (@74th) ஶ https://74th.booth.pm/items/2425642
͓ΘΓʹ
·ͱΊ • docker-compose Ͱؾָʹ࡞ΕΔʢյͤΔʣ։ൃڥΛ खʹೖΕΑ͏ • VSCode ͍͍ͧ • ࢿྉɺαϯϓϧίʔυޙެ։༧ఆʢtwitterʣ
• ʢυΩϡϝϯτॻ͜͏ʣ