Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dive into BuildKit LLB with GO

Dive into BuildKit LLB with GO

Go Conference Tokyo 2019 Spring の発表資料です。

H6 (S): Dive into Buildkit LLB with Go
Dockerに正式統合されたBuildKitをGoで扱う方法について発表します。

BuildKit は Goで実装されている為、Goのソースコードを読むことでGoを使ったDockerfile解析ツールや、独自のBuildKit LLB frontendを作成できます。

今回の発表ではGoでどのようにBuildkitが記述されているかをコードを追いながら、Goを使ったDockerfile解析ツールの作り方や、独自のコンテナイメージフロントエンドの作り方にも触れて行く為、Goでコンテナ技術を理解する大きな1歩になるでしょう。

po3rin

May 18, 2019
Tweet

More Decks by po3rin

Other Decks in Programming

Transcript

  1. Dive into BuildKit & LLB with Go Gopher Conference Tokyo

    2019 Spring April 12, 2019 @ po3rin
  2. QBHF ɾ#FDPNFBMJUUMFNPSFGBNJMJBSXJUI CVJMEJOHDPOUBJOFSJNBHFCZSFBEJOH(P ɾ"GPPUIPMEUPDSFBUFDPOUBJOFSSFMBUFE UPPMTXJUI(P Ὂ the benefits of this

    talk
  3. @po3rin Software Enginner @ Shiroyagi Corporation QBHF Golang / Python

    / Rust / Docker / AWS / Elasticsearch
  4. QBHF Introduction \

  5. QBHF .PCZJTBOPQFOGSBNFXPSLDSFBUFECZ %PDLFSUPBTTFNCMFTQFDJBMJ[FE DPOUBJOFSTZTUFNTXJUIPVUSFJOWFOUJOH UIFXIFFM What is Moby Ὂ IUUQTHJUIVCDPNNPCZ

  6. QBHF What is BuildKit #VJME,JUJTBUPPMLJUGPS DPOWFSUJOHTPVSDFDPEFUP CVJMEBSUJGBDUTJOBO F⒏DJFOU FYQSFTTJWFBOE SFQFBUBCMFNBOOFS

    Ὂ IUUQTHJUIVCDPNNPCZNPCZJTTVFT
  7. QBHF CVJMELJUE CVJMEEFBNPO CVJMEDUM DPNNVOJDBUFT XJUICVJMELJUE H31$ buildctl & buildkitd

    Ὂ 5IFCVJMELJUEEBFNPOTVQQPSUTUXPXPSLFSCBDLFOET0$* SVOD BOEDPOUBJOFSE
  8. QBHF BuildKit is written in Go !! Ὂ

  9. QBHF Reading Go source code of BuildKit \

  10. QBHF A foothold to read Go source code (1) Ὂ

    CVJMEDUMVTFT HJUIVCDPNVSGBWFDMJ QBDLBHF
  11. QBHF A foothold to read Go source code (2) Ὂ

    CVJMEDUMCVJMEDBMMT DMJFOU4PMWFNFUIPE8IBUJT UIFBSHVNFOUDBMMFEMMC 
  12. QBHF 7FSUFY &EHF 7FSUFY "UUIFDPSFPG#VJME,JUJTBOFXMPX MFWFMCVJMEEFpOJUJPOGPSNBUDBMMFE --# MPXMFWFMCVJMEFS  --#SFBMJ[FTQBSBMMFMFYFDVUJPOPG

    JOTUSVDUJPOTCZFYQSFTTJOH EFQFOEFODZBNPOHJOTUSVDUJPOTPG %PDLFSpMFBT%"( EJSFDUFEBDZDMJD HSBQI  Ὂ LLB
  13. QBHF TPMWFSQEPQTQSPUP DPOUBJOTUIFTQFDJpDBUJPO PGUIF--#TUSVDUVSF

  14. QBHF FYBNQMF

  15. QBHF *OQVUTSFQSFTFOUJOQVUFEHFT GSPNPUIFS0QT5IJT SFQSFTFOUTUIF%"( TUSVDUVSF *OQVUT

  16. QBHF MMCEPUQBDLBHFMFUTZPV UPDPOWFSU#VJME,JU--# UPEPUMBOHVBHFUP BOBMJ[F Ὂ Look inside of LLB

    (1)
  17. QBHF Ὂ Look inside of LLB (2)

  18. QBHF CVJMELJUE CVJMEDUM H31$ buildctl & buildkitd Ὂ 4PMWF

  19. QBHF 5IF--#JTHFOFSBUFECZ DPOWFSUJOHBOBSCJUSBSZJOQVU 'JOBMMZ CVJMEEFBNPOPVUQVUTCVJME BSUJGBDUTJOUIFTQFDJpFEFYQPSUFS GPSNBU UIFSJHIUpHVSFFYQMBJOT FYBNQMFPG%PDLFS 

    'SPOUFOE --# %PDLFSpMF HSQD XPSLFS CVJMELJUE FYQPSU %PDLFSJNBHF DPOWFSU Build procedure Ὂ
  20. QBHF Generetes LLB From Dockerfile (1) Ὂ 'SPOUFOE --# %PDLFSpMF

    DPOWFSU
  21. QBHF 'PSFYBNQMF MMCEPUVTFT %PDLFSpMF--#GVODJOUFSOBMMZ Generetes LLB From Dockerfile (2) Ὂ

  22. QBHF Inside Dockerfile2LLB Ὂ %PDLFSpMF %PDLFSpMF"45 #VJMEBCMF4UBHFT --# 'JSTUPG"MM %PDLFSpMF1BSTFS

    HFOFSBUFT%PDLFSpMF"45'SPN UIFSF JUDSFBUFT#--UISPVHI WBSJPVTQSPDFTTFT
  23. QBHF %PDLFSpMF %PDLFSpMF"45 #VJMEBCMF4UBHFT --#

  24. QBHF Node Construction Ὂ

  25. QBHF 6TJOHUIJTGVODUJPO ZPVDBOBMTP DSFBUF%PDLFSpMF-JOUFSGSPN"45

  26. QBHF %PDLFSpMF %PDLFSpMF"45 #VJMEBCMF4UBHFT --#

  27. QBHF DMJFOUMMCQBDLBHFQSPWJEFTUIF--#$MJFOU"1*UP HFOFSBUF--#5IJTQSPWJEFTCVJMEJOHCMPDLTUIJT. 5IFDPEFCFMPXJTBOFYBNQMFPGHFOFSBUJOHMMC VTJOHMMCDMJFOU %PDLFSpMF %PDLFSpMF"45 #VJMEBCMF4UBHFT --# FYBNQMFHJUIVCDPNNPCZCVJMELJUFYBNQMFT

  28. QBHF Develop BuildKit LLB frontend with Go \

  29. QBHF 'PDVTJOHPOUIFCVJMEqPX JGZPV DBOHFOFSBUF--# 'SPOUFOEJT HPPEGPSBOZUIJOH 'SPOUFOE --# %PDLFSpMF HSQD

    #VJMELJUE CVJMEEFBNPO FYQPSU %PDLFSJNBHF DPOWFSU
  30. QBHF 'SPOUFOE --# %PDLFSpMF HSQD #VJMELJUE CVJMEEFBNPO FYQPSU %PDLFSJNBHF DPOWFSU

    0SJHJOBM'SPOUFOE *OPUIFSXPSET JUJTQPTTJCMFUP JNQMFNFOUBOEQVCMJTIUIF PSJHJOBMGSPOUFOE
  31. QBHF (PDLFSpMFJTB#VJME,JU --#GSPOUFOEUIBUDBO HFOFSBUFNVMUJTUBHFCVJMU (P"1*JNBHFTJOKVTUUISFF MJOFT Example of Original BuildKit

    LLB frontend Ὂ
  32. QBHF 'SPOUFOE (PDLFSpMF (PTFSWFS%PDLFSJNBHF

  33. QBHF Easy way to Create Custom Frontend Ὂ $SFBUFDPOWFSTJPOQSPDFTTGSPN BSCJUSBSZGPSNBUUP--#

    6TF(BUFXBZ"1*QSPWJEFECZ CVJMELJU #JOBSZJ[FUIFQSPDFTTBOEQVCMJTIJU BTB%PDLFSJNBHF 1 2 3
  34. QBHF Use BuildKit Gateway API (1) Ὂ &YBNQMFPG$BMMJOH 3VO'SPN&OWJSPONFOUJONBJO QBDLBHF

  35. QBHF #VJME'VODOFFETUP HFUBDPOpHVSBUJPO pMFJOPSJHJOBM GPSNBU DPOWFSUJUUP --# BOEQBTTJUUP 4PMWF UPFYFDVUF

    CVJMEXJUIXPSLFS Use BuildKit Gateway API (2) Ὂ
  36. QBHF --#$MJFOU"1*DPNCJOFT4PVSDFBOE3VOPQFSBUJPOT 3VO ʜ 3PPU 4UBUF &YFD4UBUF MMC*NBHF ʜ Create

    conversion process from arbitrary format to LLB (2) Ὂ
  37. "EE.PVOU ʜ QBHF "EE.PVOUBMMPXTNPVOUJOHPGpMFTGSPNPUIFS0Q"MJUUMFDPNQMJDBUFE 3VO ʜ 3PPU 3VO ʜ Create

    conversion process from arbitrary format to LLB (3) Ὂ
  38. QBHF .FSHFEpMF0QJO.BSDI Create conversion process from arbitrary format to LLB

    (3) Ὂ
  39. QBHF Binaryize the process and publish it as a Docker

    image Ὂ
  40. QBHF 'SPOUFOE (PDLFSpMF (PTFSWFS%PDLFSJNBHF QPSJOHPDLFSMBUFTU -PBEFEBTBDPOUBJOFSJNBHF GSPNSFHJTUSZBOESVOJOB TFDVSFTBOECPYKVTUBTZPVS SFHVMBSDPOUBJOFST MPBEJNBHFDPOpH

  41. QBHF Conclusion \

  42. QBHF Conclusion Ὂ *GZPVDBOSFBE(P ZPVDBOHFUBEFFQFSVOEFSTUBOEJOHPGUIF DPOUBJOFSUFDIOPMPHZZPVBSFVTJOHDBTVBMMZ"OEZPVDBOIBDLUIF JNBHFCVJMEVTJOH(P

  43. QBHF Reference Ὂ #VJME,JU3FQPTJUPSZ IUUQTHJUIVCDPNNPCZCVJMELJU #VJME,JUʹΑΔߴ଎ͰηΩϡΞͳΠϝʔδϏϧυ εϥΠυ  IUUQTXXXTMJEFTIBSFOFU"LJIJSP4VEBCVJMELJU (FUUJOH4UBSUFE#VJME,JU

    CVJMEDUMCVJMELJUE)BOETPO  IUUQTHFPSHFNBDSPSFQPTUTHFUUJOHTUBSUFEXJUICVJMELJU
  44. QBHF Follow @po3rin !! Ὂ

  45. Dive into BuildKit & LLB with Go Gopher Conference Tokyo

    2019 Spring April 12, 2019 @ po3rin
  46. QBHF Additional Talk \

  47. QBHF Use BuildKit Gateway API (3) Ὂ 3VO'SPN&OWJSPONFOUVTFT --##SJHEHF$MJFOUJOUFSOBMZ (BUFXBZ"1*

    'SPOUFOE 3VOT*OEPDLFSDPOUBJOFS
  48. QBHF Use BuildKit Gateway API (4) Ὂ 4PMWF $MJFOU FYCVJMEDUM

    $POUPMMFS (BUFXBZ"1* 'SPOUFOE 3VOT*OEPDLFSDPOUBJOFS