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
SSMRunbook作成の勘所_20241120
koichiotomo
2
130
Lexical Analysis
shigashiyama
1
150
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
180
Application Development WG Intro at AppDeveloperCon
salaboy
0
180
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
Engineer Career Talk
lycorp_recruit_jp
0
140
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Featured
See All Featured
Producing Creativity
orderedlist
PRO
341
39k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Statistics for Hackers
jakevdp
796
220k
Side Projects
sachag
452
42k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building Adaptive Systems
keathley
38
2.3k
Bash Introduction
62gerente
608
210k
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ͷ࠾༻ใ