diff --git a/kubernetes/tekton/README.md b/kubernetes/tekton/README.md index abebfdf..ddf4d28 100644 --- a/kubernetes/tekton/README.md +++ b/kubernetes/tekton/README.md @@ -1,5 +1,85 @@ # Tekton CI - The configurations in this directory are for automating lightwalletd operations using Tekton. -Currently new tags will trigger a docker build and push to https://hub.docker.com/r/electriccoinco/lightwalletd \ No newline at end of file +Currently new tags will trigger a docker build and push to https://hub.docker.com/r/electriccoinco/lightwalletd + +## Testing + +### Requirements +- `kind` installed +- `docker` installed +- A Docker Hub account (create a new one if you want, its free!) + +### Setup + +#### Log into Docker Hub +Just run the command: +``` +docker login +``` +This creates a `config.json` file that we're going to send to tekton and contains your Docker Hub password! + +More info: https://github.com/tektoncd/pipeline/blob/master/docs/auth.md + +#### Create a kind cluster +``` +kind create cluster --name tekton-testing-zcashd_exporter +``` +#### Create a Kubernetes secret containing your Docker hub creds +``` +kubectl create secret generic dockerhub-creds \ + --from-file=.dockerconfigjson=~/.docker/config.json \ + --type=kubernetes.io/dockerconfigjson +``` + +#### Create a service account to use those creds +``` +kubectl apply -f serviceaccount.yml +``` + +#### Install Tekton +``` +kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.15.2/release.yaml +kubectl apply -f https://github.com/tektoncd/dashboard/releases/download/v0.9.0/tekton-dashboard-release.yaml +``` +#### Install the Tekton Catalog tasks +These are predefined tasks from the `tektoncd/catalog` collection on github. + +``` +kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/git-clone/0.2/git-clone.yaml +kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/kaniko/0.1/kaniko.yaml +``` + +#### Create the pipeline +``` +kubectl apply -f pipeline.yml +``` + +#### Edit the `PipelineRun` + +This object holds all of your pipeline instance parameters. + +You **must** edit (unless somehow you got access to my Docker Hub account) +Change `electriccoinco` to your Docker Hub account name. +``` + - name: dockerHubRepo + value: electriccoinco/lightwalletd +``` +You can also change the `gitTag` and `gitRepositoryURL` values if you want to try building off some other commit, or you fork the code to your own repo. + +### Run the pipeline! + +You can do this as many times as you want, each one will create a new pipelinerun. +``` +kubectl create -f pipelinerun.yml +``` + + +### View the dashboard for status + +Forward a port from inside the kubernetes cluster to your laptop. +``` +kubectl --namespace tekton-pipelines port-forward svc/tekton-dashboard 9097:9097 & +``` + +The browse to http://localhost:9097/#/namespaces/default/pipelineruns \ No newline at end of file diff --git a/kubernetes/tekton/lightwalletd-tag-pipeline.yml b/kubernetes/tekton/lightwalletd-tag-pipeline.yml deleted file mode 100644 index eb9b3a1..0000000 --- a/kubernetes/tekton/lightwalletd-tag-pipeline.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -apiVersion: tekton.dev/v1beta1 -kind: Pipeline -metadata: - name: lightwalletd-tag-pipeline -spec: - resources: - - name: source - type: git - - name: cloudlog - type: cloudEvent - - name: lightwalletd-image - type: image - params: - - name: tagName - tasks: - - name: lightwalletd-build-docker-image - taskRef: - name: build-docker-image-from-git-source - resources: - inputs: - - name: docker-source - resource: source - outputs: - - name: builtImage - resource: lightwalletd-image - - name: notification - resource: cloudlog \ No newline at end of file diff --git a/kubernetes/tekton/pipeline.yml b/kubernetes/tekton/pipeline.yml new file mode 100644 index 0000000..ca9148e --- /dev/null +++ b/kubernetes/tekton/pipeline.yml @@ -0,0 +1,39 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: lightwalletd-tag-pipeline +spec: + params: + - name: gitTag + - name: gitRepositoryURL + - name: dockerHubRepo + workspaces: + - name: source + tasks: + - name: git-clone + taskRef: + name: git-clone + workspaces: + - name: output + workspace: source + params: + - name: url + value: $(params.gitRepositoryURL) + - name: revision + value: $(params.gitTag) + - name: refspec + value: +refs/tags/*:refs/remotes/origin/tags/* +refs/heads/*:refs/heads/* + - name: verbose + value: "true" + - name: kaniko-build + taskRef: + name: kaniko + runAfter: + - git-clone + params: + - name: IMAGE + value: $(params.dockerHubRepo):$(params.gitTag) + workspaces: + - name: source + workspace: source \ No newline at end of file diff --git a/kubernetes/tekton/pipelinerun.yml b/kubernetes/tekton/pipelinerun.yml new file mode 100644 index 0000000..dd7d8a9 --- /dev/null +++ b/kubernetes/tekton/pipelinerun.yml @@ -0,0 +1,25 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + generateName: lightwalletd-tag-pipeline- +spec: + serviceAccountName: ecc-tekton + pipelineRef: + name: lightwalletd-tag-pipeline + workspaces: + - name: source + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + params: + - name: gitTag + value: GetMempoolTx + - name: gitRepositoryURL + value: https://github.com/zcash/lightwalletd.git + - name: dockerHubRepo + value: electriccoinco/lightwalletd diff --git a/kubernetes/tekton/serviceaccount.yml b/kubernetes/tekton/serviceaccount.yml new file mode 100644 index 0000000..4178dd1 --- /dev/null +++ b/kubernetes/tekton/serviceaccount.yml @@ -0,0 +1,7 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: ecc-tekton +secrets: + - name: dockerhub-creds \ No newline at end of file diff --git a/kubernetes/tekton/triggerbinding.yml b/kubernetes/tekton/triggerbinding.yml deleted file mode 100644 index 356f9a4..0000000 --- a/kubernetes/tekton/triggerbinding.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -apiVersion: triggers.tekton.dev/v1alpha1 -kind: TriggerBinding -metadata: - name: lightwalletd-tag-binding -spec: - params: - - name: dockerImageName - value: electriccoinco/lightwalletd - - name: tagName - value: $(body.extensions.tag) - - name: gitRepositoryURL - value: $(body.repository.clone_url) diff --git a/kubernetes/tekton/triggers.yml b/kubernetes/tekton/triggers.yml new file mode 100644 index 0000000..ebecb9e --- /dev/null +++ b/kubernetes/tekton/triggers.yml @@ -0,0 +1,51 @@ +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + name: lightwalletd-tag-binding +spec: + params: + - name: gitTag + value: $(body.tag) + - name: gitRepositoryURL + value: $(body.repository.git_http_url) + - name: dockerHubRepo + value: electriccoinco/zcashd_exporter +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerTemplate +metadata: + name: lightwalletd-tag-pipeline-template +spec: + params: + - name: gitTag + description: Git tag + - name: gitRepositoryURL + description: Git repo url + - name: dockerHubRepo + description: Docker Hub repository name + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: lightwalletd-tag-pipeline- + spec: + serviceAccountName: ecc-tekton + pipelineRef: + name: lightwalletd-tag-pipeline + workspaces: + - name: source + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + params: + - name: gitRepositoryURL + value: $(params.gitRepositoryURL) + - name: gitTag + value: $(params.gitTag) + - name: dockerHubRepo + value: $(params.dockerHubRepo) diff --git a/kubernetes/tekton/triggertemplate.yml b/kubernetes/tekton/triggertemplate.yml deleted file mode 100644 index f1a61da..0000000 --- a/kubernetes/tekton/triggertemplate.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -apiVersion: triggers.tekton.dev/v1alpha1 -kind: TriggerTemplate -metadata: - name: lightwalletd-tag-pipeline-template -spec: - params: - - name: gitRepositoryURL - description: Git repo url - - name: tagName - description: Release tag name - resourcetemplates: - - apiVersion: tekton.dev/v1beta1 - kind: PipelineRun - metadata: - generateName: lightwalletd-tag-pipeline- - spec: - serviceAccountName: ecc-tekton - pipelineRef: - name: lightwalletd-tag-pipeline - resources: - - name: source - resourceSpec: - type: git - params: - - name: revision - value: $(params.tagName) - - name: url - value: $(params.gitRepositoryURL) - - name: refspec - value: "+refs/tags/*:refs/remotes/origin/tags/*" - - name: lightwalletd-image - resourceSpec: - type: image - params: - - name: url - value: electriccoinco/lightwalletd:$(params.tagName) - - name: cloudlog - resourceSpec: - type: cloudEvent - params: - - name: targetURI - value: http://cloudlog:8080/inbox - params: - - name: gitRepositoryURL - value: $(params.gitRepositoryURL) - - name: tagName - value: $(params.tagName)