Initial commit

This commit is contained in:
Victor Parra 2023-02-09 17:06:27 +01:00 committed by parra
commit 4b6c2b5973
3 changed files with 177 additions and 0 deletions

120
.drone.yml Normal file
View File

@ -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

5
Dockerfile Normal file
View File

@ -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

52
script.sh Normal file
View File

@ -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