buildkit-template.yaml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # SUMMARY:
  2. #
  3. # Build and push an image using Docker Buildkit.
  4. #
  5. # DESCRIPTION:
  6. #
  7. # This does not need privileged access, unlike Docker in Docker (DIND). It has three stages:
  8. #
  9. # * clone the Git repository
  10. # * build the binary
  11. # * build and push the image containing the binary
  12. #
  13. # USAGE:
  14. #
  15. # Publishing images requires an access token. For hub.docker.com you can create one at https://hub.docker.com/settings/security
  16. # This needs to be mounted as `$DOCKER_CONFIG/config.json`. To do this, you'll need to create a secret as follows:
  17. #
  18. # export DOCKER_USERNAME=******
  19. # export DOCKER_TOKEN=******
  20. # kubectl create secret generic docker-config --from-literal="config.json={\"auths\": {\"https://index.docker.io/v1/\": {\"auth\": \"$(echo -n $DOCKER_USERNAME:$DOCKER_TOKEN|base64)\"}}}"
  21. #
  22. # REFERENCES:
  23. #
  24. # * https://github.com/moby/buildkit#expose-buildkit-as-a-tcp-service
  25. # * https://blog.alexellis.io/building-containers-without-docker/
  26. # * https://hub.docker.com/r/moby/buildkit
  27. #
  28. apiVersion: argoproj.io/v1alpha1
  29. kind: WorkflowTemplate
  30. metadata:
  31. name: buildkit
  32. spec:
  33. arguments:
  34. parameters:
  35. - name: repo
  36. value: https://github.com/argoproj/argo-workflows
  37. - name: branch
  38. value: master
  39. - name: path
  40. value: test/e2e/images/argosay/v2
  41. - name: image
  42. value: alexcollinsintuit/argosay:v2
  43. entrypoint: main
  44. # We use a volume claim template so that we can have a shared workspace.
  45. volumeClaimTemplates:
  46. - metadata:
  47. name: work
  48. spec:
  49. accessModes: [ "ReadWriteOnce" ]
  50. resources:
  51. requests:
  52. storage: 64Mi
  53. templates:
  54. - name: main
  55. dag:
  56. tasks:
  57. - name: clone
  58. template: clone
  59. arguments:
  60. parameters:
  61. - name: repo
  62. value: "{{workflow.parameters.repo}}"
  63. - name: branch
  64. value: "{{workflow.parameters.branch}}"
  65. - name: build
  66. template: build
  67. arguments:
  68. parameters:
  69. - name: path
  70. value: "{{workflow.parameters.path}}"
  71. depends: "clone"
  72. - name: image
  73. template: image
  74. arguments:
  75. parameters:
  76. - name: path
  77. value: "{{workflow.parameters.path}}"
  78. - name: image
  79. value: "{{workflow.parameters.image}}"
  80. depends: "build"
  81. - name: clone
  82. inputs:
  83. parameters:
  84. - name: repo
  85. - name: branch
  86. container:
  87. volumeMounts:
  88. - mountPath: /work
  89. name: work
  90. image: alpine/git:v2.26.2
  91. workingDir: /work
  92. # Do a shallow clone, which is the fastest way to clone, by using the
  93. # --depth, --branch, and --single-branch options
  94. args:
  95. - clone
  96. - --depth
  97. - "1"
  98. - --branch
  99. - "{{inputs.parameters.branch}}"
  100. - --single-branch
  101. - "{{inputs.parameters.repo}}"
  102. - .
  103. - name: build
  104. inputs:
  105. parameters:
  106. - name: path
  107. container:
  108. image: golang:1.13
  109. volumeMounts:
  110. - mountPath: /work
  111. name: work
  112. workingDir: /work/{{inputs.parameters.path}}
  113. env:
  114. # Because this is not a Gomodule, we must turn modules off.
  115. - name: GO111MODULE
  116. value: "off"
  117. command:
  118. - go
  119. args:
  120. - build
  121. - -v
  122. - -o
  123. - argosay
  124. - ./...
  125. - name: image
  126. inputs:
  127. parameters:
  128. - name: path
  129. - name: image
  130. # Mount the configuration so we can push the image.
  131. # This should create the /.docker/config.json file.
  132. volumes:
  133. - name: docker-config
  134. secret:
  135. secretName: docker-config
  136. container:
  137. readinessProbe:
  138. exec:
  139. command: [ sh, -c, "buildctl debug workers" ]
  140. image: moby/buildkit:v0.9.3-rootless
  141. volumeMounts:
  142. - name: work
  143. mountPath: /work
  144. - name: docker-config
  145. mountPath: /.docker
  146. workingDir: /work/{{inputs.parameters.path}}
  147. env:
  148. - name: BUILDKITD_FLAGS
  149. value: --oci-worker-no-process-sandbox
  150. - name: DOCKER_CONFIG
  151. value: /.docker
  152. command:
  153. - buildctl-daemonless.sh
  154. args:
  155. - build
  156. - --frontend
  157. - dockerfile.v0
  158. - --local
  159. - context=.
  160. - --local
  161. - dockerfile=.
  162. - --output
  163. - type=image,name=docker.io/{{inputs.parameters.image}},push=true