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
最近 Fitbit をつけて散歩してるので CircleCI + Pixela で見えるように...
Search
Mitsuyuki Shiiba
March 16, 2022
Technology
1
310
最近 Fitbit をつけて散歩してるので CircleCI + Pixela で見えるようにしてみた
自動化LT会 ~自動化・効率化大好きな人集まれ!~
https://shiftevolve.connpass.com/event/237166/
のLTのスライドです
Mitsuyuki Shiiba
March 16, 2022
Tweet
Share
More Decks by Mitsuyuki Shiiba
See All by Mitsuyuki Shiiba
入社3ヶ月目のエンジニアから見たカケハシ
bufferings
6
1.6k
Dynamic Config の紹介 #CircleCIJP
bufferings
0
410
誰も嫌な思いをしない変化 #scrumosaka / Scrum Fest Osaka 2021 Keynote
bufferings
14
9.9k
#RSGT2021 Rethink Scrum from a Japanese cultural perspective
bufferings
2
10k
#RSGT2020 テックリードは未来の話をしよう / Tech Lead in Scrum
bufferings
39
30k
Introduction to Cypress
bufferings
3
3.7k
The Touch and Feel of Micronaut
bufferings
0
710
Introducing Micronaut
bufferings
1
770
Service Operation Centered Development
bufferings
3
6.2k
Other Decks in Technology
See All in Technology
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
27
12k
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
530
UI State設計とテスト方針
rmakiyama
2
470
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
520
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
1
1.3k
Storage Browser for Amazon S3
miu_crescent
1
140
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
100
生成AIのガバナンスの全体像と現実解
fnifni
1
180
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
Qiita埋め込み用スライド
naoki_0531
0
2.8k
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Unsuck your backbone
ammeep
669
57k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
It's Worth the Effort
3n
183
28k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
We Have a Design System, Now What?
morganepeng
51
7.3k
Transcript
1 ࠷ۙ Fitbit Λ͚ͭͯࢄาͯ͠ΔͷͰ CircleCI + Pixela Ͱݟ͑ΔΑ͏ʹͯ͠Έͨ 2022-03-16 ࣗಈԽLTձɹʙࣗಈԽɾޮԽେ͖ͳਓू·Εʂʙ
༿ ޫߦ (Twitter: @bufferings) Senior Full Stack Engineer, CircleCI
า͘ͱࣗಈͰ͕͑Δʔʂ 2 https://pixe.la/v1/users/bufferings/graphs/steps.html ΞΫηε 2022-03-14
3 ༿ ޫߦ (Twitter: @bufferings) Senior Full Stack Engineer, CircleCI
(202110݄ʙ) ࣗݾհ https://bufferings.hatenablog.com/entry/2022/02/27/150342
4 Free ϓϥϯͰेͳϏϧυ࣌ؒͰࣗಈԽՄೳ Free ϓϥϯͰ ेͳϏϧυ࣌ؒͰࣗಈԽՄೳ ɾຖ݄6,000૬ͷΫϨδο ɹτΛ༩ɺ࠷దͳϦιʔε
ɹΫϥε (CPU/RAM) ΛબՄೳ ɾϢʔβʔແ੍ݶ͔ͩΒ ɹνʔϜ։ൃʹద༻Մೳ ɾύϫϑϧͳϦιʔεΫϥεɺ ɹDocker ίϯςφVM(Linux, ɹWindows, Mac)Λར༻Մೳ ಉ࣌ؒ͡Ͱ CircleCI ͳΒ ར༻Մೳͳػೳ͕͜Μͳʹ ɾεϐʔυͱύϑΥʔϚϯε͕ ɹ্ɺDocker ίϯςφΛ࠷దԽ ɾϏϧυ͕ΑΓߴԽɺ ɹಉ࣌ʹ30ฒྻ࣮ߦ·ͰՄೳ ɾϓϥΠϕʔτ Orb Ͱ CI/CD ɹίϥϘϨʔγϣϯɺઃఆͷ ɹ෦Խɺ৫Ͱͷ࠶ར༻Մೳ ɾϏϧυ࣌ؒ̎ഒɺࣗಈԽ ɹͷ݁ՌΛΑΓૣ͘ಘΒΕ·͢ ϑΟʔυόοΫϧʔϓΛճ͠ ιϑτΣΞΛૉૣ͘ಧ͚Δ ɾϏϧυ࣌ؒΛॖՄೳͳͷ ɹδϣϒΛฒྻ࣮ߦͰ͖Δ͔Β ɾΠϯςϦδΣϯτʹςετ ɹ্ׂͨ͠Ͱฒྻ࣮ߦՄೳ ɹ(ϑΝΠϧɺϑΝΠϧαΠζɺ ɹ ϩά͔Βͷ࣮ߦ࣮࣌ؒͰׂ) ɾΠϯαΠτػೳͰࣦഊ͕ͪ͠ ɹͳςετ݁Ռ͕ෆ҆ఆͳςε ɹτͳͲΛநग़Մೳ Ϣʔβʔొ: https://circleci.com/ja/signup/ ྉۚϓϥϯ: https://circleci.com/ja/pricing/ αϙʔτ: https://support.circleci.com/hc/ja
5 ͦ͏ͩɺؾసʹίʔυΛॻ͜͏ʂ Fitbit Pixela
6 "ౙٳΈͷࣗ༝ݚڀ (3) ʙ ԶҰͲͷ͘Β͍ͬͯ (า͍ͯ) ͍Δͷ͔Λ Fitbit Web API
ͱ pixela ΛͬͯՄࢹԽ͢Δݕূ CircleCI Λఴ͑ͯ ʙ" https://inokara.hateblo.jp/entry/2020/01/03/132348ɹ ΞΫηε 2022-03-14 Α͏͍͞Μͷϒϩά
7 (1) Fitbit (2) Pixela (3) CircleCI ͦ͏ͩɺؾసʹίʔυΛॻ͜͏ʂ
8 Fitbit าΛऔಘ͢Δ
9 ❯ FITBIT_ACCESS_TOKEN="ΞΫηετʔΫϯ" ❯ curl -sX GET "https://api.fitbit.com/1/user/-/activities/steps/date/today/7d.json" \ -H
"accept: application/json" \ -H "authorization: Bearer $FITBIT_ACCESS_TOKEN" \ | jq { "activities-steps": [ { "dateTime": "2022-02-21", "value": "7204" }, ... Fitbit API Ͱۙ7ؒͷาΛऔಘ (1) Fitbit → (3) CircleCI → (2) Pixela Get Activity Time Series by Date https://dev.fitbit.com/build/reference/web-api/activity-timeseries/get-activity-timeseries-by-date/
10 Fitbit API ͷΞΫηετʔΫϯΛऔಘ (1) Fitbit → (3) CircleCI →
(2) Pixela 1. https://dev.fitbit.com/apps/new ͔ΒΞϓϦέʔγϣϯΛొ (*1) 2. OAuth 2.0 ͷ Authorization Code Flow ͰίʔυΛऔಘ (*2) 3. औಘͨ͠ίʔυΛ༻ͯ͠τʔΫϯΛऔಘ • (*1) ࣗ༻ͷμϛʔΞϓϦͳͷͰ URL શ෦ localhost ͰOK • (*2) OAuth 2.0 tutorial page ͕ศར
11 ❯ FITBIT_BASIC_TOKEN="Authorization: Basic ͷͱ͜ΖͷτʔΫϯ" ❯ FITBIT_REFRESH_TOKEN="ϦϑϨογϡτʔΫϯ" ❯ curl -sX
POST "https://api.fitbit.com/oauth2/token" \ -H "accept: application/json" \ -H "authorization: Basic $FITBIT_BASIC_TOKEN" \ -d "grant_type=refresh_token&refresh_token=$FITBIT_REFRESH_TOKEN" \ | jq { "access_token": "৽͍͠ΞΫηετʔΫϯ", ... "refresh_token": "৽͍͠ϦϑϨογϡτʔΫϯ", ... Fitbit API ͰτʔΫϯΛϦϑϨογϡ (1) Fitbit → (3) CircleCI → (2) Pixela Refresh Token https://dev.fitbit.com/build/reference/web-api/authorization/refresh-token/
12 Fitbit API ͷ·ͱΊ (1) Fitbit → (3) CircleCI →
(2) Pixela 1. ϦϑϨογϡτʔΫϯΛͬͯ৽͍͠ΞΫηετʔΫϯͱϦϑϨογϡτʔΫϯΛ औಘ 2. ৽͍͠ΞΫηετʔΫϯΛͬͯาΛऔಘ 3. ৽͍͠ϦϑϨογϡτʔΫϯ࣍ճͷͨΊʹอଘ͓ͯ͘͠
13 Pixela าΛॻ͖ࠐΉ
14 ❯ PIXELA_TOKEN="Pixela ʹొͨ͠τʔΫϯ" ❯ curl -sX POST "https://pixe.la/v1/users/bufferings/graphs" \
-H "X-USER-TOKEN:$PIXELA_TOKEN" \ -d '{"id":"demo-lt","name":"demo-lt","unit":"steps","type":"int", "color":"ichou","timezone":"Asia/Tokyo"}' {"message":"Success.","isSuccess":true} Pixela API ͰάϥϑΛ࡞ (1) Fitbit → (3) CircleCI → (2) Pixela POST - /v1/users/<username>/graphs https://docs.pixe.la/entry/post-graph
15 ❯ curl -sX PUT "https://pixe.la/v1/users/bufferings/graphs/demo-lt/20220310" \ -H "X-USER-TOKEN:$PIXELA_TOKEN" \
-d '{"quantity": "5000"}' {"message":"Success.","isSuccess":true} Pixela API ͰσʔλΛొ (1) Fitbit → (3) CircleCI → (2) Pixela POST - /v1/users/<username>/graphs https://docs.pixe.la/entry/post-graph
16 Script ίʔυʹ͢Δ
17 TypeScript Ͱॻ͍͓͍ͯͨɿ https://github.com/bufferings/fitbit-to-pixela/blob/main/src/main.ts ίʔυʹ͢Δ (1) Fitbit → (3) CircleCI
→ (2) Pixela
18 CircleCI ࣗಈԽ͢Δ
Node.js ͷ Orb (https://circleci.com/developer/ja/orbs/orb/circleci/node) Λ͏ͱศ རɻ͜Ε͚ͩͰ `npm run main` ͯ͘͠ΕΔɻΩϟογϡ໘Έͯ͘ΕΔɻ
19 config.yml Λ༻ҙ (1) Fitbit → (3) CircleCI → (2) Pixela
͋ͱ Project Settings > Environment Variables ͔ΒڥมΛઃఆͯ͋͛͠Εಈ͘ • Fitbit ༻
◦ FITBIT_BASIC_TOKEN ◦ FITBIT_REFRESH_TOKEN • Pixela ༻ ◦ PIXELA_GRAPH_URL ◦ PIXELA_TOKEN • CircleCI ༻ ◦ MY_CIRCLE_API_TOKEN ◦ MY_CIRCLE_PROJECT_SLUG 20 ϓϩδΣΫτʹڥมΛઃఆ (1) Fitbit → (3) CircleCI → (2) Pixela
User Settings > Personal API Tokens ͔ΒτʔΫϯΛੜ 21 ৽͍͠ϦϑϨογϡτʔΫϯΛอଘ͢Δ (1)
Fitbit → (3) CircleCI → (2) Pixela
22 ❯ MY_CIRCLE_PROJECT_SLUG="ϓϩδΣΫτͷύεɻྫ: github/bufferings/fitbit-to-pixela" ❯ MY_CIRCLE_API_TOKEN="ੜͨ͠τʔΫϯ" ❯ curl -sX POST
"https://circleci.com/api/v2/project/${MY_CIRCLE_PROJECT_SLUG}/envvar" \ -H "circle-token: $MY_CIRCLE_API_TOKEN" \ -H "content-type: application/json" \ -d '{"name":"FITBIT_REFRESH_TOKEN","value":"xxxx12345"}' \ { "name" : "FITBIT_REFRESH_TOKEN", "value" : "xxxx2345" } ৽͍͠ϦϑϨογϡτʔΫϯΛอଘ͢Δ (1) Fitbit → (3) CircleCI → (2) Pixela Create an environment variable https://circleci.com/docs/api/v2/#operation/createEnvVar ͜Μͳײ͡Ͱߋ৽Ͱ͖ΔͷͰɺεΫϦϓτʹॻ͍͓͍ͯͨ
Project Settings > Triggers Ͱఆظ࣮ߦ͞ΕΔΑ͏ʹઃఆ 23 ఆظతʹ࣮ߦ͞ΕΔΑ͏ʹ͢Δ (1) Fitbit →
(3) CircleCI → (2) Pixela
24 ఆظతʹ࣮ߦ͞ΕΔΑ͏ʹ͢Δ (1) Fitbit → (3) CircleCI → (2) Pixela
ಈ͍ͨʔʂ
25 (1) Fitbit (2) Pixela (3) CircleCI
า͘ͱࣗಈͰ͕͑Δʔʂ 26 https://pixe.la/v1/users/bufferings/graphs/steps.html ΞΫηε 2022-03-14
27 ݱࡏCircleCI JAPACΦϑΟεͰੵۃతʹԼهͷϙδγϣϯΛ࠾༻͓ͯ͠Γ·͢ʂ • Staff Infrastructure Enginee r • DevOps
Customer Enginee r • Senior Solutions Enginee r • Sales Development Representativ e • Enterprise Account Executiv e • Commercial Account Executive, APA C ͋Γ͕ͱ͏͍͟͝·ͨ͠ʔʂ CircleCIͷ࠾༻ใ