This commit is contained in:
병준 박 2025-04-12 15:00:23 +00:00
parent 1589193b83
commit 4f97c75ee1

View File

@ -6,47 +6,58 @@ spec:
params: params:
- name: subdirectory - name: subdirectory
type: string type: string
description: Subdirectory within the repo where the source code is located
default: "" default: ""
description: Subdirectory within the repo where the Dockerfile/context reside
- name: imageName - name: imageName
type: string type: string
description: Base image name with registry (e.g. docker.unbox-x.net/registry/unbox-x-aisi-cron-app) description: Full image name (e.g. docker.unbox-x.net/registry/my-app)
- name: tag - name: tag
type: string type: string
description: Version tag to apply to the image (e.g. v0.2.0) description: Version tag (e.g. v1.0.0)
- name: dockerfile - name: dockerfile
type: string type: string
default: ./Dockerfile default: ./Dockerfile
description: Path to Dockerfile description: Path to Dockerfile (relative to subdirectory)
- name: context - name: context
type: string type: string
default: . default: .
description: Build context path (relative to subdirectory) description: Build context (relative to subdirectory)
- name: pypi-username
type: string
description: PyPI registry username
- name: pypi-password
type: string
description: PyPI registry password
workspaces: workspaces:
- name: source - name: source
description: Source code workspace description: Source code workspace
- name: docker-auth - name: docker-auth
description: Docker registry credentials (username + password) description: Docker registry secret (username/password)
- name: pypi-auth
description: PyPI registry secret (username/password)
results: results:
- name: imageUrl - name: imageUrl
description: Final pushed image URL with tag (e.g. registry/app:v0.2.0) description: Final pushed image URL with tag
volumes:
- name: env
emptyDir: {}
steps: steps:
- name: write-pypi-env
image: alpine:3.21.3
script: |
#!/bin/sh
set -e
mkdir -p /tekton/env
echo "PYPI_USERNAME=$(cat /workspace/pypi-auth/username)" > /tekton/env/.env
echo "PYPI_PASSWORD=$(cat /workspace/pypi-auth/password)" >> /tekton/env/.env
volumeMounts:
- name: env
mountPath: /tekton/env
- name: write-docker-config - name: write-docker-config
image: alpine:3.21.3 image: alpine:3.21.3
workingDir: /workspace/source workingDir: /workspace/source
@ -63,10 +74,8 @@ spec:
PASSWORD=$(cat /workspace/docker-auth/password) PASSWORD=$(cat /workspace/docker-auth/password)
REGISTRY=$(echo "$IMAGE" | cut -d/ -f1) REGISTRY=$(echo "$IMAGE" | cut -d/ -f1)
echo "📦 Using image: $IMAGE"
echo -n "$IMAGE" > /tekton/results/imageUrl echo -n "$IMAGE" > /tekton/results/imageUrl
echo "🔐 Writing Docker config for $REGISTRY..."
mkdir -p /tekton/home/.docker mkdir -p /tekton/home/.docker
cat > /tekton/home/.docker/config.json <<EOF cat > /tekton/home/.docker/config.json <<EOF
{ {
@ -77,19 +86,32 @@ spec:
} }
} }
EOF EOF
volumeMounts:
- name: env
mountPath: /tekton/env
- 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: /workspace/source workingDir: /workspace/source
command: ["/bin/sh"]
args:
- -c
- |
set -e
. /tekton/env/.env
/kaniko/executor \
--dockerfile=$(params.subdirectory)/$(params.dockerfile) \
--context=$(params.subdirectory)/$(params.context) \
--destination=$(params.imageName):$(params.tag) \
--build-arg=PYPI_USERNAME=$PYPI_USERNAME \
--build-arg=PYPI_PASSWORD=$PYPI_PASSWORD \
--skip-tls-verify \
--reproducible \
--verbosity=info
env: env:
- name: DOCKER_CONFIG - name: DOCKER_CONFIG
value: /tekton/home/.docker value: /tekton/home/.docker
args: volumeMounts:
- --dockerfile=$(params.subdirectory)/$(params.dockerfile) - name: env
- --context=$(params.subdirectory)/$(params.context) mountPath: /tekton/env
- --destination=$(params.imageName):$(params.tag)
- --skip-tls-verify
- --reproducible
- --verbosity=info
- --build-arg=PYPI_USERNAME=$(params.pypi-username)
- --build-arg=PYPI_PASSWORD=$(params.pypi-password)