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
300
最近 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
400
誰も嫌な思いをしない変化 #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
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
200
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
200
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Taming you application's environments
salaboy
0
180
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
500
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
250
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
AIチャットボット開発への生成AI活用
ryomrt
0
170
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Producing Creativity
orderedlist
PRO
341
39k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
KATA
mclloyd
29
14k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Unsuck your backbone
ammeep
668
57k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Building Applications with DynamoDB
mza
90
6.1k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Site-Speed That Sticks
csswizardry
0
23
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ͷ࠾༻ใ