From 439b0cad43c47af5b8349117cc5a212554d27436 Mon Sep 17 00:00:00 2001 From: Dimitris Sotirakis Date: Tue, 20 Dec 2022 12:05:25 +0200 Subject: [PATCH] [v9.3.x] CI: Add automation for github assets publishing (#59491) (#60192) CI: Add automation for github assets publishing (#59491) * Add github.star * Make step depend on fetch images * artifacts -> path * Add github token * Fix custom path * Add case where path is absent * Add GH_REGISTRY secret (cherry picked from commit e9cf8fa7519d73e6029f612437622a2ed4580c8d) --- .drone.star | 26 ++++-- .drone.yml | 124 +++++++++++++++++++++++++++- pkg/build/cmd/main.go | 5 +- pkg/build/cmd/publishgithub.go | 4 + scripts/drone/pipelines/github.star | 36 ++++++++ 5 files changed, 185 insertions(+), 10 deletions(-) create mode 100644 scripts/drone/pipelines/github.star diff --git a/.drone.star b/.drone.star index 9d2a65ebc63..c00c11ac5bf 100644 --- a/.drone.star +++ b/.drone.star @@ -9,14 +9,28 @@ load('scripts/drone/events/main.star', 'main_pipelines') load('scripts/drone/pipelines/docs.star', 'docs_pipelines') load('scripts/drone/events/release.star', 'release_pipelines', 'publish_artifacts_pipelines', 'publish_npm_pipelines', 'publish_packages_pipeline', 'artifacts_page_pipeline') load('scripts/drone/pipelines/publish_images.star', 'publish_image_pipelines_public', 'publish_image_pipelines_security') +load('scripts/drone/pipelines/github.star', 'publish_github_pipeline') load('scripts/drone/version.star', 'version_branch_pipelines') load('scripts/drone/events/cron.star', 'cronjobs') load('scripts/drone/vault.star', 'secrets') +edition = 'oss' + def main(ctx): - edition = 'oss' - return pr_pipelines(edition=edition) + main_pipelines(edition=edition) + release_pipelines() + \ - publish_image_pipelines_public() + publish_image_pipelines_security() + \ - publish_artifacts_pipelines('security') + publish_artifacts_pipelines('public') + \ - publish_npm_pipelines('public') + publish_packages_pipeline() + artifacts_page_pipeline() + \ - version_branch_pipelines() + cronjobs(edition=edition) + secrets() + return ( + pr_pipelines(edition=edition) + + main_pipelines(edition=edition) + + release_pipelines() + + publish_image_pipelines_public() + + publish_image_pipelines_security() + + publish_github_pipeline('public') + + publish_github_pipeline('security') + + publish_artifacts_pipelines('security') + + publish_artifacts_pipelines('public') + + publish_npm_pipelines('public') + + publish_packages_pipeline() + + artifacts_page_pipeline() + + version_branch_pipelines() + + cronjobs(edition=edition) + + secrets() + ) diff --git a/.drone.yml b/.drone.yml index 3a72db10b15..9c92617f58e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3554,6 +3554,128 @@ volumes: clone: retries: 3 depends_on: [] +environment: + EDITION: enterprise2 +image_pull_secrets: +- dockerconfigjson +kind: pipeline +name: publish-github-public +node: + type: no-parallel +platform: + arch: amd64 + os: linux +services: [] +steps: +- commands: + - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd + depends_on: [] + environment: + CGO_ENABLED: 0 + image: golang:1.19.3 + name: compile-build-cmd +- commands: + - ./bin/build artifacts docker fetch --edition enterprise2 + depends_on: + - compile-build-cmd + environment: + DOCKER_PASSWORD: + from_secret: docker_password + DOCKER_USER: + from_secret: docker_username + GCP_KEY: + from_secret: gcp_key + image: google/cloud-sdk + name: fetch-images-enterprise2 + volumes: + - name: docker + path: /var/run/docker.sock +- commands: + - ./bin/build publish github --repo $${GH_REGISTRY} --create + depends_on: + - fetch-images-enterprise2 + environment: + GH_REGISTRY: + from_secret: gh_registry + GH_TOKEN: + from_secret: github_token + image: grafana/grafana-ci-deploy:1.3.3 + name: publish-github +trigger: + event: + - promote + target: + - public +type: docker +volumes: +- host: + path: /var/run/docker.sock + name: docker +--- +clone: + retries: 3 +depends_on: [] +environment: + EDITION: enterprise2 +image_pull_secrets: +- dockerconfigjson +kind: pipeline +name: publish-github-security +node: + type: no-parallel +platform: + arch: amd64 + os: linux +services: [] +steps: +- commands: + - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd + depends_on: [] + environment: + CGO_ENABLED: 0 + image: golang:1.19.3 + name: compile-build-cmd +- commands: + - ./bin/build artifacts docker fetch --edition enterprise2 + depends_on: + - compile-build-cmd + environment: + DOCKER_PASSWORD: + from_secret: docker_password + DOCKER_USER: + from_secret: docker_username + GCP_KEY: + from_secret: gcp_key + image: google/cloud-sdk + name: fetch-images-enterprise2 + volumes: + - name: docker + path: /var/run/docker.sock +- commands: + - ./bin/build publish github --repo $${GH_REGISTRY} --create + depends_on: + - fetch-images-enterprise2 + environment: + GH_REGISTRY: + from_secret: gh_registry + GH_TOKEN: + from_secret: github_token + image: grafana/grafana-ci-deploy:1.3.3 + name: publish-github +trigger: + event: + - promote + target: + - security +type: docker +volumes: +- host: + path: /var/run/docker.sock + name: docker +--- +clone: + retries: 3 +depends_on: [] image_pull_secrets: - dockerconfigjson kind: pipeline @@ -5512,6 +5634,6 @@ kind: secret name: packages_secret_access_key --- kind: signature -hmac: 2b1b5ade4e8007a9d5b76ec2dbc9e647ca0938e00713b3ad8e8163bce2db40a6 +hmac: c2c81ccb90eff41fcf2929631f42c7d81d1d6b9965a39320be9f6da55128d2dd ... diff --git a/pkg/build/cmd/main.go b/pkg/build/cmd/main.go index 46d8ef8f32a..555e10ad2c2 100644 --- a/pkg/build/cmd/main.go +++ b/pkg/build/cmd/main.go @@ -200,9 +200,8 @@ func main() { Flags: []cli.Flag{ &dryRunFlag, &cli.StringFlag{ - Name: "path", - Required: true, - Usage: "Path to the asset to be published", + Name: "path", + Usage: "Path to the asset to be published", }, &cli.StringFlag{ Name: "repo", diff --git a/pkg/build/cmd/publishgithub.go b/pkg/build/cmd/publishgithub.go index 02c06b3ab33..9abc9e53af9 100644 --- a/pkg/build/cmd/publishgithub.go +++ b/pkg/build/cmd/publishgithub.go @@ -114,6 +114,10 @@ func getFlags(ctx *cli.Context) (*publishGithubFlags, error) { name := strings.Split(fullRepo, "/")[1] create := ctx.Value("create").(bool) artifactPath := ctx.Value("path").(string) + if artifactPath == "" { + artifactPath = fmt.Sprintf("grafana-enterprise2-%s-amd64.img", metadata.GrafanaVersion) + fmt.Printf("path argument is not provided, resolving to default %s...\n", artifactPath) + } return &publishGithubFlags{ artifactPath: artifactPath, create: create, diff --git a/scripts/drone/pipelines/github.star b/scripts/drone/pipelines/github.star new file mode 100644 index 00000000000..06096327295 --- /dev/null +++ b/scripts/drone/pipelines/github.star @@ -0,0 +1,36 @@ +load( + 'scripts/drone/steps/lib.star', + 'download_grabpl_step', + 'publish_images_step', + 'compile_build_cmd', + 'fetch_images_step', + 'publish_image', +) + +load('scripts/drone/vault.star', 'from_secret') + +load( + 'scripts/drone/utils/utils.star', + 'pipeline', +) + +def publish_github_step(): + return { + 'name': 'publish-github', + 'image': publish_image, + 'commands': ['./bin/build publish github --repo $${GH_REGISTRY} --create'], + 'depends_on': ['fetch-images-enterprise2'], + 'environment': { + 'GH_TOKEN': from_secret('github_token'), + 'GH_REGISTRY': from_secret('gh_registry'), + }, + } + +def publish_github_pipeline(mode): + trigger = { + 'event': ['promote'], + 'target': [mode], + } + return [pipeline( + name='publish-github-{}'.format(mode), trigger=trigger, steps=[compile_build_cmd(), fetch_images_step('enterprise2'), publish_github_step()], edition="", environment = {'EDITION': 'enterprise2'} + ),]