ClusterTask Yaml Add

This commit is contained in:
2023-01-31 02:27:18 +00:00
parent 3e78876c64
commit 9df4805f6f
5 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
annotations:
tekton.dev/categories: Deployment
tekton.dev/displayName: argocd
tekton.dev/pipelines.minVersion: 0.12.1
tekton.dev/platforms: linux/amd64
tekton.dev/tags: deploy
labels:
app.kubernetes.io/version: "0.2"
name: argocd-task-sync-and-wait
spec:
description: |-
This task syncs (deploys) an Argo CD application and waits for it to be healthy.
To do so, it requires the address of the Argo CD server and some form of authentication either a username/password or an authentication token.
params:
- description: name of the application to sync
name: application-name
type: string
- default: HEAD
description: the revision to sync to
name: revision
type: string
- default: --
name: flags
type: string
- default: v2.2.5
name: argocd-version
type: string
stepTemplate:
envFrom:
- configMapRef:
name: argocd-env-configmap
- secretRef:
name: argocd-env-secret
name: ""
resources: {}
steps:
- image: quay.io/argoproj/argocd:$(params.argocd-version)
name: login
resources: {}
script: |
if [ -z "$ARGOCD_AUTH_TOKEN" ]; then
yes | argocd login "$ARGOCD_SERVER" --username="$ARGOCD_USERNAME" --password="$ARGOCD_PASSWORD" "$(params.flags)";
fi
argocd --grpc-web app get --refresh "$(params.application-name)" > /dev/null && argocd --grpc-web app wait "$(params.application-name)" --sync --health
argocd app sync "$(params.application-name)" --revision "$(params.revision)" "$(params.flags)"
argocd app wait "$(params.application-name)" --health "$(params.flags)"

View File

@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-env-configmap
data:
ARGOCD_SERVER: <Argo CD server address>

View File

@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: argocd-env-secret
data:
# choose one of username/password or auth token
ARGOCD_USERNAME: <username>
ARGOCD_PASSWORD: <password>
#ARGOCD_AUTH_TOKEN: <token> 계정 혹은 token 둘 중 하나만 사용

102
clustertask/buildah.yaml Normal file
View File

@@ -0,0 +1,102 @@
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
annotations:
tekton.dev/categories: Image Build
tekton.dev/pipelines.minVersion: 0.17.0
tekton.dev/platforms: linux/amd64,linux/s390x,linux/ppc64le,linux/arm64
tekton.dev/tags: image-build
labels:
app.kubernetes.io/version: "0.5"
name: buildah
spec:
description: |-
Buildah task builds source into a container image and then pushes it to a container registry.
Buildah Task builds source into a container image using Project Atomic's Buildah build tool.It uses Buildah's support for building from Dockerfiles, using its buildah bud command.This command executes the directives in the Dockerfile to assemble a container image, then pushes that image to a container registry.
params:
- description: Reference of the image buildah will produce.
name: IMAGE
type: string
- default: quay.io/buildah/stable:v1.23.3
description: The location of the buildah builder image.
name: BUILDER_IMAGE
type: string
- default: overlay
description: Set buildah storage driver
name: STORAGE_DRIVER
type: string
- default: ./Dockerfile
description: Path to the Dockerfile to build.
name: DOCKERFILE
type: string
- default: .
description: Path to the directory to use as context.
name: CONTEXT
type: string
- default: "true"
description: Verify the TLS on the registry endpoint (for push/pull to a non-TLS
registry)
name: TLSVERIFY
type: string
- default: oci
description: The format of the built container, oci or docker
name: FORMAT
type: string
- default: ""
description: Extra parameters passed for the build command when building images.
name: BUILD_EXTRA_ARGS
type: string
- default: ""
description: Extra parameters passed for the push command when pushing images.
name: PUSH_EXTRA_ARGS
type: string
- default: "false"
description: Skip pushing the built image
name: SKIP_PUSH
type: string
results:
- description: Digest of the image just built.
name: IMAGE_DIGEST
- description: Image repository where the built image would be pushed to
name: IMAGE_URL
steps:
- image: $(params.BUILDER_IMAGE)
name: build
resources: {}
script: |
yum install podman -y
cd ./reviews
podman run --rm -u root -v ./:/home/gradle/project -w /home/gradle/project docker.io/gradle:4.8.1 gradle clean build
cd ./reviews-wlpcfg
ls -l
[[ "$(workspaces.sslcertdir.bound)" == "true" ]] && CERT_DIR_FLAG="--cert-dir $(workspaces.sslcertdir.path)"
[[ "$(workspaces.dockerconfig.bound)" == "true" ]] && export DOCKER_CONFIG="$(workspaces.dockerconfig.path)"
buildah ${CERT_DIR_FLAG} --storage-driver=$(params.STORAGE_DRIVER) bud \
$(params.BUILD_EXTRA_ARGS) --format=$(params.FORMAT) \
--tls-verify=$(params.TLSVERIFY) --no-cache \
-f $(params.DOCKERFILE) -t $(params.IMAGE) --build-arg service_version=v3 --build-arg enable_ratings=true --build-arg star_color=red $(params.CONTEXT)
[[ "$(params.SKIP_PUSH)" == "true" ]] && echo "Push skipped" && exit 0
buildah ${CERT_DIR_FLAG} --storage-driver=$(params.STORAGE_DRIVER) push \
$(params.PUSH_EXTRA_ARGS) --tls-verify=$(params.TLSVERIFY) \
--digestfile /tmp/image-digest $(params.IMAGE) \
docker://$(params.IMAGE)
cat /tmp/image-digest | tee $(results.IMAGE_DIGEST.path)
echo "$(params.IMAGE)" | tee $(results.IMAGE_URL.path)
securityContext:
privileged: true
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
workingDir: $(workspaces.source.path)
volumes:
- emptyDir: {}
name: varlibcontainers
workspaces:
- name: source
- name: sslcertdir
optional: true
- description: An optional workspace that allows providing a .docker/config.json
file for Buildah to access the container registry. The file should be placed
at the root of the Workspace with name config.json.
name: dockerconfig
optional: true

