Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
700
Introducing Micronaut
bufferings
1
760
Service Operation Centered Development
bufferings
3
6.2k
Other Decks in Technology
See All in Technology
累計2500万着電を支える大規模 電話自動応答サービスのアーキテクチャ / Architecture of a Large-Scale Automated Phone Response Service Supporting 25 Million Cumulative Calls
ymachida
8
4.1k
ご挨拶
iotcomjpadmin
0
180
Entra ID の多要素認証(Japan Microsoft 365 コミュニティ カンファレンス 2024 )
murachiakira
0
1.5k
241130紅白ぺぱ合戦LT「編集の技術」
toya524287
5
550
ARRが3年で10倍になったプロダクト開発とAI活用の軌跡
akiroom
0
170
Hyperledger Fabric(再)入門
gakumura
3
6.7k
Amazon ECSとCloud Runの相互理解で広げるクラウドネイティブの景色 / Mutually understanding Amazon ECS and Cloud Run
iselegant
18
2.2k
asumikamというカンファレンスオーガナイザの凄さを語る / The Brilliance of Asumikam
tomzoh
1
160
クルマのサブスクを Next.jsで内製化した経験とその1年後
kintotechdev
2
400
TypeScript100%で作るMovable Typeプラグイン
usualoma
2
260
データ共有による新しい価値の創造
iotcomjpadmin
0
180
Yahoo! JAPANトップページにおけるマイクロフロントエンド - 大規模組織におけるFE開発を加速させるには
lycorptech_jp
PRO
0
1.7k
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Facilitating Awesome Meetings
lara
50
6.1k
Visualization
eitanlees
145
15k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Fireside Chat
paigeccino
34
3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Embracing the Ebb and Flow
colly
84
4.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Designing for humans not robots
tammielis
250
25k
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ͷ࠾༻ใ