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
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
840
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
12
3.5k
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
550
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
730
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
CustomCopを使ってMongoidのコーディングルールを整えてみた
jinoketani
0
220
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
190
20241220_S3 tablesの使い方を検証してみた
handy
3
330
podman_update_2024-12
orimanabu
1
260
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
160
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
180
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
210
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
Build your cross-platform service in a week with App Engine
jlugia
229
18k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Done Done
chrislema
181
16k
YesSQL, Process and Tooling at Scale
rocio
169
14k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
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ͷ࠾༻ใ