This commit is contained in:
병준 박 2025-04-16 04:18:30 +00:00
parent 2e1cdf0fea
commit fe358d4815
13 changed files with 73 additions and 136 deletions

View File

@ -20,14 +20,14 @@ spec:
The name of the folder in the shared workspace to delete. The name of the folder in the shared workspace to delete.
If empty, no cleanup action will be performed. If empty, no cleanup action will be performed.
workspaces: workspaces:
- name: shared - name: base
steps: steps:
- name: cleanup-folder - name: cleanup-folder
image: ubuntu image: ubuntu
script: | script: |
#!/bin/bash #!/bin/bash
base="/workspace/shared/$(params.base)" base="/workspace/base/$(params.base)"
if [ -d "${base}" ]; then if [ -d "${base}" ]; then
rm -rf "${base}" rm -rf "${base}"
echo "Deleted folder: ${base}" echo "Deleted folder: ${base}"

View File

@ -20,27 +20,19 @@ spec:
A prefix for the working folder name. A prefix for the working folder name.
The final folder name will include this prefix, a timestamp, and a random string. The final folder name will include this prefix, a timestamp, and a random string.
results: results:
- name: base - name: context
description: | description: |
The unique folder name created in the shared workspace. The unique folder name created in the shared workspace.
- name: home
description: |
The unique home folder name created in the shared workspace.
- name: workshop
description: |
The unique working folder name created in the shared workspace.
workspaces: workspaces:
- name: shared - name: base
steps: steps:
- name: create-folder - name: create-folder
image: ubuntu image: ubuntu
script: | script: |
#!/bin/bash #!/bin/bash
uniqueFolder="$(params.workingFolderPrefix)-$(date +%s)-$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)" context="$(params.workingFolderPrefix)-$(date +%s)-$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)"
mkdir -p /workspace/shared/${uniqueFolder}/workshop mkdir -p /workspace/base/${context}/source
mkdir -p /workspace/shared/${uniqueFolder}/home mkdir -p /workspace/base/${context}/home
chmod -R a+rwX /workspace/shared/${uniqueFolder} chmod -R a+rwX /workspace/base/${context}
echo "Created folder: ${uniqueFolder}/{workshop | home}" echo "Created folder: ${context}/{source | home}"
echo -n "${uniqueFolder}" > $(results.base.path) echo -n "${context}" > $(results.context.path)
echo -n "${uniqueFolder}/workshop" > $(results.workshop.path)
echo -n "${uniqueFolder}/home" > $(results.home.path)

View File

@ -4,15 +4,10 @@ metadata:
name: docker-registry name: docker-registry
spec: spec:
params: params:
- name: home - name: context
type: string type: string
default: "" default: ""
description: home directory description: context directory
- name: workshop
type: string
default: ""
description: workshop within the repo where the source code is located
- name: imageName - name: imageName
type: string type: string
@ -27,14 +22,14 @@ spec:
default: ./Dockerfile default: ./Dockerfile
description: Path to Dockerfile description: Path to Dockerfile
- name: context - name: dockerContext
type: string type: string
default: . default: .
description: Build context path (relative to workshop) description: Build context path (relative to workshop)
workspaces: workspaces:
- name: shared - name: base
description: Source code workspace description: base workspace
results: results:
- name: imageUrl - name: imageUrl
@ -43,11 +38,6 @@ spec:
steps: steps:
- name: prepare-docker - name: prepare-docker
image: alpine:3.21.3 image: alpine:3.21.3
workingDir: /workspace/shared/$(params.workshop)
env:
- name: HOME
value: /workspace/shared/$(params.home)
script: | script: |
#!/bin/sh #!/bin/sh
set -e set -e
@ -58,17 +48,17 @@ spec:
- name: kaniko-build - name: kaniko-build
image: gcr.io/kaniko-project/executor:v1.23.2 image: gcr.io/kaniko-project/executor:v1.23.2
workingDir: $(workspaces.shared.path)/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
- name: DOCKER_CONFIG - name: DOCKER_CONFIG
value: /workspace/shared/$(params.home)/.docker value: /workspace/base/$(params.context)/home/.docker
command: command:
- /kaniko/executor - /kaniko/executor
args: args:
- --dockerfile=$(params.dockerfile) - --dockerfile=$(params.dockerfile)
- --context=$(params.context) - --context=$(params.dockerContext)
- --destination=$(params.imageName):$(params.tag) - --destination=$(params.imageName):$(params.tag)
- --skip-tls-verify - --skip-tls-verify
- --verbosity=info - --verbosity=info

