You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
231 lines
5.7 KiB
231 lines
5.7 KiB
apiVersion: tekton.dev/v1beta1
|
|
kind: Pipeline
|
|
metadata:
|
|
name: msbdeployment-pipeline
|
|
spec:
|
|
description: |
|
|
Run all tasks
|
|
params:
|
|
- name: repo-url
|
|
type: string
|
|
description: The git repository URL to clone from.
|
|
- name: branch-name
|
|
type: string
|
|
description: The git branch to clone.
|
|
- name: version
|
|
type: string
|
|
description: version
|
|
- name: image
|
|
type: string
|
|
description: build image
|
|
- name: app-name
|
|
type: string
|
|
description: Argocd Application name
|
|
- name: deploy-repo-url
|
|
type: string
|
|
description: Argocd repo url
|
|
- name: deploy-branch-name
|
|
type: string
|
|
description: Argocd branch name
|
|
workspaces:
|
|
- name: shared-data
|
|
description: |
|
|
save code
|
|
tasks:
|
|
- name: fetch-repo
|
|
taskRef:
|
|
name: git-clone
|
|
workspaces:
|
|
- name: output
|
|
workspace: shared-data
|
|
params:
|
|
- name: url
|
|
value: $(params.repo-url)
|
|
- name: revision
|
|
value: $(params.branch-name)
|
|
- name: pre-do
|
|
retries: 5
|
|
runAfter:
|
|
- fetch-repo
|
|
workspaces:
|
|
- name: source
|
|
workspace: shared-data
|
|
taskRef:
|
|
name: pre-do
|
|
params:
|
|
- name: version
|
|
value: $(params.version)
|
|
- name: kaniko
|
|
retries: 5
|
|
taskRef:
|
|
name: kaniko
|
|
runAfter:
|
|
- pre-do
|
|
workspaces:
|
|
- name: source
|
|
workspace: shared-data
|
|
params:
|
|
- name: IMAGE
|
|
value: $(params.image):$(params.version)
|
|
- name: EXTRA_ARGS
|
|
value:
|
|
- --skip-tls-verify
|
|
- --insecure
|
|
- --skip-tls-verify-pull
|
|
- --insecure-pull
|
|
- name: verify-digest
|
|
runAfter:
|
|
- kaniko
|
|
params:
|
|
- name: digest
|
|
value: $(tasks.kaniko.results.IMAGE_DIGEST)
|
|
taskSpec:
|
|
params:
|
|
- name: digest
|
|
steps:
|
|
- name: bash
|
|
image: ubuntu
|
|
script: |
|
|
echo $(params.digest)
|
|
case .$(params.digest) in
|
|
".sha"*) exit 0 ;;
|
|
*) echo "Digest value is not correct" && exit 1 ;;
|
|
esac
|
|
- name: verify-url
|
|
runAfter:
|
|
- kaniko
|
|
params:
|
|
- name: url
|
|
value: $(tasks.kaniko.results.IMAGE_URL)
|
|
taskSpec:
|
|
params:
|
|
- name: url
|
|
steps:
|
|
- name: bash
|
|
image: ubuntu
|
|
script: |
|
|
echo $(params.url)
|
|
case .$(params.url) in
|
|
*"/deployment/msbdeployment:"*) exit 0 ;;
|
|
*) echo "URL value is not correct" && exit 1 ;;
|
|
esac
|
|
- name: kind
|
|
retries: 5
|
|
taskRef:
|
|
name: kind
|
|
params:
|
|
- name: command
|
|
value:
|
|
- sh
|
|
- -c
|
|
- "docker network create --driver=bridge --subnet=172.19.0.0/16 --gateway=172.19.0.1 kind && \
|
|
cd $(workspaces.source.path)/test/e2e && \
|
|
export CGO_ENABLED=0 && \
|
|
export GOPROXY=https://goproxy.cn && \
|
|
export IMG=$(tasks.kaniko.results.IMAGE_URL) && \
|
|
go test -tags=e2e -config config.yaml -startup-timeout 7200 -test.timeout=120m"
|
|
- name: image
|
|
value: docker.io/library/docker-kind:v0.0.1
|
|
workspaces:
|
|
- name: source
|
|
workspace: shared-data
|
|
runAfter:
|
|
- verify-digest
|
|
- verify-url
|
|
- name: fetch-deploy-repo
|
|
runAfter:
|
|
- kind
|
|
taskRef:
|
|
name: git-clone
|
|
workspaces:
|
|
- name: output
|
|
workspace: shared-data
|
|
params:
|
|
- name: url
|
|
value: $(params.deploy-repo-url)
|
|
- name: revision
|
|
value: $(params.deploy-branch-name)
|
|
- name: commit-deploy-image
|
|
runAfter:
|
|
- fetch-deploy-repo
|
|
params:
|
|
- name: image-name
|
|
#value: $(params.image)
|
|
value: localhost:5001/deployment/msbdeployment
|
|
- name: image-tag
|
|
value: $(params.version)
|
|
- name: git-branch
|
|
value: $(params.deploy-branch-name)
|
|
workspaces:
|
|
- name: source
|
|
workspace: shared-data
|
|
taskSpec:
|
|
params:
|
|
- name: image-name
|
|
- name: image-tag
|
|
- name: git-branch
|
|
workspaces:
|
|
- name: source
|
|
steps:
|
|
- image: alpine/git:v2.36.2
|
|
script: |
|
|
#!/usr/bin/env sh
|
|
cd $(workspaces.source.path)
|
|
git config --global --add safe.directory $(workspaces.source.path)
|
|
git checkout -b $(params.git-branch)
|
|
sed -i "s#newName: .*#newName: $(params.image-name)#" manager/kustomization.yaml
|
|
sed -i "s#newTag: .*#newTag: $(params.image-tag)#" manager/kustomization.yaml
|
|
git config --global user.email "tekton-rebot@mashibing.com"
|
|
git config --global user.name "tekton rebot"
|
|
git add manager/kustomization.yaml
|
|
git commit -m "update image to $(params.image-name):$(params.image-tag)"
|
|
git push origin $(params.git-branch)
|
|
- name: sync-application
|
|
runAfter:
|
|
- commit-deploy-image
|
|
taskRef:
|
|
name: argocd-task-sync-and-wait
|
|
params:
|
|
- name: application-name
|
|
value: $(params.app-name)
|
|
- name: flags
|
|
value: --insecure
|
|
- name: argocd-version
|
|
value: latest
|
|
---
|
|
apiVersion: tekton.dev/v1beta1
|
|
kind: PipelineRun
|
|
metadata:
|
|
name: msbdeployment-pipeline
|
|
spec:
|
|
serviceAccountName: build-bot
|
|
pipelineRef:
|
|
name: msbdeployment-pipeline
|
|
podTemplate:
|
|
securityContext:
|
|
fsGroup: 65532
|
|
workspaces:
|
|
- name: shared-data
|
|
volumeClaimTemplate:
|
|
spec:
|
|
accessModes:
|
|
- ReadWriteOnce
|
|
resources:
|
|
requests:
|
|
storage: 1Gi
|
|
params:
|
|
- name: repo-url
|
|
value: git@host.docker.internal:root/mashibing-deployment.git
|
|
- name: branch-name
|
|
value: master
|
|
- name: version
|
|
value: "v0.0.2"
|
|
- name: image
|
|
value: kind-registry:5000/deployment/msbdeployment
|
|
- name: app-name
|
|
value: msb-app
|
|
- name: deploy-repo-url
|
|
value: git@host.docker.internal:root/mashibing-deployment-deploy.git
|
|
- name: deploy-branch-name
|
|
value: master
|