This commit is contained in:
2024-04-23 10:52:04 +02:00
parent bacc62981c
commit 5a6cd40cc7
9 changed files with 282 additions and 49 deletions

View File

@@ -40,6 +40,43 @@ data "kustomization_overlay" "data" {
- op: add
path: /spec/params/2/default
value: ${var.domain_name}
- op: add
path: /spec/params/3/default
value: ${jsonencode(var.stages)}
EOF
}
patches {
target {
kind = "Task"
name = "auto-ci-activate"
}
patch = <<-EOF
- op: replace
path: /spec/params/1/default
value: ${var.issuer}
- op: add
path: /spec/params/2/default
value: ${var.domain_name}
- op: add
path: /spec/params/3/default
value: ${jsonencode(var.stages)}
EOF
}
patches {
target {
kind = "Task"
name = "auto-ci-delete"
}
patch = <<-EOF
- op: replace
path: /spec/params/1/default
value: ${var.issuer}
- op: add
path: /spec/params/2/default
value: ${var.domain_name}
- op: add
path: /spec/params/3/default
value: ${jsonencode(var.stages)}
EOF
}
patches {

View File

@@ -4,7 +4,7 @@ kind: Component
category: share
metadata:
name: gitea-tekton-org
description: null
description: Setup tekton-cicd base objects and set the webhook for gitea
options:
autoCD:
default: true
@@ -36,6 +36,11 @@ options:
examples:
- your-org
type: string
stages:
default: []
items:
type: string
type: array
storage:
default:
volume:

View File

@@ -34,7 +34,7 @@ spec:
finally:
- name: cleanup
taskRef:
name: auto-ci-cleaup
name: auto-ci-cleanup
workspaces:
- name: source
- name: inform-gitea-success

View File

@@ -31,7 +31,7 @@ spec:
finally:
- name: cleanup
taskRef:
name: auto-ci-cleaup
name: auto-ci-cleanup
workspaces:
- name: source
- name: inform-gitea-success

View File

@@ -0,0 +1,77 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: auto-ci-activate
spec:
params:
- name: toolbox-image
default: sebt3/basic-toolbox-image:1.30.0
description: The name of the toolbox image
type: string
- name: issuer-name
default: letsencrypt-prod
type: string
- name: domain-name
type: string
- name: stages
type: array
- name: artifactory-url
description: The url of the current artifactory
- name: project-name
description: The git repository name
- name: project-path
description: The path of the current project
- name: git-repository-url
description: The git repository url
- name: deploy-url
description: The git repository url for the deploy project
steps:
- name: activate
image: $(params.toolbox-image)
workingDir: $(workspaces.source.path)
args:
- $(params.stages)
env:
- name: ARTIFACTORY_URL
value: $(params.artifactory-url)
- name: DOMAIN_NAME
value: $(params.domain-name)
- name: ISSUER_NAME
value: $(params.issuer-name)
- name: PROJECT_NAME
value: $(params.project-name)
- name: PROJECT_PATH
value: $(params.project-path)
- name: GIT_REPOSITORY_URL
value: $(params.git-repository-url)
- name: DEPLOY_URL
value: $(params.deploy-url)
- name: TEMPLATE_ROOT
value: /etc/templates
- name: WORKSPACE_SSH_DIRECTORY_PATH
value: $(workspaces.ssh-directory.path)
script: |-
#!/usr/bin/env bash
. ${TEMPLATE_ROOT}/functions.sh
git_prepare "$(params.deploy-url)" "Auto CD" "autocd@$(params.domain-name)"
install_base
create_prj
activate_prj
git_push "Activating $(params.project-name)"
cleanup
volumeMounts:
- mountPath: /etc/templates
name: templates
volumes:
- name: templates
configmap:
name: auto-cd-templates
workspaces:
- name: source
mountPath: /data
- description: |
A .ssh directory with private key, known_hosts, config, etc. Copied to
the user's home before git commands are executed. Used to authenticate
with the git remote when performing the clone. Binding a Secret to this
Workspace is strongly recommended over other volume types.
name: ssh-directory

View File

@@ -13,7 +13,7 @@ spec:
image: $(params.toolbox-image)
workingDir: $(workspaces.source.path)
script: |-
#!/usr/bin/env ash
#!/usr/bin/env bash
rm -rf . || true
workspaces:
- name: source

View File

@@ -13,6 +13,8 @@ spec:
type: string
- name: domain-name
type: string
- name: stages
type: array
- name: artifactory-url
description: The url of the current artifactory
- name: project-name
@@ -24,71 +26,45 @@ spec:
- name: deploy-url
description: The git repository url for the deploy project
steps:
- name: cleanup
- name: create
image: $(params.toolbox-image)
workingDir: $(workspaces.source.path)
args:
- $(params.stages)
env:
- name: ARTIFACTORY_URL
value: $(params.artifactory-url)
- name: PROJECT_NAME
value: $(params.project-name)
- name: DOMAIN_NAME
value: $(params.domain-name)
- name: ISSUER_NAME
value: $(params.issuer-name)
- name: PROJECT_NAME
value: $(params.project-name)
- name: PROJECT_PATH
value: $(params.project-path)
- name: GIT_REPOSITORY_URL
value: $(params.git-repository-url)
- name: DEPLOY_URL
value: $(params.deploy-url)
- name: TEMPLATE_ROOT
value: /etc/templates
- name: WORKSPACE_SSH_DIRECTORY_PATH
value: $(workspaces.ssh-directory.path)
script: |-
#!/usr/bin/env bash
git clone "$(params.deploy-url)" --depth 1 .
mkdir -p "projects/$(params.project-name)" bases/project bases/install bases/deploy
added=0
copy() {
local src=/etc/templates/$1 dest=$2
if [ ! -f $dest ];then
cp "$src" "$dest"
git add "$dest"
added=$(($added+1))
fi
}
template() {
local src=/etc/templates/$1 dest=$2
if [ ! -f $dest ];then
envsubst <"$src" >"$dest"
git add "$dest"
added=$(($added+1))
fi
}
template base-update.yaml.tmpl bases/project/base-update.yaml
copy base-repo.yaml bases/project/repo.yaml
copy base-cert.yaml bases/project/cert.yaml
copy base-ingress.yaml bases/project/ingress.yaml
copy base-policy.yaml bases/project/policy.yaml
copy base-deploy.yaml bases/project/deploy.yaml
copy base-secret.yaml bases/project/secret.yaml
copy base-config.yaml bases/project/config.yaml
copy base-service.yaml bases/project/service.yaml
copy base-kusto.yaml bases/project/kustomization.yaml
copy install-install.yaml bases/install/install.yaml
copy install-kusto.yaml bases/install/kustomization.yaml
copy deploy-kusto.yaml bases/deploy/kustomization.yaml
template deploy-repo.yaml.tmpl bases/deploy/repo.yaml
template project-kusto.yaml.tmpl "projects/$(params.project-name)/kustomization.yaml"
if [ $added -ne 0 ];then
git commit -am "Adding $(params.project-name)"
git push
fi
. ${TEMPLATE_ROOT}/functions.sh
git_prepare "$(params.deploy-url)" "Auto CD" "autocd@$(params.domain-name)"
install_base
create_prj
git_push "Adding $(params.project-name)"
cleanup
volumeMounts:
- mountPath: /etc/templates
name: templates
volumes:
- name: templates
configmap:
name: auto-cd-create-templates
name: auto-cd-templates
workspaces:
- name: source
mountPath: /data
@@ -97,5 +73,4 @@ spec:
the user's home before git commands are executed. Used to authenticate
with the git remote when performing the clone. Binding a Secret to this
Workspace is strongly recommended over other volume types.
name: ssh-directory
optional: true
name: ssh-directory

View File

@@ -0,0 +1,75 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: auto-ci-delete
spec:
params:
- name: toolbox-image
default: sebt3/basic-toolbox-image:1.30.0
description: The name of the toolbox image
type: string
- name: issuer-name
default: letsencrypt-prod
type: string
- name: domain-name
type: string
- name: stages
type: array
- name: artifactory-url
description: The url of the current artifactory
- name: project-name
description: The git repository name
- name: project-path
description: The path of the current project
- name: git-repository-url
description: The git repository url
- name: deploy-url
description: The git repository url for the deploy project
steps:
- name: delete
image: $(params.toolbox-image)
workingDir: $(workspaces.source.path)
args:
- $(params.stages)
env:
- name: ARTIFACTORY_URL
value: $(params.artifactory-url)
- name: DOMAIN_NAME
value: $(params.domain-name)
- name: ISSUER_NAME
value: $(params.issuer-name)
- name: PROJECT_NAME
value: $(params.project-name)
- name: PROJECT_PATH
value: $(params.project-path)
- name: GIT_REPOSITORY_URL
value: $(params.git-repository-url)
- name: DEPLOY_URL
value: $(params.deploy-url)
- name: TEMPLATE_ROOT
value: /etc/templates
- name: WORKSPACE_SSH_DIRECTORY_PATH
value: $(workspaces.ssh-directory.path)
script: |-
#!/usr/bin/env bash
. ${TEMPLATE_ROOT}/functions.sh
git_prepare "$(params.deploy-url)" "Auto CD" "autocd@$(params.domain-name)"
delete_prj
git_push "Removing $(params.project-name)"
cleanup
volumeMounts:
- mountPath: /etc/templates
name: templates
volumes:
- name: templates
configmap:
name: auto-cd-templates
workspaces:
- name: source
mountPath: /data
- description: |
A .ssh directory with private key, known_hosts, config, etc. Copied to
the user's home before git commands are executed. Used to authenticate
with the git remote when performing the clone. Binding a Secret to this
Workspace is strongly recommended over other volume types.
name: ssh-directory

View File

@@ -1,8 +1,72 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: auto-cd-create-templates
name: auto-cd-templates
data:
functions.sh: |-
added=0
copy() {
local src=${TEMPLATE_ROOT}/$1 dest=$2
if [ ! -f $dest ];then
cp "$src" "$dest"
git add "$dest"
added=$(($added+1))
fi
}
template() {
local src=${TEMPLATE_ROOT}/$1 dest=$2
if [ ! -f $dest ];then
envsubst <"$src" >"$dest"
git add "$dest"
added=$(($added+1))
fi
}
git_push() {
local message=$1
if [ $added -ne 0 ];then
git commit -am "$message"
git push
fi
}
cleanup() {
rm -rf . || true
}
git_prepare() {
local url=$1 username=$2 email=$3
mkdir -p "${HOME}/.ssh"
cp -Rv "${WORKSPACE_SSH_DIRECTORY_PATH}" "${HOME}/.ssh"
chmod 700 "${HOME}/.ssh"
chmod 400 "${HOME}/.ssh"/*
git config --global user.name "$username"
git config --global user.email "$email"
git clone "$url" --depth 1 .
}
install_base() {
mkdir -p bases/project bases/install bases/deploy
template base-update.yaml.tmpl bases/project/base-update.yaml
copy base-repo.yaml bases/project/repo.yaml
copy base-cert.yaml bases/project/cert.yaml
copy base-ingress.yaml bases/project/ingress.yaml
copy base-policy.yaml bases/project/policy.yaml
copy base-deploy.yaml bases/project/deploy.yaml
copy base-secret.yaml bases/project/secret.yaml
copy base-config.yaml bases/project/config.yaml
copy base-service.yaml bases/project/service.yaml
copy base-kusto.yaml bases/project/kustomization.yaml
copy install-install.yaml bases/install/install.yaml
copy install-kusto.yaml bases/install/kustomization.yaml
copy deploy-kusto.yaml bases/deploy/kustomization.yaml
template deploy-repo.yaml.tmpl bases/deploy/repo.yaml
}
create_prj() {
mkdir -p "projects/${PROJECT_NAME}"
template project-kusto.yaml.tmpl "projects/${PROJECT_NAME}/kustomization.yaml"
}
activate_prj() {
}
delete_prj() {
rm -rf "projects/${PROJECT_NAME}"
}
base-kusto.yaml: |-
---
apiVersion: kustomize.config.k8s.io/v1beta1