View File

@ -9,15 +9,10 @@ spec:
The commit SHA, committer date, and fetched URL are exposed as Task results. The commit SHA, committer date, and fetched URL are exposed as Task results.
params: params:
- name: home - name: context
type: string type: string
default: "" default: ""
description: home directory description: context directory
- name: workshop
type: string
default: ""
description: workshop inside the `shared` Workspace to clone the repo into.
- name: url - name: url
type: string type: string
@ -91,7 +86,7 @@ spec:
description: The image providing the git-init binary that this Task runs. description: The image providing the git-init binary that this Task runs.
workspaces: workspaces:
- name: shared - name: base
description: The workspace where the repository will be cloned. description: The workspace where the repository will be cloned.
results: results:
@ -107,9 +102,9 @@ spec:
image: $(params.gitInitImage) image: $(params.gitInitImage)
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
- name: SSL_CERT_FILE - name: SSL_CERT_FILE
value: /workspace/shared/$(params.home)/cert/$(params.crtFileName)" value: /workspace/base/$(params.context)/home/cert/$(params.crtFileName)"
- name: HTTP_PROXY - name: HTTP_PROXY
value: $(params.httpProxy) value: $(params.httpProxy)
- name: HTTPS_PROXY - name: HTTPS_PROXY
@ -125,9 +120,9 @@ spec:
git config --global http.sslVerify false git config --global http.sslVerify false
fi fi
cd /workspace/shared cd /workspace/base
CLONE_DIR="$(params.workshop)" CLONE_DIR="$(params.source)"
if [ -z "$CLONE_DIR" ]; then if [ -z "$CLONE_DIR" ]; then
CLONE_DIR="." CLONE_DIR="."
fi fi

View File

@ -14,10 +14,10 @@ spec:
to the corresponding GitOps repository derived from the application source repo. to the corresponding GitOps repository derived from the application source repo.
params: params:
- name: home - name: context
type: string type: string
default: "" default: ""
description: home directory description: context directory
- name: repositoryUrl - name: repositoryUrl
type: string type: string
@ -42,7 +42,7 @@ spec:
description: Commit message description: Commit message
workspaces: workspaces:
- name: shared - name: base
steps: steps:
- name: update-and-push - name: update-and-push
@ -50,7 +50,7 @@ spec:
workingDir: /workspace workingDir: /workspace
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
script: | script: |
#!/bin/sh #!/bin/sh
set -e set -e
@ -73,8 +73,6 @@ spec:
echo "🛠 Updating image.tag in $VALUES_PATH to $TAG" echo "🛠 Updating image.tag in $VALUES_PATH to $TAG"
yq e ".image.tag = \"$TAG\"" -i "$VALUES_PATH" yq e ".image.tag = \"$TAG\"" -i "$VALUES_PATH"
git config user.name "tekton-ci"
git config user.email "ci@example.com"
git add "$VALUES_PATH" git add "$VALUES_PATH"
git commit -m "$(params.commitMessage)" || echo "No changes to commit." git commit -m "$(params.commitMessage)" || echo "No changes to commit."
git push origin "$BRANCH" git push origin "$BRANCH"

View File

@ -4,14 +4,9 @@ metadata:
name: nx-nodejs-analysis name: nx-nodejs-analysis
spec: spec:
params: params:
- name: home - name: context
type: string type: string
description: home directory description: context directory
default: ""
- name: workshop
type: string
description: workshop within the repo where the source code is located
default: "" default: ""
- name: targetProject - name: targetProject
@ -24,7 +19,7 @@ spec:
description: Node.js image (e.g., node:18-slim) description: Node.js image (e.g., node:18-slim)
workspaces: workspaces:
- name: shared - name: base
description: Git-cloned source code with Nx monorepo description: Git-cloned source code with Nx monorepo
results: results:
@ -36,10 +31,10 @@ spec:
steps: steps:
- name: lint-and-test - name: lint-and-test
image: $(params.nodejsImageName) image: $(params.nodejsImageName)
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e

