oncall-engine/.drone.yml
Joey Orlando b26706e7e4
configure yamllint pre-commit step (#2728)
# What this PR does

Add [`yamllint`](https://github.com/adrienverge/yamllint) to
`pre-commit` configuration + fix pre-existing errors

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-08-03 02:35:08 -04:00

334 lines
9.5 KiB
YAML

---
kind: pipeline
type: docker
name: Build and Release
steps:
- name: Build Plugin
image: node:18.16.0-buster
commands:
- apt-get update
- apt-get --assume-yes install jq
- cd grafana-plugin/
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else jq ".version=\"${DRONE_TAG#v}\"" package.json > package.new && mv package.new package.json && jq '.version' package.json; fi
# yamllint enable rule:line-length
- yarn --network-timeout 500000
- yarn build
- ls ./
- name: Sign and Package Plugin
image: node:18.16.0-buster
environment:
GRAFANA_API_KEY:
from_secret: gcom_plugin_publisher_api_key
depends_on:
- Build Plugin
commands:
- apt-get update
- apt-get install zip
- cd grafana-plugin
- yarn sign
- if [ ! -f dist/MANIFEST.txt ]; then echo "Sign failed, MANIFEST.txt not created, aborting." && exit 1; fi
- yarn ci-build:finish
- yarn ci-package
- cd ci/dist
- zip -r grafana-oncall-app.zip ./grafana-oncall-app
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, skipping archive"; else cp grafana-oncall-app.zip grafana-oncall-app-${DRONE_TAG}.zip; fi
# yamllint enable rule:line-length
- name: Publish Plugin to GCS (release)
image: plugins/gcs
settings:
acl: allUsers:READER
source: grafana-plugin/ci/dist/grafana-oncall-app-${DRONE_TAG}.zip
target: grafana-oncall-app/releases/grafana-oncall-app-${DRONE_TAG}.zip
token:
from_secret: gcs_oncall_publisher_key
depends_on:
- Sign and Package Plugin
when:
ref:
- refs/tags/v*.*.*
- name: Lint Backend
image: python:3.11.4
environment:
DJANGO_SETTINGS_MODULE: settings.ci-test
commands:
- pip install $(grep "pre-commit" engine/requirements-dev.txt)
- pre-commit run isort --all-files
- pre-commit run black --all-files
- pre-commit run flake8 --all-files
- name: Unit Test Backend
image: python:3.11.4
environment:
RABBITMQ_URI: amqp://rabbitmq:rabbitmq@rabbit_test:5672
DJANGO_SETTINGS_MODULE: settings.ci-test
SLACK_CLIENT_OAUTH_ID: 1
commands:
- apt-get update && apt-get install -y netcat-traditional
- cd engine/
- pip install -r requirements.txt -r requirements-dev.txt
- ./wait_for_test_mysql_start.sh && pytest
depends_on:
- rabbit_test
- name: Image Tag
image: alpine
commands:
- apk add --no-cache bash git sed
- git fetch origin --tags
- chmod +x ./tools/image-tag.sh
- echo $(./tools/image-tag.sh)
- echo $(./tools/image-tag.sh) > .tags
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else sed "0,/VERSION.*/ s/VERSION.*/VERSION = \"${DRONE_TAG}\"/g" engine/settings/base.py > engine/settings/base.temp && mv engine/settings/base.temp engine/settings/base.py; fi
# yamllint enable rule:line-length
- cat engine/settings/base.py | grep VERSION | head -1
when:
ref:
- refs/heads/dev
- refs/tags/v*.*.*
- name: Build and Push Engine Docker Image Backend to GCR
image: plugins/docker
environment:
# force docker to use buildkit feature, this will skip build stages that aren't required in
# the final image (ie. dev & dev-enterprise)
# https://github.com/docker/cli/issues/1134#issuecomment-406449342
DOCKER_BUILDKIT: 1
settings:
repo: us.gcr.io/kubernetes-dev/oncall
dockerfile: engine/Dockerfile
context: engine/
target: prod
config:
from_secret: gcr_admin
depends_on:
- Lint Backend
- Unit Test Backend
- Image Tag
- name: Build and Push Engine Docker Image Backend to Dockerhub
image: plugins/docker
environment:
# force docker to use buildkit feature, this will skip build stages that aren't required in
# the final image (ie. dev & dev-enterprise)
# https://github.com/docker/cli/issues/1134#issuecomment-406449342
DOCKER_BUILDKIT: 1
settings:
repo: grafana/oncall
dockerfile: engine/Dockerfile
context: engine/
target: prod
password:
from_secret: docker_password
username:
from_secret: docker_username
depends_on:
- Lint Backend
- Unit Test Backend
- Image Tag
when:
ref:
- refs/heads/dev
# Services for Unit Test Backend
services:
- name: rabbit_test
image: rabbitmq:3.12.0
environment:
RABBITMQ_DEFAULT_USER: rabbitmq
RABBITMQ_DEFAULT_PASS: rabbitmq
- name: mysql_test
image: mysql:8.0.32
environment:
MYSQL_DATABASE: oncall_local_dev
MYSQL_ROOT_PASSWORD: local_dev_pwd
trigger:
event:
include:
- tag
- push
- pull_request
ref:
include:
- refs/heads/main
- refs/heads/dev
- refs/tags/v*.*.*
---
kind: pipeline
type: docker
name: OSS plugin release
steps:
- name: build plugin
image: node:18.16.0-buster
commands:
- apt-get update
- apt-get --assume-yes install jq
- cd grafana-plugin/
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else jq ".version=\"${DRONE_TAG#v}\"" package.json > package.new && mv package.new package.json && jq '.version' package.json; fi
# yamllint enable rule:line-length
- yarn --network-timeout 500000
- yarn build
- ls ./
- name: sign and package plugin
image: node:18.16.0-buster
environment:
GRAFANA_API_KEY:
from_secret: gcom_plugin_publisher_api_key
depends_on:
- build plugin
commands:
- apt-get update
- apt-get install zip
- cd grafana-plugin
- yarn sign
- if [ ! -f dist/MANIFEST.txt ]; then echo "Sign failed, MANIFEST.txt not created, aborting." && exit 1; fi
- yarn ci-build:finish
- yarn ci-package
- cd ci/dist
- zip -r grafana-oncall-app.zip ./grafana-oncall-app
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, skipping archive"; else cp grafana-oncall-app.zip grafana-oncall-app-${DRONE_TAG}.zip; fi
# yamllint enable rule:line-length
- name: publish plugin to grafana.com (release)
image: curlimages/curl:7.73.0
environment:
GRAFANA_API_KEY:
from_secret: gcom_plugin_publisher_api_key
commands:
# yamllint disable rule:line-length
- 'curl -f -s -H "Authorization: Bearer $${GRAFANA_API_KEY}" -d "download[any][url]=https://storage.googleapis.com/grafana-oncall-app/releases/grafana-oncall-app-${DRONE_TAG}.zip" -d "download[any][md5]=$$(curl -sL https://storage.googleapis.com/grafana-oncall-app/releases/grafana-oncall-app-${DRONE_TAG}.zip | md5sum | cut -d'' '' -f1)" -d url=https://github.com/grafana/oncall/grafana-plugin https://grafana.com/api/plugins'
# yamllint enable rule:line-length
depends_on:
- sign and package plugin
trigger:
event:
- promote
target:
- oss
ref:
- refs/tags/v*.*.*
---
kind: pipeline
type: docker
name: OSS engine release
steps:
- name: set engine version
image: alpine
commands:
- apk add --no-cache bash sed
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else sed "0,/VERSION.*/ s/VERSION.*/VERSION = \"${DRONE_TAG#v}\"/g" engine/settings/base.py > engine/settings/base.temp && mv engine/settings/base.temp engine/settings/base.py; fi
# yamllint enable rule:line-length
- cat engine/settings/base.py | grep VERSION | head -1
- name: build and push docker image
image: thegeeklab/drone-docker-buildx:24.1.0
# From the docs (https://drone-plugin-index.geekdocs.de/plugins/drone-docker-buildx/) regarding privileged=true:
#
# Be aware that the this plugin requires privileged capabilities, otherwise the integrated
# Docker daemon is not able to start.
privileged: true
settings:
repo: grafana/oncall
tags: latest,${DRONE_TAG}
platforms: linux/arm64/v8,linux/amd64
dockerfile: engine/Dockerfile
target: prod
context: engine/
password:
from_secret: docker_password
username:
from_secret: docker_username
depends_on:
- set engine version
trigger:
event:
- promote
target:
- oss
ref:
- refs/tags/v*.*.*
---
# Secret for pulling docker images.
kind: secret
name: dockerconfigjson
get:
path: secret/data/common/gcr
name: .dockerconfigjson
---
# Secret for pushing docker images.
kind: secret
name: gcr_admin
get:
path: infra/data/ci/gcr-admin
name: .dockerconfigjson
---
# Slack webhook
get:
name: slack-plugin
path: infra/data/ci/oncall/drone
kind: secret
name: slack_webhook
---
# GCOM plugin publisher
get:
name: gcom-plugin-publisher
path: infra/data/ci/oncall/drone
kind: secret
name: gcom_plugin_publisher_api_key
---
# GCS bucket
get:
name: gcs-oncall-drone-publisher
path: infra/data/ci/oncall/drone
kind: secret
name: gcs_oncall_publisher_key
---
# Dockerhub
get:
name: username
path: infra/data/ci/docker_hub
kind: secret
name: docker_username
---
get:
name: password
path: infra/data/ci/docker_hub
kind: secret
name: docker_password
---
# Drone
get:
name: machine-user-token
path: infra/data/ci/drone
kind: secret
name: drone_token
---
kind: signature
hmac: 8b387638ef35f86ed9f8c8c964726e0ae703beb7d0f18e053b5041ab8ee9bed2
...