This commit is contained in:
병준 박 2025-04-12 13:41:04 +00:00
parent d9064d1343
commit 296edaeb47

View File

@ -10,7 +10,7 @@ spec:
default: "" default: ""
- name: imageName - name: imageName
description: Base image name with registry (e.g. registry.unbox-x.net/unbox-x-aisi-cron-app) description: Base image name with registry (e.g. docker.unbox-x.net/registry/unbox-x-aisi-cron-app)
type: string type: string
- name: tag - name: tag
@ -39,54 +39,43 @@ spec:
description: Final pushed image URL with tag (e.g. registry/app:v0.2.0) description: Final pushed image URL with tag (e.g. registry/app:v0.2.0)
steps: steps:
- name: build-and-push # 🔐 인증 정보 생성
- name: write-docker-config
image: alpine:3.21.3 image: alpine:3.21.3
workingDir: /workspace/source workingDir: /workspace/source
env:
- name: DOCKER_CONFIG
value: /tekton/home/.docker
script: | script: |
#!/bin/sh #!/bin/sh
set -e set -e
echo "📦 Installing curl and tar..."
apk add --no-cache curl tar
if [ -n "$(params.subdirectory)" ]; then if [ -n "$(params.subdirectory)" ]; then
cd "$(params.subdirectory)" cd "$(params.subdirectory)"
fi fi
IMAGE="$(params.imageName):$(params.tag)" IMAGE="$(params.imageName):$(params.tag)"
echo "📦 Using image: $IMAGE"
echo -n "$IMAGE" > /tekton/results/imageUrl
USERNAME=$(cat /workspace/docker-auth/username) USERNAME=$(cat /workspace/docker-auth/username)
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 "🔐 Writing Docker config for $REGISTRY..." echo "🔐 Writing Docker config for $REGISTRY..."
mkdir -p "$DOCKER_CONFIG" mkdir -p /tekton/home/.docker
cat > "$DOCKER_CONFIG/config.json" <<EOF echo "{\"auths\": {\"$REGISTRY\": {\"auth\": \"$(echo -n "$USERNAME:$PASSWORD" | base64)"}}}" \
{ > /tekton/home/.docker/config.json
"auths": {
"$REGISTRY": {
"auth": "$(echo -n "$USERNAME:$PASSWORD" | base64)"
}
}
}
EOF
echo "📥 Downloading Kaniko executor..." # 🏗️ Kaniko 공식 이미지 실행
curl -sSL -o /kaniko.tar.gz https://github.com/GoogleContainerTools/kaniko/releases/download/v1.23.2/executor-linux-amd64.tar.gz - name: kaniko-build
mkdir -p /kaniko && tar -xzf /kaniko.tar.gz -C /kaniko image: gcr.io/kaniko-project/executor:v1.23.2
chmod +x /kaniko/executor workingDir: /workspace/source
env:
echo "🚀 Building and pushing image..." - name: DOCKER_CONFIG
/kaniko/executor \ value: /tekton/home/.docker
--dockerfile="$(params.dockerfile)" \ args:
--context="$(params.context)" \ - --dockerfile=$(params.subdirectory)/$(params.dockerfile)
--destination="$IMAGE" \ - --context=$(params.subdirectory)/$(params.context)
--skip-tls-verify \ - --destination=$(params.imageName):$(params.tag)
--reproducible \ - --skip-tls-verify
--verbosity=info - --reproducible
- --verbosity=info