View File

@ -4,13 +4,9 @@ metadata:
name: nx-nodejs-version name: nx-nodejs-version
spec: spec:
params: params:
- name: home - name: context
type: string type: string
description: home directory description: context directory
default: ""
- name: workshop
type: string
description: workshop within the repo where the source code is located
default: "" default: ""
- name: ref - name: ref
@ -21,7 +17,7 @@ spec:
default: "node:slim" default: "node:slim"
description: Node.js image (e.g., node:23-slim) description: Node.js image (e.g., node:23-slim)
workspaces: workspaces:
- name: shared - name: base
description: Git-cloned source code description: Git-cloned source code
results: results:
- name: version - name: version
@ -29,10 +25,10 @@ spec:
steps: steps:
- name: verify-tag-version - name: verify-tag-version
image: $(params.nodejsImageName) image: $(params.nodejsImageName)
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e

View File

@ -4,23 +4,18 @@ metadata:
name: pybuild name: pybuild
spec: spec:
params: params:
- name: home - name: context
type: string type: string
default: "" default: ""
description: home directory description: home directory
- name: workshop
type: string
default: ""
description: workshop within the repo where the source code is located
- name: pythonImageName - name: pythonImageName
type: string type: string
default: "python:3.11-slim" default: "python:3.11-slim"
description: Python version to use description: Python version to use
workspaces: workspaces:
- name: shared - name: base
description: Workspace containing the cloned Git repository description: Workspace containing the cloned Git repository
results: results:
@ -30,10 +25,10 @@ spec:
steps: steps:
- name: build-package - name: build-package
image: $(params.pythonImageName) image: $(params.pythonImageName)
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
@ -67,7 +62,7 @@ spec:
fi fi
echo "📂 Checking built artifacts..." echo "📂 Checking built artifacts..."
BUILD_PATH="/workspace/shared/$(params.workshop)/dist" BUILD_PATH="/workspace/base/$(params.workshop)/dist"
echo -n "$BUILD_PATH" > /tekton/results/build-artifact-path echo -n "$BUILD_PATH" > /tekton/results/build-artifact-path
if [ -d "$BUILD_PATH" ] && [ -n "$(ls -A "$BUILD_PATH")" ]; then if [ -d "$BUILD_PATH" ] && [ -n "$(ls -A "$BUILD_PATH")" ]; then

View File

@ -4,14 +4,9 @@ metadata:
name: pylint name: pylint
spec: spec:
params: params:
- name: home - name: context
type: string type: string
description: home directory description: context directory
default: ""
- name: workshop
type: string
description: workshop within the repo where the shared code is located
default: "" default: ""
- name: pythonImageName - name: pythonImageName
@ -36,16 +31,16 @@ spec:
description: Exit code returned by pylint (0=clean, non-zero=issues) description: Exit code returned by pylint (0=clean, non-zero=issues)
workspaces: workspaces:
- name: shared - name: base
description: Workspace containing the cloned Git repository description: Workspace containing the cloned Git repository
steps: steps:
- name: run-pylint - name: run-pylint
image: $(params.pythonImageName) image: $(params.pythonImageName)
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
@ -70,7 +65,7 @@ spec:
echo "🧪 Running Pylint (JSON report)..." echo "🧪 Running Pylint (JSON report)..."
set +e set +e
REPORT_FILE="/workspace/shared/pylint-report.json" REPORT_FILE="/workspace/base/pylint-report.json"
if [ -f pyproject.toml ]; then if [ -f pyproject.toml ]; then
poetry run pylint $(params.pylint-args) --output-format=json . > "$REPORT_FILE" poetry run pylint $(params.pylint-args) --output-format=json . > "$REPORT_FILE"

View File

