Skip to content

Commit

Permalink
docs: Add buildkit example. Closes argoproj#2325 (argoproj#4008)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Sep 16, 2020
1 parent fc77bee commit 513ed9f
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ WorkflowTemplate is the definition of a workflow template resource
<summary>Examples (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`cron-backfill.yaml`](https://github.com/argoproj/argo/blob/master/examples/cron-backfill.yaml)

- [`templates.yaml`](https://github.com/argoproj/argo/blob/master/examples/workflow-template/templates.yaml)
Expand Down Expand Up @@ -351,6 +353,8 @@ WorkflowSpec is the specification of a Workflow.

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -694,6 +698,8 @@ CronWorkflowSpec is the specification of a CronWorkflow

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -999,6 +1005,8 @@ WorkflowTemplateSpec is a spec of WorkflowTemplate.

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -1317,6 +1325,8 @@ Arguments to a template

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -1561,6 +1571,8 @@ Template is a reusable and composable unit of execution in a workflow

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -2127,6 +2139,8 @@ Parameter indicate a passed string parameter to a service template with an optio

- [`artifact-path-placeholders.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifact-path-placeholders.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -2359,6 +2373,8 @@ DAGTemplate is a template subtype for directed acyclic graph templates
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`cluster-wftmpl-dag.yaml`](https://github.com/argoproj/argo/blob/master/examples/cluster-workflow-template/cluster-wftmpl-dag.yaml)

- [`clustertemplates.yaml`](https://github.com/argoproj/argo/blob/master/examples/cluster-workflow-template/clustertemplates.yaml)
Expand Down Expand Up @@ -2469,6 +2485,8 @@ Inputs are the mechanism for passing parameters, artifacts, volumes from one tem

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -2635,6 +2653,8 @@ Pod metdata

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -3372,6 +3392,8 @@ GitArtifact is the location of an git artifact
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -3640,6 +3662,8 @@ DAGTask represents a node in the graph during DAG execution
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`cluster-wftmpl-dag.yaml`](https://github.com/argoproj/argo/blob/master/examples/cluster-workflow-template/cluster-wftmpl-dag.yaml)

- [`clustertemplates.yaml`](https://github.com/argoproj/argo/blob/master/examples/cluster-workflow-template/clustertemplates.yaml)
Expand Down Expand Up @@ -3920,6 +3944,8 @@ ObjectMeta is metadata that all persisted resources must have, which includes al

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -4320,6 +4346,8 @@ PersistentVolumeClaim is a user's request for and claim to a persistent volume
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -4348,6 +4376,8 @@ Volume represents a named volume in a pod that may be accessed by any container
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`init-container.yaml`](https://github.com/argoproj/argo/blob/master/examples/init-container.yaml)

- [`secrets.yaml`](https://github.com/argoproj/argo/blob/master/examples/secrets.yaml)
Expand Down Expand Up @@ -4448,6 +4478,8 @@ A single application container that you want to run within a pod.

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -4710,6 +4742,8 @@ EnvVar represents an environment variable present in a Container.
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`colored-logs.yaml`](https://github.com/argoproj/argo/blob/master/examples/colored-logs.yaml)

- [`secrets.yaml`](https://github.com/argoproj/argo/blob/master/examples/secrets.yaml)
Expand Down Expand Up @@ -4789,6 +4823,8 @@ ResourceRequirements describes the compute resource requirements.
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -4859,6 +4895,8 @@ VolumeMount describes a mounting of a Volume within a container.
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -5074,6 +5112,8 @@ PersistentVolumeClaimSpec describes the common attributes of storage devices and

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -5690,6 +5730,8 @@ Adapts a Secret into a volume.The contents of the target Secret's Data field wil
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`secrets.yaml`](https://github.com/argoproj/argo/blob/master/examples/secrets.yaml)
</details>

Expand Down Expand Up @@ -6085,6 +6127,8 @@ ListMeta describes metadata that synthetic resources must have, including lists

- [`artifactory-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/artifactory-artifact.yaml)

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`ci-output-artifact.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci-output-artifact.yaml)

- [`ci.yaml`](https://github.com/argoproj/argo/blob/master/examples/ci.yaml)
Expand Down Expand Up @@ -6393,6 +6437,8 @@ Adapts a secret into a projected volume.The contents of the target Secret's Data
<summary>Examples with this field (click to open)</summary>
<br>

- [`buildkit-template.yaml`](https://github.com/argoproj/argo/blob/master/examples/buildkit-template.yaml)

- [`secrets.yaml`](https://github.com/argoproj/argo/blob/master/examples/secrets.yaml)
</details>

Expand Down
162 changes: 162 additions & 0 deletions examples/buildkit-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# SUMMARY:
#
# Build and push an image using Docker Buildkit.
#
# DESCRIPTION:
#
# This does not need privileged access, unlike Docker in Docker (DIND). It has three stages:
#
# * clone the Git repository
# * build the binary
# * build and push the image containing the binary
#
# USAGE:
#
# Publishing images requires an access token. For hub.docker.com you can create one at https://hub.docker.com/settings/security
# This needs to be mounted as `$DOCKER_CONFIG/config.json`. To do this, you'll need to create a secret as follows:
#
# export DOCKER_USERNAME=******
# export DOCKER_TOKEN=******
# kubectl create secret generic docker-config --from-literal="config.json={\"auths\": {\"https://index.docker.io/v1/\": {\"auth\": \"$(echo -n $DOCKER_USERNAME:$DOCKER_TOKEN|base64)\"}}}"
#
# REFERENCES:
#
# * https://github.com/moby/buildkit#expose-buildkit-as-a-tcp-service
# * https://blog.alexellis.io/building-containers-without-docker/
# * https://hub.docker.com/r/moby/buildkit
#
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: buildkit
spec:
arguments:
parameters:
- name: repo
value: https://github.com/argoproj/argo
- name: branch
value: master
- name: path
value: test/e2e/images/argosay/v2
- name: image
value: alexcollinsintuit/argosay:v2
entrypoint: main
# We use a volume claim template so that we can have a shared workspace.
volumeClaimTemplates:
- metadata:
name: work
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 64Mi
templates:
- name: main
dag:
tasks:
- name: clone
template: clone
arguments:
parameters:
- name: repo
value: "{{workflow.parameters.repo}}"
- name: branch
value: "{{workflow.parameters.branch}}"
- name: build
template: build
arguments:
parameters:
- name: path
value: "{{workflow.parameters.path}}"
dependencies:
- clone
- name: image
template: image
arguments:
parameters:
- name: path
value: "{{workflow.parameters.path}}"
- name: image
value: "{{workflow.parameters.image}}"
dependencies:
- build
- name: clone
inputs:
parameters:
- name: repo
- name: branch
container:
volumeMounts:
- mountPath: /work
name: work
image: alpine/git:v2.26.2
workingDir: /work
# Do a shallow clone, which is the fastest way to clone, by using the
# --depth, --branch, and --single-branch options
args:
- clone
- --depth
- "1"
- --branch
- "{{inputs.parameters.branch}}"
- --single-branch
- "{{inputs.parameters.repo}}"
- .
- name: build
inputs:
parameters:
- name: path
container:
image: golang:1.13
volumeMounts:
- mountPath: /work
name: work
workingDir: /work/{{inputs.parameters.path}}
env:
# Because this is not a Gomodule, we must turn modules off.
- name: GO111MODULE
value: "off"
command:
- go
args:
- build
- -v
- -o
- argosay
- ./...
- name: image
inputs:
parameters:
- name: path
- name: image
# Mount the configuration so we can push the image.
# This should create the /.docker/config.json file.
volumes:
- name: docker-config
secret:
secretName: docker-config
container:
image: moby/buildkit:v0.7.2-rootless
volumeMounts:
- name: work
mountPath: /work
- name: docker-config
mountPath: /.docker
workingDir: /work/{{inputs.parameters.path}}
env:
- name: BUILDKITD_FLAGS
value: --oci-worker-no-process-sandbox
- name: DOCKER_CONFIG
value: /.docker
command:
- buildctl-daemonless.sh
args:
- build
- --frontend
- dockerfile.v0
- --local
- context=.
- --local
- dockerfile=.
- --output
- type=image,name=docker.io/{{inputs.parameters.image}},push=true

0 comments on commit 513ed9f

Please sign in to comment.