Drone pipeline steps¶
Notify start¶
- name: notify start
image: plugins/matrix
settings:
homeserver:
from_secret: matrix_home_server
roomid:
from_secret: matrix_room_id
username:
from_secret: matrix_username
password:
from_secret: matrix_password
accesstoken:
from_secret: matrix_access_token
template: |-
[${DRONE_REPO_NAME}]
Build **started** for [${DRONE_REPO_NAME}#${DRONE_COMMIT_SHA:0:8}](${DRONE_BUILD_LINK}) (${DRONE_BRANCH}) by ${DRONE_COMMIT_AUTHOR}.
Linting¶
# Flake8
- name: flake8
image: python
commands:
- pip install flake8
- flake8 app
# Black
- name: black
image: python
commands:
- pip install black
- black app
# Helm3 chart lint
- name: lint charts home-assistant
image: evertjstam/drone-helm3:0.16
settings:
mode: lint
chart: ./charts
Testing¶
Build step¶
Example to build an app for Nginx. The files will be available for the next step to pickup and use in the docker image.
Docker image¶
Build the docker image and push it to a repository
# Build the Docker image
- name: build docker image
image: plugins/docker
settings:
autotag: true
registry: gitea.lemoen-eijsden.nl
username:
from_secret: docker_username
password:
from_secret: docker_password
repo: gitea.lemoen-eijsden.nl/${DRONE_REPO}
tags:
- "${DRONE_COMMIT_SHA:0:8}"
- latest
mtu: 1450
Deploy¶
Deployment with Helm3. I use an altered drone-helm3 plugin which is build especially for arm64 (RPi4-64 bit) and has additional privilegde repo entries to retrieve the images from my own image chartmuseum part of Gitea instance.
More info can be found on Docker hub - evertjstam
Example for local charts in the project:
- name: update home-assistant helm
image: evertjstam/drone-helm3:0.16
settings:
mode: upgrade
username:
from_secret: docker_username
password:
from_secret: docker_password
namespace: home-assistant
chart: ./charts
release: home-assistant
wait_for_upgrade: true
timeout: "20m"
values_files:
- values.yaml
environment:
KUBE_API_SERVER:
from_secret: k3s_server
KUBE_TOKEN:
from_secret: k3s_token
KUBE_CERTIFICATE:
from_secret: k3s_cert
KUBE_SERVICE_ACCOUNT: default
Example for external charts hosted in package registry:
- name: deploy
image: evertjstam/drone-helm3:0.16
settings:
mode: upgrade
wait: true
add_repos:
- "helm=https://gitea.lemoen-eijsden.nl/api/packages/evertjanstamhuis/helm"
username:
from_secret: docker_username
password:
from_secret: docker_password
namespace: dev
chart: helm/docs
release: docs
values:
- image.tag=${DRONE_COMMIT_SHA:0:8}
values_files:
- charts/values.yaml
environment:
KUBE_API_SERVER:
from_secret: k3s_server
KUBE_TOKEN:
from_secret: k3s_token
KUBE_CERTIFICATE:
from_secret: k3s_cert
KUBE_SERVICE_ACCOUNT: default
Build and push chart to package registry¶
I use and altered version of drone-chartmuseum. This is special build for arm64 (RPi4-64 bit) and has additional privilegde repo entries to push the images to my own image chartmuseum part of Gitea instance.
- name: package and push charts
image: evertjstam/drone-chartmuseum:2.0.1
settings:
helm_repo: https://gitea.lemoen-eijsden.nl/api/packages/evertjanstamhuis/helm
username:
from_secret: docker_username
password:
from_secret: docker_password
Notify status¶
Example with Matrix notification
- name: notify build status
image: plugins/matrix
settings:
homeserver:
from_secret: matrix_home_server
roomid:
from_secret: matrix_room_id
username:
from_secret: matrix_username
password:
from_secret: matrix_password
accesstoken:
from_secret: matrix_access_token
template: |-
[${DRONE_REPO_NAME}]
Build stage **${DRONE_STAGE_STATUS}** for [${DRONE_REPO_NAME}#${DRONE_COMMIT_SHA:0:8}](${DRONE_BUILD_LINK}) (${DRONE_BRANCH}) by ${DRONE_COMMIT_AUTHOR}.
Build **${DRONE_BUILD_STATUS}** for [${DRONE_REPO_NAME}#${DRONE_COMMIT_SHA:0:8}](${DRONE_BUILD_LINK}) (${DRONE_BRANCH}) by ${DRONE_COMMIT_AUTHOR}.
when:
status:
- success
- failure
Example with discord notification:
- name: discord notification finished
image: appleboy/drone-discord
settings:
webhook_id:
from_secret: discord_webhook_id
webhook_token:
from_secret: discord_webhook_token
message: >
{{#success build.status}}
build {{build.number}} succeeded. Good job.
find it at: gitea.lemoen-eijsden.nl/${DRONE_REPO}
{{else}}
build {{build.number}} failed for ${DRONE_TAG}. Fix me please.
{{/success}}