@ -4,14 +4,9 @@ metadata:
name: pytest name: pytest
spec: spec:
params: params:
- name: home - name: context
type: string type: string
description: home directory description: context directory
default: ""
- name: workshop
type: string
description: workshop within the workspace where the tests are located
default: "" default: ""
- name: pythonImageName - name: pythonImageName
@ -20,16 +15,16 @@ spec:
default: "python:3.11-slim" default: "python:3.11-slim"
workspaces: workspaces:
- name: shared - name: base
description: Workspace containing the cloned Git repository from git-clone-checkout description: Workspace containing the cloned Git repository from git-clone-checkout
steps: steps:
- name: install-dependencies - name: install-dependencies
image: $(params.pythonImageName) image: $(params.pythonImageName)
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
@ -56,17 +51,17 @@ spec:
echo "🧪 Running tests..." echo "🧪 Running tests..."
set +e set +e
if [ -f pyproject.toml ]; then if [ -f pyproject.toml ]; then
poetry run pytest --verbose --junitxml=/workspace/shared/pytest-results.xml poetry run pytest --verbose --junitxml=/workspace/base/pytest-results.xml
else else
pytest --verbose --junitxml=/workspace/shared/pytest-results.xml pytest --verbose --junitxml=/workspace/base/pytest-results.xml
fi fi
TEST_EXIT_CODE=$? TEST_EXIT_CODE=$?
set -e set -e
echo "📄 Checking test results..." echo "📄 Checking test results..."
if [ -f /workspace/shared/pytest-results.xml ]; then if [ -f /workspace/base/pytest-results.xml ]; then
echo "Test results:" echo "Test results:"
cat /workspace/shared/pytest-results.xml cat /workspace/base/pytest-results.xml
else else
echo "❌ No test results found" echo "❌ No test results found"
exit 1 exit 1

View File

@ -4,14 +4,9 @@ metadata:
name: pyversion name: pyversion
spec: spec:
params: params:
- name: home - name: context
type: string type: string
description: home directory description: context directory
default: ""
- name: workshop
type: string
description: workshop within the repo where the source code is located
default: "" default: ""
- name: ref - name: ref
@ -24,7 +19,7 @@ spec:
default: "python:3.11-slim" default: "python:3.11-slim"
workspaces: workspaces:
- name: shared - name: base
description: shared code workspace (includes pyproject.toml) description: shared code workspace (includes pyproject.toml)
results: results:
@ -34,7 +29,7 @@ spec:
steps: steps:
- name: verify-tag - name: verify-tag
image: $(params.pythonImageName) image: $(params.pythonImageName)
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e

View File

@ -4,14 +4,9 @@ metadata:
name: secret-home name: secret-home
spec: spec:
params: params:
- name: home - name: context
type: string type: string
description: home directory description: context directory
default: ""
- name: workshop
type: string
description: workshop directory
default: "" default: ""
- name: keys - name: keys
@ -20,7 +15,7 @@ spec:
Comma-separated keys (e.g. ".gitconfig,.git-credentials") Comma-separated keys (e.g. ".gitconfig,.git-credentials")
workspaces: workspaces:
- name: shared - name: base
description: Workspace containing the cloned Git repository description: Workspace containing the cloned Git repository
- name: credentials - name: credentials
description: Secret data from workspace description: Secret data from workspace
@ -28,10 +23,10 @@ spec:
steps: steps:
- name: extract - name: extract
image: python:3.11-slim image: python:3.11-slim
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
env: env:
- name: HOME - name: HOME
value: /workspace/shared/$(params.home) value: /workspace/base/$(params.context)/home
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e

View File

@ -4,14 +4,10 @@ metadata:
name: sonarqube-analysis name: sonarqube-analysis
spec: spec:
params: params:
- name: home - name: context
type: string type: string
default: "" default: ""
description: home directory description: context directory
- name: workshop
type: string
default: ""
description: workshop within workspace containing the source (if any)
- name: sonarHostUrl - name: sonarHostUrl
type: string type: string
@ -23,7 +19,7 @@ spec:
description: SonarQube project key description: SonarQube project key
workspaces: workspaces:
- name: shared - name: base
description: Workspace with shared code (e.g. from git-clone) description: Workspace with shared code (e.g. from git-clone)
- name: sonar-auth - name: sonar-auth
@ -33,7 +29,7 @@ spec:
steps: steps:
- name: sonar-scan - name: sonar-scan
image: sonarsource/sonar-scanner-cli:5 image: sonarsource/sonar-scanner-cli:5
workingDir: /workspace/shared/$(params.workshop) workingDir: /workspace/base/$(params.context)/source
script: | script: |
#!/bin/sh #!/bin/sh
set -e set -e