oncall-engine/.drone.yml
Matias Bordese 2aab2a3e04
Remove v prefix from plugin version on build (#2540)
Related to https://github.com/grafana/oncall/issues/458

Change version naming for plugin and docker releases to drop the `v`
prefix (ie. `1.2.3` instead of `v1.2.3`).
Update both to keep consistency between plugin and engine versions,
which are also checked to match.
2023-07-17 13:59:16 +00:00

339 lines
9.3 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/
- 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
- 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
- if [ -z "$DRONE_TAG" ]; then echo "No tag, skipping archive"; else cp grafana-oncall-app.zip grafana-oncall-app-${DRONE_TAG}.zip; fi
- name: Publish Plugin to Github (release)
image: plugins/github-release
settings:
api_key:
from_secret: gh_token
files: grafana-plugin/ci/dist/grafana-oncall-app-${DRONE_TAG}.zip
title: ${DRONE_TAG}
depends_on:
- Sign and Package Plugin
when:
ref:
- refs/tags/v*.*.*
- 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.3
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.3
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
- 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
- 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
- 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/
- 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
- 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
- if [ -z "$DRONE_TAG" ]; then echo "No tag, skipping archive"; else cp grafana-oncall-app.zip grafana-oncall-app-${DRONE_TAG}.zip; fi
- 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:
- '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'
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
- 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
- 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
---
# Secret for GitHub
get:
name: pat
path: infra/data/ci/github/grafanabot
kind: secret
name: gh_token
---
# 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: 1ca79af7b8ada54237e4fb78fffb9314babc00b3a8a4866ec454d32356bc067b
...