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
GitLab CI/CDとECS Fargateでリリース作業が楽になった話
Search
orfx
April 24, 2019
Technology
2
4.9k
GitLab CI/CDとECS Fargateでリリース作業が楽になった話
2019/04/24(水)
GitLab Meetup Tokyo #16: 新年度応援
https://gitlab-jp.connpass.com/event/126533/
orfx
April 24, 2019
Tweet
Share
More Decks by orfx
See All by orfx
Datadog Logs に ログを集約しようと してる話
orfx
0
7k
Other Decks in Technology
See All in Technology
Taming you application's environments
salaboy
0
180
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
200
スクラムチームを立ち上げる〜チーム開発で得られたもの・得られなかったもの〜
ohnoeight
2
350
Terraform Stacks入門 #HashiTalks
msato
0
350
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.3k
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
360
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
590
元旅行会社の情シス部員が教えるおすすめなre:Inventへの行き方 / What is the most efficient way to re:Invent
naospon
2
340
Featured
See All Featured
Building Applications with DynamoDB
mza
90
6.1k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Code Review Best Practice
trishagee
64
17k
Typedesign – Prime Four
hannesfritz
40
2.4k
4 Signs Your Business is Dying
shpigford
180
21k
Thoughts on Productivity
jonyablonski
67
4.3k
Teambox: Starting and Learning
jrom
133
8.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Agile that works and the tools we love
rasmusluckow
327
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Visualization
eitanlees
145
15k
Transcript
GitLab CI/CD ͱ ECS Fargate Ͱ ϦϦʔε࡞ۀָ͕ʹͳͬͨ GitLab Meetup Tokyo
#16 גࣜձࣾΞΠϦοδ ޱ
Kawaguchi So • ࣗࣾαʔϏεͷӡ༻νʔϜॴଐ • αʔόαΠυΤϯδχΞ • GitLab ྺ1 •
Suzuki V-Strom250 2018.04 ~
ͱ͜ΖͰ օ͞ΜͷपΓʹ͜Μͳ ΦϖϨʔγϣϯ͋Γ·ͤΜ͔ʁ
Before ౿Έαʔό ΞϓϦέʔγϣϯαʔό • ͱ͋ΔίϯϙʔωϯτͷϦϦʔεखॱॻʹه ࡌ͞Ε͍ͯͨίϚϯυܭ 88 ݸͰɺ࡞ۀऀͱ ֬ೝऀ͕ҰͭҰͭ݁ՌΛμϒϧνΣοΫ͠ͳ ͕Β࣮ߦ͍ͯͨ͠
(࣮) ϦϦʔε࡞ۀऀ ϦϙδτϦ 44) BOTJCMF QMBZCPPL HJUDMPOF
ͭΒ͍ ɺɺɺͰ͕͢
ͦΜͳͭΒ͍ӡ༻पΓ GitLab CI/CD Λ ׆༻͢ΔνϟϯεͰ͢
After GitLab 1ͷࢲͰ GitLab CI/CD Λ͑ ϘλϯΛԡ͚ͩ͢ ͷϦϦʔε͕࣮ݱͰ͖·ͨ͠ʂ
ͲΜͳύΠϓϥΠϯΛ ߏஙͨ͠ͷ͔
Build Stage build: stage: build script: - docker build -t
image_name:ci . - docker save image_name:ci -o ${ARTIFACT_PATH} artifacts: paths: - ${ARTIFACT_PATH} expire_in: 1h • docker build ͰϏϧυͨ͠ΠϝʔδΛ docker save ͰϑΝΠϧʹॻ͖ग़͢ɻ • ॻ͖ग़ͨ͠ϑΝΠϧ GitLab ͷ artifacts ػೳͰ δϣϒྃޙʹ GitLab ࣗಈΞοϓϩʔυͤ͞Δɻ
Test Stage unittest: stage: test script: - docker load -i
${ARTIFACT_PATH} - docker-compose up --exit-code-from service_name • artifacts ͰΞοϓϩʔυ͞ΕͨϑΝΠϧ࣍ͷδϣϒ։࢝࣌ ʹࣗಈμϯϩʔυ͞ΕΔͷͰ docker load ͰಡΈࠐΉɻ • ͦͷΠϝʔδΛ༻͍ͯ docker-compose Ͱ UnitTest ʹඞཁ ͳίϯςφҰࣜΛཱͪ͛ͯςετΛ࣮ߦ͢Δɻ
Push Stage push: stage: push script: - docker load -i
${ARTIFACT_PATH} - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker tag image_name:ci $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG • ಉ༷ʹࣗಈμϯϩʔυ͞ΕͨϏϧυΠϝʔδΛಡΈࠐΉɻ • docker login Ͱ GitLab Container Registry ʹϩάΠϯͯ͠ɺ docker push ͰϨδετϦʹΠϝʔδΛΞοϓϩʔυ͢Δɻ
Deploy Stage deploy: stage: deploy variables: RELEASE_TAG: $CI_COMMIT_REF_SLUG script: -
ecs-cli compose -p ${SERVICE_NAME} -f ${CLUSTER_NAME} service up தུ environment: name: ${ENVIRONMENT} when: manual • ECS CLI Ͱ docker-compose ϑΝΠϧΛ༻ͯ͠αʔϏεΞοϓ ͢Δɻ͜Ε͚ͩͰ ECS ͕͍͍ײ͡ʹσϓϩΠͯ͘͠ΕΔ (ࡶ) • σϓϩΠδϣϒ when: manual Λࢦఆͯࣗ͠ಈ࣮ߦ͞Εͳ͍Α ͏ʹ͢Δɻ -> ͜Ε͕ઌ΄Ͳͷԡ͚ͩ͢ͷϘλϯ
δϣϒ࣮ߦ݅Λઃఆͯ͠ޡരࢭ ௨ৗ࣌ ςετলུͯ࣌ؒ͠ॖ ϦϦʔε࣌ͷΈ ຊ൪ڥσϓϩΠ͕ දࣔ͞ΕΔ ϦϦʔε࣌ (λάϓογϡͰύΠϓϥΠϯΛੜ͢Δӡ༻)
ศརͰخ͍͠ػೳ
Artifacts ػೳ • Runner ͕ෳ͋ΔڥͰɺύΠϓϥΠϯதʹผͷ Runner Ͱॲཧ͕࣮ߦ͞Εͯ͠·ͬͯɺδϣϒ࣮ߦʹඞ ཁͳϑΝΠϧΛ؆୯ʹڞ༗͢Δ͜ͱ͕Ͱ͖Δɻ • expire_in
Ͱ༗ޮظݶΛઃఆ͢ΔͱࣗಈͰআͯ͘͠Ε Δɻ • Ξοϓϩʔυͨ͠ϑΝΠϧΣϒαΠτ্͔Βμ ϯϩʔυͰ͖Δɻ
Environment ػೳ deploy: stage: deploy variables: RELEASE_TAG: $CI_COMMIT_REF_SLUG script: -
ecs-cli compose -f compose.yml தུ environment: name: ${ENVIRONMENT} when: manual δϣϒʹڥ໊Λఆ͓͚ٛͯͩ͘͠Ͱ…
Environment ػೳ GitLab ্ʹڥҰཡΛউखʹ࡞ͬͯ͘ΕΔʂ
Environment ػೳ • ڥຖʹσϓϩΠཤྺ͕࣌λά͖ͰݟΕΔʂ • ͔͜͜ΒϘλϯҰͭͰҙ࣌ʹϩʔϧόοΫͰ͖Δʂ
Container Registry ػೳ • Լهਤͷ༷ʹύεΛ۠Δͱผݸʹදࣔ͞ΕΔͷͰ nginx ͳͲαΠυΧʔతͳίϯςφΛಉҰϓϩδΣΫτ ͰҰݩཧ͢Δࡍʹศརɻ
Container Registry ͱ Fargate Fargate Secrets Manager Container Registry ᶃ
ᶄ ᶅ ᶆ 1. CI/CD ͕ Registry ʹΠϝʔδΛϓογϡ 2. CI/CD ͕λεΫఆٛͱαʔϏεΛߋ৽ AWS७ਖ਼ͷ Container Registry (ECR) ͡Όͳͯ͘ Deploy Token ͱ Secrets Manager Ͱ Fargate ʹσϓϩΠͰ͖·͢ʂ 3. Fargate ͕ SM ͔Β Deploy Token Λೖख 4. Fargate ͕ Deploy Token ΛͬͯΠϝʔδΛऔಘ
ຊͷ·ͱΊ • GitLab ʹӡ༻୲ऀʹخ͍͠ศརͳػೳ͕ Γͩ͘͞Μʂ • ͳΜͱ͜ΕΒͷػೳΛࡌͨ͠ GitLab ແྉ Ͱ͍࢝ΊΔ͜ͱ͕Ͱ͖·͢ʂ
• ͳ͓ɺແঈ൛ʹҰ෦ػೳ੍ݶ͕͍͟͝·͢ɻ ࠓ͙͢ొ
ຊൃද͖͠Εͳ͔ͬͨ ECS Fargate पΓͷҠߦ ΞΠϦοδ։ൃऀϒϩά ʹͯ ެ։தʂ EC2 ͰՔಇ͍ͯ͠ΔγεςϜΛ ECS
Fargate ʹҠߦͤ͞Δ https://iridge-tech.hatenablog.com/entry/2019/04/24/162758