From 4b6c2b59730f97254990e9918edd1429ecb89675 Mon Sep 17 00:00:00 2001 From: Victor Parra Date: Thu, 9 Feb 2023 17:06:27 +0100 Subject: [PATCH] Initial commit --- .drone.yml | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 5 +++ script.sh | 52 +++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 script.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..1f95534 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,120 @@ +kind: pipeline +type: docker +name: build + +steps: +- name: Build docker image + image: registry.cuzo.dev/plugins/docker + privileged: true + volumes: + - name: manifest + path: docker + settings: + repo: parrazam/drone-ntfy + auto_tag: true + mirror: https://registry.cuzo.dev + username: + from_secret: docker_hub_user + password: + from_secret: docker_hub_pass + +image_pull_secrets: +- custom_mirror_registry + +trigger: + event: + - push + - tag + exclude: + - pull_request + +--- +kind: pipeline +type: docker +name: manifest + +steps: +- name: Upload manifest + image: registry.cuzo.dev/plugins/manifest + privileged: true + volumes: + - name: manifest + path: docker + settings: + target: parrazam/drone-ntfy + auto_tag: true + ignore_missing: true + username: + from_secret: docker_hub_user + password: + from_secret: docker_hub_pass + +depends_on: +- build + +image_pull_secrets: +- custom_mirror_registry + +trigger: + event: + - push + - tag + exclude: + - pull_request + +--- +kind: pipeline +type: docker +name: release + +steps: +- name: release + image: registry.cuzo.dev/plugins/gitea-release + settings: + api_key: + from_secret: drone_api_key + base_url: https://git.parravidales.es + when: + ref: + - refs/tags/* + +depends_on: +- manifest + +image_pull_secrets: +- custom_mirror_registry + +trigger: + event: + - tag + +--- +kind: pipeline +type: docker +name: Notify result + +steps: +- name: send ntfy notification + image: registry.cuzo.dev/parrazam/drone-ntfy + settings: + url: https://ntfy.parravidales.es + topic: pipelines + priority: low + username: + from_secret: ntfy_user + password: + from_secret: ntfy_password + +depends_on: +- manifest +- release + +image_pull_secrets: +- custom_mirror_registry + +trigger: + event: + - push + - tag + exclude: + - pull_request \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2325933 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine +ADD script.sh /bin/ +RUN chmod +x /bin/script.sh +RUN apk -Uuv add curl ca-certificates +ENTRYPOINT /bin/script.sh diff --git a/script.sh b/script.sh new file mode 100644 index 0000000..ff4de84 --- /dev/null +++ b/script.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +DEFAULT_TAGS="drone,$CI_REPO_NAME/$CI_COMMIT_BRANCH" +BASE_URL=${PLUGIN_URL:-"https://ntfy.sh"} +TOPIC=$PLUGIN_TOPIC # mandatory +TITLE="Build #$DRONE_BUILD_NUMBER $DRONE_BUILD_STATUS" +PRIORITY=${PLUGIN_PRIORITY:-""} +TAGS=${PLUGIN_TAGS:-""} + +MESSAGE="[${CI_COMMIT_SHA:0:8}] $CI_COMMIT_MESSAGE" + +if [ -z "$TOPIC" ] +then + echo "Topic cannot be empty."; + exit 1 +fi + +URL="$BASE_URL/$TOPIC" + +if [ $DRONE_BUILD_STATUS = "success" ] +then + DEFAULT_TAGS="$DEFAULT_TAGS,white_check_mark" +elif [ $DRONE_BUILD_STATUS = "failure" ] +then + DEFAULT_TAGS="$DEFAULT_TAGS,x" +else + DEFAULT_TAGS="$DEFAULT_TAGS,grey_question" +fi + +TAGS="$DEFAULT_TAGS,$TAGS" +TAGS=${TAGS%,} + +HTTP_STATUS=$( +curl \ + -o /dev/null -s -w "%{http_code}\n" \ + --retry 3 --retry-delay 5 \ + -u $PLUGIN_USERNAME:$PLUGIN_PASSWORD \ + -H title:"$TITLE" \ + -H tags:$TAGS \ + -H prio:$PRIORITY \ + -H "Actions: view, Build, $DRONE_BUILD_LINK; view, Changes, $DRONE_COMMIT_LINK" \ + -d "$MESSAGE" \ + $URL +) + +if [ $? -eq 0 ] && [ $HTTP_STATUS -eq 200 ] +then + echo "Message sent!" +else + echo "Error publishing notification." + exit 2 +fi