147
clustertask/git-cli.yaml Normal file
View File

@@ -0,0 +1,147 @@
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
name: git-cli
labels:
app.kubernetes.io/version: "0.4"
annotations:
tekton.dev/pipelines.minVersion: "0.21.0"
tekton.dev/categories: Git
tekton.dev/tags: git
tekton.dev/displayName: "git cli"
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le"
spec:
description: >-
This task can be used to perform git operations.
Git command that needs to be run can be passed as a script to
the task. This task needs authentication to git in order to push
after the git operation.
workspaces:
- name: source
description: A workspace that contains the fetched git repository.
- name: input
optional: true
description: |
An optional workspace that contains the files that need to be added to git. You can
access the workspace from your script using `$(workspaces.input.path)`, for instance:
cp $(workspaces.input.path)/file_that_i_want .
git add file_that_i_want
# etc
- name: ssh-directory
optional: true
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: basic-auth
optional: true
description: |
A Workspace containing a .gitconfig and .git-credentials file. These
will be copied to the user's home before any git commands are run. Any
other files in this Workspace are ignored. It is strongly recommended
to use ssh-directory over basic-auth whenever possible and to bind a
Secret to this Workspace over other volume types.
params:
- name: BASE_IMAGE
description: |
The base image for the task.
type: string
default: docker.io/alpine/git:v2.26.2@sha256:23618034b0be9205d9cc0846eb711b12ba4c9b468efdd8a59aac1d7b1a23363f #tag: v2.26.2
- name: GIT_USER_NAME
type: string
description: |
Git user name for performing git operation.
default: ""
- name: GIT_USER_EMAIL
type: string
description: |
Git user email for performing git operation.
default: ""
- name: GIT_SCRIPT
description: The git script to run.
type: string
default: |
git help
- name: USER_HOME
description: |
Absolute path to the user's home directory. Set this explicitly if you are running the image as a non-root user or have overridden
the gitInitImage param with an image containing custom user configuration.
type: string
default: "/root"
- name: VERBOSE
description: Log the commands that are executed during `git-clone`'s operation.
type: string
default: "true"
results:
- name: commit
description: The precise commit SHA after the git operation.
steps:
- name: git
image: $(params.BASE_IMAGE)
workingDir: $(workspaces.source.path)
env:
- name: HOME
value: $(params.USER_HOME)
- name: PARAM_VERBOSE
value: $(params.VERBOSE)
- name: PARAM_USER_HOME
value: $(params.USER_HOME)
- name: WORKSPACE_OUTPUT_PATH
value: $(workspaces.output.path)
- name: WORKSPACE_SSH_DIRECTORY_BOUND
value: $(workspaces.ssh-directory.bound)
- name: WORKSPACE_SSH_DIRECTORY_PATH
value: $(workspaces.ssh-directory.path)
- name: WORKSPACE_BASIC_AUTH_DIRECTORY_BOUND
value: $(workspaces.basic-auth.bound)
- name: WORKSPACE_BASIC_AUTH_DIRECTORY_PATH
value: $(workspaces.basic-auth.path)
script: |
#!/usr/bin/env sh
set -eu
if [ "${PARAM_VERBOSE}" = "true" ] ; then
set -x
fi
if [ "${WORKSPACE_BASIC_AUTH_DIRECTORY_BOUND}" = "true" ] ; then
cp "${WORKSPACE_BASIC_AUTH_DIRECTORY_PATH}/.git-credentials" "${PARAM_USER_HOME}/.git-credentials"
cp "${WORKSPACE_BASIC_AUTH_DIRECTORY_PATH}/.gitconfig" "${PARAM_USER_HOME}/.gitconfig"
chmod 400 "${PARAM_USER_HOME}/.git-credentials"
chmod 400 "${PARAM_USER_HOME}/.gitconfig"
fi
if [ "${WORKSPACE_SSH_DIRECTORY_BOUND}" = "true" ] ; then
cp -R "${WORKSPACE_SSH_DIRECTORY_PATH}" "${PARAM_USER_HOME}"/.ssh
chmod 700 "${PARAM_USER_HOME}"/.ssh
chmod -R 400 "${PARAM_USER_HOME}"/.ssh/*
fi
# Setting up the config for the git.
git config --global user.email "$(params.GIT_USER_EMAIL)"
git config --global user.name "$(params.GIT_USER_NAME)"
eval '$(params.GIT_SCRIPT)'
RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')"
EXIT_CODE="$?"
if [ "$EXIT_CODE" != 0 ]
then
exit $EXIT_CODE
fi
# Make sure we don't add a trailing newline to the result!
printf "%s" "$RESULT_SHA" > "$(results.commit.path)"