This commit is contained in:
병준 박 2025-04-10 06:00:56 +00:00
parent 1d6ba5b419
commit d696e5d8b5
7 changed files with 126 additions and 14 deletions

View File

@ -0,0 +1,40 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: after-pipeline
spec:
params:
- name: persistence
type: object
properties:
volumeName:
type: string
namespace:
type: string
default:
volumeName: ""
namespace: ""
results:
- name: pvcName
type: string
default: ""
description: Name of the PVC to delete if it exists
steps:
- name: delete-pvc-if-exists
image: bitnami/kubectl:latest
script: |
#!/usr/bin/env bash
if [ -n "$(params.persistence.volumeName)" ]; then
if kubectl get pvc $(params.persistence.volumeName) -n $(params.persistence.namespace) >/dev/null 2>&1; then
echo "PVC $(params.persistence.volumeName) exists, deleting..."
kubectl delete pvc $(params.persistence.volumeName) -n $(params.persistence.namespace)
echo "PVC $(params.persistence.volumeName) deleted."
else
echo "PVC $(params.persistence.volumeName) does not exist, skipping deletion."
fi
else
echo "No pvcName provided, nothing to delete."
fi

View File

@ -0,0 +1,61 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: before-pipeline
spec:
params:
- name: persistence
type: object
properties:
enabled:
type: boolean
volumeName:
type: string
namespace:
type: string
storageClass:
type: string
accessModes:
type: array
size:
type: string
default:
enabled: false
volumeName: "data"
namespace: "default"
storageClass: ""
accessModes:
- "ReadWriteOnce"
size: "1Gi"
results:
- name: pvcName
description: Name of the created PVC (if enabled)
steps:
- name: create-pvc-if-enabled
image: bitnami/kubectl:latest
script: |
#!/usr/bin/env bash
if [ "$(params.persistence.enabled)" == "true" ]; then
pvcName="$(params.persistence.volumeName)-$(context.taskRun.uid)"
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: $pvcName
namespace: $(params.persistence.namespace)
spec:
accessModes:
$(for mode in $(params.persistence.accessModes); do echo " - $mode"; done)
resources:
requests:
storage: $(params.persistence.size)
storageClassName: $(params.persistence.storageClass)
EOF
echo "PVC $pvcName created."
echo -n "$pvcName" > /tekton/results/pvcName
else
echo "Persistence disabled, no PVC created."
echo -n "" > /tekton/results/pvcName
fi

View File

@ -24,9 +24,11 @@ spec:
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
pip install --upgrade pip
# Poetry가 있는 경우 설치 및 의존성 처리
if [ -f pyproject.toml ]; then
@ -43,14 +45,17 @@ spec:
echo "Error: No valid build configuration found (pyproject.toml or setup.py required)"
exit 1
fi
- name: build-package
image: python:$(params.python-version)-slim
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
# Poetry가 사용된 경우
if [ -f pyproject.toml ]; then
poetry build
@ -65,6 +70,7 @@ spec:
echo "Error: No build tool available"
exit 1
fi
# 빌드 결과 경로를 결과로 저장
echo -n "/workspace/source/$(params.subdirectory)/dist" > /tekton/results/build-artifact-path
- name: verify-build
@ -72,6 +78,7 @@ spec:
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
DIST_PATH=$(cat /tekton/results/build-artifact-path)
if [ -d "$DIST_PATH" ] && [ -n "$(ls -A $DIST_PATH)" ]; then
echo "Build artifacts successfully created in $DIST_PATH:"

View File

@ -25,10 +25,13 @@ spec:
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
pip install --upgrade pip
# Poetry가 있는 경우 설치 및 의존성 처리
if [ -f pyproject.toml ]; then
echo "Detected Poetry project (pyproject.toml found)"
@ -45,14 +48,17 @@ spec:
echo "No dependency file found, installing pylint only"
pip install pylint
fi
- name: run-lint
image: python:$(params.python-version)-slim
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
# Poetry가 사용된 경우 가상환경에서 실행
if [ -f pyproject.toml ]; then
poetry run pylint $(params.pylint-args) .
@ -60,10 +66,12 @@ spec:
pylint $(params.pylint-args) .
fi
onError: continue # 린트 실패 시에도 파이프라인을 중단하지 않음 (선택적)
- name: check-results
image: ubuntu
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
echo "Pylint execution completed."
# Pylint 결과를 별도 파일로 저장하려면 run-lint에서 --output 옵션 추가 필요

View File

@ -29,6 +29,7 @@ spec:
image: python:$(params.python-version)-slim # python-version을 고정하거나 params로 받을 수 있음
script: |
#!/usr/bin/env bash
pip install twine
twine upload \
--repository-url "$(params.pypi-repository-url)" \

View File

@ -16,30 +16,19 @@ spec:
- name: source
description: Workspace containing the cloned Git repository from git-clone-checkout
steps:
# - name: debug-workspace
# image: ubuntu
# workingDir: /workspace/source
# script: |
# #!/usr/bin/env bash
# if [ -n "$(params.subdirectory)" ]; then
# if [ -d "$(params.subdirectory)" ]; then
# echo "Subdirectory $(params.subdirectory) exists:"
# ls -la $(params.subdirectory)
# else
# echo "Subdirectory $(params.subdirectory) not found!"
# exit 1
# fi
# fi
- name: install-dependencies
image: python:$(params.python-version)-slim
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
pip install --upgrade pip
pip install pytest
if [ -f pyproject.toml ]; then
pip install poetry
poetry config virtualenvs.in-project true
@ -48,25 +37,30 @@ spec:
elif [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
- name: run-tests
image: python:$(params.python-version)-slim
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
if [ -f pyproject.toml ]; then
poetry run pytest --verbose --junitxml=/workspace/source/pytest-results.xml
else
pytest --verbose --junitxml=/workspace/source/pytest-results.xml
fi
onError: continue
- name: check-results
image: ubuntu
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -f pytest-results.xml ]; then
echo "Test results generated: pytest-results.xml"
cat pytest-results.xml

View File

@ -12,5 +12,6 @@ spec:
image: bitnami/kubectl:latest
script: |
#!/usr/bin/env bash
kubectl delete pvc $(params.pvc-name) -n gitops-ci --ignore-not-found=true
echo "PVC $(params.pvc-name) deleted."