diff --git a/tasks/after-pipeline/task.yaml b/tasks/after-pipeline/task.yaml new file mode 100644 index 0000000..5d2570f --- /dev/null +++ b/tasks/after-pipeline/task.yaml @@ -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 + diff --git a/tasks/before-pipeline/task.yaml b/tasks/before-pipeline/task.yaml new file mode 100644 index 0000000..1591a15 --- /dev/null +++ b/tasks/before-pipeline/task.yaml @@ -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 < /tekton/results/pvcName + else + echo "Persistence disabled, no PVC created." + echo -n "" > /tekton/results/pvcName + fi + diff --git a/tasks/pybuild/task.yaml b/tasks/pybuild/task.yaml index f489717..9ba4ef4 100644 --- a/tasks/pybuild/task.yaml +++ b/tasks/pybuild/task.yaml @@ -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:" diff --git a/tasks/pylint/task.yaml b/tasks/pylint/task.yaml index d36d876..d35e48f 100644 --- a/tasks/pylint/task.yaml +++ b/tasks/pylint/task.yaml @@ -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 옵션 추가 필요 diff --git a/tasks/pypi/task.yaml b/tasks/pypi/task.yaml index d3add97..e8e1f03 100644 --- a/tasks/pypi/task.yaml +++ b/tasks/pypi/task.yaml @@ -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)" \ diff --git a/tasks/pytest/task.yaml b/tasks/pytest/task.yaml index efdfc20..969692f 100644 --- a/tasks/pytest/task.yaml +++ b/tasks/pytest/task.yaml @@ -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 diff --git a/tasks/remove-pvc/task.yaml b/tasks/remove-pvc/task.yaml index abb6a61..45496c5 100644 --- a/tasks/remove-pvc/task.yaml +++ b/tasks/remove-pvc/task.yaml @@ -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." \ No newline at end of file