Files
drone-publish-tool/.drone.yml
Patrick Gniza 668836a8fa
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
drone.yml update
2025-11-08 17:20:20 +01:00

110 lines
3.4 KiB
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
kind: pipeline
type: docker
name: build-sign-and-release
steps:
# --------------------------------------------------
# 1⃣ Build & Push Image
# --------------------------------------------------
- name: build-and-push
image: docker:26
privileged: true
environment:
REGISTRY_URL:
from_secret: REGISTRY_URL
DOCKER_USER:
from_secret: DOCKER_USER
DOCKER_PASS:
from_secret: DOCKER_PASS
volumes:
- name: docker_sock
path: /var/run/docker.sock
commands:
- echo "=== 🏗️ Building and Pushing Image ==="
- docker login $REGISTRY_URL -u "$DOCKER_USER" -p "$DOCKER_PASS"
- VERSION_TAG="v$DRONE_BUILD_NUMBER"
- IMAGE_NAME="public/drone-publish-tool"
- IMAGE_FULL="$REGISTRY_URL/$IMAGE_NAME:$VERSION_TAG"
- echo "Building image $IMAGE_FULL ..."
- docker build -t $IMAGE_FULL .
- docker tag $IMAGE_FULL $REGISTRY_URL/$IMAGE_NAME:latest
- echo "Pushing images to $REGISTRY_URL ..."
- docker push $IMAGE_FULL
- docker push $REGISTRY_URL/$IMAGE_NAME:latest
- DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' $IMAGE_FULL)
- echo "VERSION_TAG=$VERSION_TAG" >> build.env
- echo "IMAGE_FULL=$IMAGE_FULL" >> build.env
- echo "IMAGE_DIGEST=$DIGEST" >> build.env
- echo "✅ Build and push complete."
outputs:
- build.env
- name: export-env
image: alpine:3.20
commands:
- echo "=== 📦 Loading build.env into environment ==="
- export $(cat build.env | xargs)
- echo "IMAGE_DIGEST=$IMAGE_DIGEST" >> /drone/env
- echo "IMAGE_FULL=$IMAGE_FULL" >> /drone/env
- echo "VERSION_TAG=$VERSION_TAG" >> /drone/env
depends_on:
- build-and-push
# --------------------------------------------------
# 2⃣ Sign Image with Cosign (Secret-Key aus Variable)
# --------------------------------------------------
- name: sign-image
image: gcr.io/projectsigstore/cosign:v2.4.0
entrypoint: ["cosign"]
args:
- "sign"
- "--yes"
- "--key"
- "env://COSIGN_KEY"
- "$${IMAGE_DIGEST}"
environment:
COSIGN_KEY:
from_secret: COSIGN_KEY
COSIGN_PASSWORD:
from_secret: COSIGN_PASSWORD
depends_on:
- export-env
# --------------------------------------------------
# 3⃣ Create Gitea Release
# --------------------------------------------------
- name: create-release
image: curlimages/curl:8.10.1
environment:
GITEA_URL:
from_secret: GITEA_URL
GITEA_TOKEN:
from_secret: GITEA_TOKEN
commands:
- echo "=== 🏷️ Creating Gitea release ==="
- . build.env
- RELEASE_NAME="Release $VERSION_TAG"
- RELEASE_BODY="Automatisch erstellter Release für Build $DRONE_BUILD_NUMBER\n\nImage:\n\`\`\`\n$IMAGE_FULL\n\`\`\`"
- |
curl -s -X POST "$GITEA_URL/api/v1/repos/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/releases" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"$VERSION_TAG\",
\"name\": \"$RELEASE_NAME\",
\"body\": \"$RELEASE_BODY\",
\"draft\": false,
\"prerelease\": false
}"
- echo "✅ Release created in Gitea."
depends_on:
- sign-image
volumes:
- name: docker_sock
host:
path: /var/run/docker.sock