dc6bd2a20a
* CI: move grafana-build into pkg/build (#105640) * move grafana-build into pkg/build * Update go.mod/go.sum files after cherry-pick build - Updates from workspace sync after cherry-picking daggerbuild package - Resolves dependency conflicts from pkg/build integration - Required for successful build after CI migration backport * CI Migration: Replace .github with main branch version - Complete replacement of .github directory from main branch - Includes updated workflows, actions, and configuration files - Ensures all CI improvements from main are included - Next step: fix branch-specific issues in separate commits * Fix branch triggers: Update workflows to target release branches - Update 8 workflows to trigger on release-* instead of main - Ensures workflows run on pull requests to release branches - Workflows updated: documentation-ci, pr-codeql-analysis-*, pr-dependabot-update-go-workspace, pr-go-workspace-check, pr-k8s-codegen-check, verify-kinds, codeowners-validator * Fix branch triggers: Update workflows to target both main and release branches - CORRECTED: Include both main and release-* branch patterns - Ensures workflows run on both main branch (original functionality) and release branches (needed for backport) - Previous commit incorrectly removed main branch support - Workflows updated: documentation-ci, pr-codeql-analysis-*, pr-dependabot-update-go-workspace, pr-go-workspace-check, pr-k8s-codegen-check, verify-kinds, codeowners-validator * CI Migration: Update .gitignore to allow OSS wire file to be committed - Remove **/wire_gen.go (allow pkg/server/wire_gen.go to be committed) - Add /pkg/server/enterprise_wire_gen.go (keep enterprise wire file ignored) - This enables the new committed wire files architecture for CI * CI Migration: Add enhanced wire tool with automatic build constraints - Backport enhanced wire tool from main branch with -gen_tags flag - This enables automatic regeneration with proper constraints to prevent conflicts - Wire file contains all required functions: Initialize, InitializeDocumentBuilders, etc. - Solves the missing wire functions issue causing CI failures - Enhanced tool ensures build constraints persist on regeneration * CI Migration: Update Makefile to use enhanced wire tool with build constraints - Update gen-go target to use -gen_tags flag for automatic build constraints - Ensures future engineers get proper build constraints when running 'make gen-go' - Matches main branch approach for consistent wire file generation - Removes dependency on WIRE_TAGS variable and GO_RACE_FLAG for simplicity * Add gen-enterprise-go target to Makefile for release-12.0.3 - Backports gen-enterprise-go target from main branch - Enables enterprise wire file generation in release branches - Part of CI migration backport wire infrastructure fixes - Resolves CI issues where enterprise wire functions were missing * Fix wire tool golden file format for Drone CI compatibility - Update all 43 golden test files to match main branch format - Change go:generate command from github.com/google/wire/cmd/wire to ./pkg/build/wire/cmd/wire/main.go - Remove legacy '// +build !wireinject' constraints - Fixes Drone CI test failures that were blocking OSS PR merge - All wire tests now pass successfully This aligns the backport branch with the golden file format updates that were made in main branch when the wire tool was enhanced. * Update swagger specs to include enterprise APIs - Regenerated api-enterprise-spec.json with enterprise API definitions - Updated api-merged.json with merged OSS and enterprise specs - Regenerated openapi3.json with complete API specifications - Fixes enterprise CI swagger generation validation failures - Enterprise APIs now properly detected and documented * Fix OSS integration tests missing enterprise build tags in Drone CI - Add -tags=enterprise to all integration test steps in lib.star - Fixes test-backend-integration, postgres-integration-tests, and mysql-integration-tests - Regenerate .drone.yml with proper enterprise build tags - Resolves 'server could not find the requested resource' errors for enterprise APIs - Ensures enterprise APIs (querylibrary, reporting, banners, scim) are registered during tests - Aligns OSS Drone CI with GitHub Actions behavior and enterprise repository * Fix CODEOWNERS for release-12.0.3 compatibility - Remove 21 entries that reference files/directories not present in release branch - Resolves File Exist Checker failures in codeowners-validator workflow - Maintains team ownership assignments from main branch for existing files - Lines removed: .air.toml, apps/secret/, apps/iam/, e2e-playwright/, packages/grafana-alerting/, etc. * baldm0mma/ update releasefinder * Add i18n-extract script for release branch compatibility - Add 'i18n-extract': 'make i18n-extract' to package.json scripts - Resolves i18n-verify workflow failure that expects this script - The make target already exists and handles OSS + enterprise i18n extraction - Maintains i18n verification functionality from main branch workflows - Simple safe addition that calls existing make infrastructure * Phase 4: Fix GitHub Actions workflow branch triggers - Add release-*.*.* pattern to 8 workflows missing it - Fix duplicate release branch patterns in 3 workflows - Ensure consistent branch trigger format across all workflows - Critical workflows now properly trigger on release branches Fixes workflows: actionlint, backend-code-checks, go-lint, reject-gh-secrets, run-schema-v2-e2e, shellcheck, swagger-gen, trivy-scan * Fix: Backport E2E runner infrastructure for Enterprise CI - Add e2e/main.go and e2e/internal/ directory from main branch - Add urfave/cli/v3 dependency required by E2E runner - Fixes Enterprise CI failure: 'Build E2E test runner' and 'Build & package Grafana for e2e tests' - Root cause: E2E runner infrastructure was added to main after release-12.0.3 branch creation - Solution: Backport missing E2E runner files to enable Enterprise CI completion Resolves: no Go files in /opt/actions-runner/_work/grafana-enterprise/grafana-enterprise/grafana/e2e * Fix: Update go.mod dependency classification for urfave/cli/v3 - Change urfave/cli/v3 from indirect to direct dependency - Fixes Go Workspace Check failure in CI - Required after adding E2E runner infrastructure that directly imports urfave/cli/v3 - Resolves: make update-workspace corrects dependency classification * Fix: Add team ownership for urfave/cli/v3 dependency - Assign @grafana/grafana-backend-group as owner for github.com/urfave/cli/v3@v3.3.8 - Follows existing pattern: urfave/cli v1 and v2 also owned by grafana-backend-group - Resolves Backend Code Checks / Validate Backend Configs CI failure - Required for E2E runner infrastructure dependency ownership compliance Fixes: modowners check requiring team assignment for newly added dependencies * Fix: Revert experimental E2E playwright infrastructure to stable version - Revert pr-e2e-tests.yml to stable Cypress-based E2E testing - Remove experimental storybook-verification-playwright.yml workflow - Revert run-dashboard-search-e2e.yml and release-pr.yml to use e2e/test-plugins/ - Keep stable E2E runner infrastructure (e2e/main.go + e2e/internal/) - Remove experimental playwright features per team recommendation Team feedback: Playwright tests are experimental and shouldn't be backported to stable release branches * Fix: Complete cleanup of experimental playwright dependencies - Revert package.json to stable version (remove e2e-playwright scripts and path references) - Revert playwright.config.ts to stable plugin-e2e configuration - Remove all experimental playwright infrastructure dependencies - Ensure clean stable E2E testing environment All experimental features removed per team recommendation for stable release branches * Fix: Restore working package.json configuration - Revert package.json to version 12.0.3 (working release branch version) - Fix workspace dependency resolution issues caused by incorrect revert to main branch version - FE tests, betterer, and linting should now work correctly Issue was caused by reverting package.json to main branch (12.1.0-pre) instead of keeping the working release branch configuration (12.0.3) * CI: mirror some CI dependencies (#106148) * mirror some CI dependencies * remove -v from go build * Fix: Backport missing e2e/run-suite script for daggerbuild E2E system The daggerbuild E2E system (used by OSS workflows) expects ./e2e/run-suite to exist, but we only backported the new E2E runner infrastructure. This script is needed for: - OSS workflow: 'go run ./pkg/build/e2e --suite=dashboards-suite' - Legacy Cypress configuration with video support - Integration between daggerbuild and existing Cypress test suites Resolves E2E test failures in OSS workflows where videos directory cannot be found because run-suite script was missing. * Fix: Resolve daggerbuild E2E path doubling issue - Extract just suite name from full path using filepath.Base() - Prevents doubled paths like './e2e/e2e/dashboards-suite/videos' - Resolves 'no spec files found' and 'no such file or directory' errors - GitHub Actions passes full paths like 'e2e/dashboards-suite' but run-suite script expects just 'dashboards-suite' * Infrastructure: Wholesale copy pkg/build/ from main COMPLETE DAGGERBUILD SYSTEM UPDATE: - Modern E2E system with CLI framework and --flags support - New accessibility testing system (a11y/) - New Playwright E2E testing system (e2e-playwright/) - External infrastructure improvements (musl.cc → dl.grafana.com/ci) - Updated daggerbuild core components with latest fixes - Updated Go dependencies and wire modules ARCHITECTURAL COMPATIBILITY VERIFIED: - Modern pkg/build calls: ./e2e-runner cypress --start-grafana=false --cypress-video - Our e2e runner supports: All required parameters including --suite, --env flags - GitHub Actions workflows: Pass compatible arguments - Binary builds: Successfully creates working e2e-runner RESOLVES ISSUES: - Fixes --flags parameter compatibility with GitHub Actions - Includes all follow-up infrastructure improvements - Provides complete, tested system with modern CLI framework - Eliminates external dependency failures (musl.cc timeouts) - Removes need for path doubling workarounds (modern system handles full paths correctly) Replaces incremental cherry-picking with complete, tested system from main. * Dependencies: Update Go modules after pkg/build wholesale copy DEPENDENCY UPDATES: - Updated go.work.sum with new dependencies from modern pkg/build system - Updated all workspace module dependencies (go.mod/go.sum files) - Removed pkg/build/cmd/enterprise.go (enterprise-only file, gets copied during enterprise development) ENTERPRISE INTEGRATION FIX: - enterprise.go file doesn't belong in OSS repository - Gets copied from grafana-enterprise during development mode - Main branch doesn't have this file, explaining module compatibility All Go modules now properly resolved and compatible with modern pkg/build architecture. * Dependencies: Update workspace Go module checksums after pkg/build wholesale copy - Synchronizes all go.sum files across workspace modules - Adds missing .mod.h1 entries that were required after infrastructure update - Resolves Go Workspace Check CI failures - Updates 22 modules: .citools/, apps/, pkg/ subdirectories plus go.work.sum Addresses CI error: 'Please run make update-workspace and commit the changes' * Infrastructure: Revert to pre-Playwright E2E system for release branch compatibility Strategic combination of modern daggerbuild with stable E2E infrastructure: **Modern Daggerbuild (from main):** - Latest CLI framework (github.com/urfave/cli/v3) - External infrastructure fixes (musl.cc → dl.grafana.com/ci) - Complete pkg/build/ system with all enhancements - Updated dependencies and architecture improvements **Stable E2E Infrastructure (pre-Playwright):** - pkg/build/e2e/service.go: Reverted to version before commitb6580ccb10- pkg/build/a11y/: Reverted to stable version compatible with existing infrastructure - Removed experimental pkg/build/e2e-playwright/ system - Removed experimental e2e-playwright/ test infrastructure **Why This Approach:** - GitHub Actions workflows call 'go run ./pkg/build/e2e' (modern system) - Modern system now expects only standard e2e/ directory (compatible) - Release branches have standard e2e/ infrastructure (dashboards-suite, various-suite, etc.) - Eliminates dependency on experimental Playwright infrastructure **Key Dependencies Met:** - e2e/pa11yci.conf.js: Added for a11y test compatibility - /src/e2e directory: Standard directory structure (no e2e-playwright needed) - Existing test plugins: Uses stable e2e/test-plugins/ **Result:** Best of both worlds - modern, reliable daggerbuild infrastructure with proven E2E testing that works across all release branches without requiring experimental dependencies. * Fix: Remove unused embed.go file causing golangci-lint failure - Removes pkg/build/daggerbuild/msi/embed.go with unused embed.FS variable - MSI build process uses directory mounting instead of embedded filesystem - Resolves 'var resources is unused (unused)' linting error * Fix: Update Node.js version to match working E2E configuration - Changes from v22.11.0 to v22.16.0 to match commit17952d45e4- Working commit had all E2E tests passing with same daggerbuild infrastructure - Node.js version differences can affect frontend builds and UI rendering - Ensures consistent environment between working reference and current branch * Fix: Use conditional container base for E2E compatibility - Alpine for OSS tests (better old arch dashboardScene=false compatibility) - Ubuntu for Enterprise tests (when image renderer needed) - Restores original release-12.0.3 Alpine behavior for OSS - Should resolve old arch E2E test failures * Fix: Go fmt formatting for conditional container logic * Revert: Remove unnecessary Alpine/Ubuntu conditional logic - Real issue was wrong environment variable name (dashboardScene vs DISABLE_SCENES) - Keep Ubuntu base (original main branch behavior) for simplicity - Container base was not the root cause of old arch failures * Experiment: Copy scripts/ from pre-Playwright commit (ea0ddb3fc9) - Copied scripts directory from commitea0ddb3fc9(just before Playwright migration) - This overwrites some CI migration fixes but testing if it's actually needed - Can revert back tob9b4602dbdif CI breaks Test commit to see real impact on GitHub Actions workflows. * trigger ci 01 * Fix: Copy .drone.star from main to match scripts structure - Resolves Starlark evaluation error for missing integration_test_pipelines - Aligns .drone.star with main branch scripts structure - Same fix applied to both OSS and Enterprise repositories * make drone * Fix ARM/v7 Docker build failures by using dagger run for cross-compilation - Change artifacts_cmd() in scripts/drone/steps/rgm.star to use 'dagger run go run' instead of 'go run' - Add --max-execution-steps 100000 to make drone target in Makefile to properly regenerate .drone.yml - This fixes CGO cross-compilation issues with SQLite for ARM/v7 Docker builds - Matches the approach already used successfully in Enterprise builds * Fix Docker base image references in rgm build steps - Change from symbolic names (alpine-base, ubuntu-base) to actual Docker images - alpine-base → alpine:3.21.3 - ubuntu-base → ubuntu:22.04 - Add ubuntu and alpine parameters to rgm_artifacts_step and rgm_build_docker_step functions - Fixes Docker pull errors: 'repository does not exist or may require authorization' - Aligns OSS configuration with Enterprise approach --------- Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com>
496 lines
13 KiB
Go
496 lines
13 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"dagger.io/dagger"
|
|
"github.com/grafana/grafana/pkg/build/daggerbuild/backend"
|
|
"github.com/grafana/grafana/pkg/build/daggerbuild/containers"
|
|
"github.com/grafana/grafana/pkg/build/daggerbuild/pipelines"
|
|
)
|
|
|
|
const (
|
|
proName = "enterprise2"
|
|
// 1: The version (with a v prefix)
|
|
// 2: The "edition". Options: 'oss', 'pro', 'enterprise'.
|
|
// 3: The full name. 'grafana', 'grafana-enterprise', 'grafana-pro
|
|
// 4: The 'ersion', or 'version' without the 'v'.
|
|
// 5: The OS: 'windows', 'linux', 'darwin'
|
|
// 6: The architecture: 'amd64', 'armv6', 'armv7', 'arm64'.
|
|
// 7: -musl, sometimes.
|
|
// 8: '.sha256', sometimes.
|
|
tarGzFormat = "artifacts/downloads%[9]s/%[1]s/%[2]s/release/%[3]s-%[4]s.%[5]s-%[6]s%[7]s.tar.gz%[8]s"
|
|
debFormat = "artifacts/downloads%[9]s/%[1]s/%[2]s/release/%[3]s_%[4]s_%[6]s.deb%[8]s"
|
|
rpmFormat = "artifacts/downloads%[9]s/%[1]s/%[2]s/release/%[3]s-%[4]s-1.%[6]s.rpm%[8]s"
|
|
exeFormat = "artifacts/downloads%[9]s/%[1]s/%[2]s/release/%[3]s_%[4]s_%[6]s.exe%[8]s"
|
|
msiFormat = "artifacts/downloads%[9]s/%[1]s/%[2]s/release/%[3]s_%[4]s_%[6]s.msi%[8]s"
|
|
|
|
tarGzMainFormat = "%[2]s/main/%[3]s-%[4]s.%[5]s-%[6]s%[7]s.tar.gz%[8]s"
|
|
debMainFormat = "%[2]s/main/%[3]s_%[4]s_%[6]s.deb%[8]s"
|
|
|
|
// 1: ersion
|
|
// 2. name (grafana-oss | grafana-enterprise)
|
|
// 3: '-ubuntu', if set
|
|
// 4: arch
|
|
// 5: '.sha256', if set
|
|
dockerFormat = "artifacts/docker/%[1]s/%[2]s-%[1]s%[3]s-%[4]s.img%[5]s"
|
|
|
|
// 1: ersion
|
|
// 2. name (grafana-oss | grafana-enterprise)
|
|
cdnFormat = "artifacts/static-assets/%[2]s/%[1]s/public"
|
|
cdnMainFormat = "grafana/%s/public"
|
|
|
|
// 1: ersion
|
|
storybookFormat = "artifacts/storybook/v%[1]s"
|
|
|
|
// 1: version
|
|
// 2: package name (@grafana-ui-10.0.0.tgz)
|
|
npmFormat = "artifacts/npm/v%[1]s/npm-artifacts"
|
|
|
|
sha256Ext = ".sha256"
|
|
grafana = "grafana"
|
|
)
|
|
|
|
// One artifact and be copied to multiple different locations (like armv7 tar.gz packages should be copied to tar.gz and -musl.tar.gz)
|
|
type HandlerFunc func(name string) []string
|
|
|
|
var Handlers = map[string]HandlerFunc{
|
|
".tar.gz": TarGZHandler,
|
|
".deb": DebHandler,
|
|
".rpm": RPMHandler,
|
|
".docker.tar.gz": DockerHandler,
|
|
".exe": EXEHandler,
|
|
".msi": MSIHandler,
|
|
".zip": ZipHandler,
|
|
}
|
|
|
|
func IsMain() bool {
|
|
return os.Getenv("IS_MAIN") != ""
|
|
}
|
|
|
|
func NPMHandler(name string) []string {
|
|
var (
|
|
version = strings.TrimPrefix(os.Getenv("DRONE_TAG"), "v")
|
|
)
|
|
|
|
return []string{fmt.Sprintf(npmFormat, version)}
|
|
}
|
|
|
|
func ZipHandler(name string) []string {
|
|
files := EXEHandler(strings.ReplaceAll(name, "zip", "exe"))
|
|
|
|
for i, v := range files {
|
|
files[i] = strings.ReplaceAll(v, "exe", "zip")
|
|
}
|
|
|
|
return files
|
|
}
|
|
|
|
func MSIHandler(name string) []string {
|
|
files := EXEHandler(strings.ReplaceAll(name, "msi", "exe"))
|
|
|
|
for i, v := range files {
|
|
files[i] = strings.ReplaceAll(v, "exe", "msi")
|
|
}
|
|
|
|
return files
|
|
}
|
|
|
|
func RPMHandler(name string) []string {
|
|
ext := filepath.Ext(name)
|
|
|
|
// If we're copying a sha256 file and not a tar.gz then we want to add .sha256 to the template
|
|
// or just give it emptystring if it's not the sha256 file
|
|
sha256 := ""
|
|
if ext == sha256Ext {
|
|
sha256 = sha256Ext
|
|
}
|
|
|
|
n := filepath.Base(name) // Surprisingly still works even with 'gs://' urls
|
|
opts := pipelines.TarOptsFromFileName(strings.ReplaceAll(strings.ReplaceAll(n, sha256Ext, ""), "rpm", "tar.gz"))
|
|
|
|
// In grafana-build we just use "" to refer to "oss"
|
|
edition := "oss"
|
|
fullName := grafana
|
|
if opts.Edition != "" {
|
|
edition = opts.Edition
|
|
fullName += "-" + opts.Edition
|
|
}
|
|
|
|
goos, arch := backend.OSAndArch(opts.Distro)
|
|
arm := backend.ArchVersion(opts.Distro)
|
|
if arch == "arm" {
|
|
if arm == "7" {
|
|
arch = "armhfp"
|
|
}
|
|
}
|
|
|
|
if arch == "arm64" {
|
|
arch = "aarch64"
|
|
}
|
|
|
|
if arch == "amd64" {
|
|
arch = "x86_64"
|
|
}
|
|
|
|
enterprise2 := ""
|
|
version := opts.Version
|
|
ersion := strings.Replace(strings.TrimPrefix(version, "v"), "-", "~", 1)
|
|
|
|
if edition == "pro" {
|
|
// "pro" in this case is called "enterprise2"
|
|
fullName = "grafana-enterprise2"
|
|
edition = proName
|
|
// and is in the 'downloads-enterprise2' folder instead of 'downloads'
|
|
enterprise2 = "-enterprise2"
|
|
// and has an period separator {version}.{arch} instead of {version}_{arch}
|
|
}
|
|
dst := fmt.Sprintf(rpmFormat, version, edition, fullName, ersion, goos, arch, edition, sha256, enterprise2)
|
|
|
|
return []string{
|
|
dst,
|
|
}
|
|
}
|
|
|
|
func EXEHandler(name string) []string {
|
|
packages := DebHandler(strings.ReplaceAll(name, "exe", "deb"))
|
|
for i, v := range packages {
|
|
v = strings.ReplaceAll(v, "deb", "exe")
|
|
v = strings.ReplaceAll(v, "amd64", "windows-amd64")
|
|
v = strings.ReplaceAll(v, "_", "-")
|
|
v = strings.ReplaceAll(v, "~", "-")
|
|
v = strings.ReplaceAll(v, "-windows", ".windows")
|
|
packages[i] = v
|
|
}
|
|
|
|
return packages
|
|
}
|
|
|
|
func DebHandler(name string) []string {
|
|
ext := filepath.Ext(name)
|
|
format := debFormat
|
|
if IsMain() {
|
|
format = debMainFormat
|
|
}
|
|
|
|
// If we're copying a sha256 file and not a tar.gz then we want to add .sha256 to the template
|
|
// or just give it emptystring if it's not the sha256 file
|
|
sha256 := ""
|
|
if ext == sha256Ext {
|
|
sha256 = sha256Ext
|
|
}
|
|
|
|
n := filepath.Base(name) // Surprisingly still works even with 'gs://' urls
|
|
opts := pipelines.TarOptsFromFileName(strings.ReplaceAll(strings.ReplaceAll(n, sha256Ext, ""), "deb", "tar.gz"))
|
|
|
|
// In grafana-build we just use "" to refer to "oss"
|
|
edition := "oss"
|
|
fullName := grafana
|
|
version := opts.Version
|
|
ersion := strings.TrimPrefix(version, "v")
|
|
ersion = strings.Replace(ersion, "-", "~", 1)
|
|
enterprise2 := ""
|
|
if opts.Edition != "" {
|
|
edition = opts.Edition
|
|
fullName += "-" + opts.Edition
|
|
if edition == "pro" {
|
|
// "pro" in this case is called "enterprise2"
|
|
fullName = "grafana-enterprise2"
|
|
edition = proName
|
|
// and is in the 'downloads-enterprise2' folder instead of 'downloads'
|
|
enterprise2 = "-enterprise2"
|
|
}
|
|
|
|
if edition == "pro-rpi" {
|
|
// "pro" in this case is called "enterprise2"
|
|
fullName = "grafana-enterprise2-rpi"
|
|
edition = proName
|
|
// and is in the 'downloads-enterprise2' folder instead of 'downloads'
|
|
enterprise2 = "-enterprise2"
|
|
}
|
|
|
|
if edition == "rpi" {
|
|
edition = "oss"
|
|
}
|
|
|
|
if edition == "enterprise-rpi" {
|
|
edition = "enterprise"
|
|
}
|
|
}
|
|
|
|
names := []string{fullName}
|
|
goos, arch := backend.OSAndArch(opts.Distro)
|
|
if arch == "arm" {
|
|
arch = "armhf"
|
|
// If we're building for arm then we also copy the same thing, but with the name '-rpi'. for osme reason?
|
|
names = []string{fullName}
|
|
}
|
|
|
|
dst := []string{}
|
|
for _, n := range names {
|
|
dst = append(dst, fmt.Sprintf(format, opts.Version, edition, n, ersion, goos, arch, edition, sha256, enterprise2))
|
|
}
|
|
|
|
return dst
|
|
}
|
|
|
|
func TarGZHandler(name string) []string {
|
|
ext := filepath.Ext(name)
|
|
|
|
// If we're copying a sha256 file and not a tar.gz then we want to add .sha256 to the template
|
|
// or just give it emptystring if it's not the sha256 file
|
|
sha256 := ""
|
|
if ext == sha256Ext {
|
|
sha256 = sha256Ext
|
|
}
|
|
|
|
n := filepath.Base(name) // Surprisingly still works even with 'gs://' urls
|
|
opts := pipelines.TarOptsFromFileName(strings.ReplaceAll(n, sha256Ext, ""))
|
|
|
|
// In grafana-build we just use "" to refer to "oss"
|
|
edition := "oss"
|
|
fullName := grafana
|
|
version := opts.Version
|
|
ersion := strings.TrimPrefix(version, "v")
|
|
enterprise2 := ""
|
|
if opts.Edition != "" {
|
|
edition = opts.Edition
|
|
fullName += "-" + opts.Edition
|
|
if edition == "pro" {
|
|
enterprise2 = "-enterprise2"
|
|
fullName = "grafana-enterprise2"
|
|
edition = proName
|
|
}
|
|
}
|
|
|
|
libc := []string{""}
|
|
goos, arch := backend.OSAndArch(opts.Distro)
|
|
|
|
if arch == "arm64" || arch == "arm" || arch == "amd64" && goos == "linux" {
|
|
libc = []string{"", "-musl"}
|
|
}
|
|
|
|
arm := backend.ArchVersion(opts.Distro)
|
|
if arch == "arm" {
|
|
arch += "v" + arm
|
|
// I guess we don't create an arm-6-musl?
|
|
if arm == "6" {
|
|
libc = []string{""}
|
|
}
|
|
}
|
|
format := tarGzFormat
|
|
if IsMain() {
|
|
format = tarGzMainFormat
|
|
}
|
|
dst := []string{}
|
|
for _, m := range libc {
|
|
dst = append(dst, fmt.Sprintf(format, opts.Version, edition, fullName, ersion, goos, arch, m, sha256, enterprise2))
|
|
}
|
|
|
|
return dst
|
|
}
|
|
|
|
func DockerHandler(name string) []string {
|
|
ext := filepath.Ext(name)
|
|
|
|
// If we're copying a sha256 file and not a tar.gz then we want to add .sha256 to the template
|
|
// or just give it emptystring if it's not the sha256 file
|
|
sha256 := ""
|
|
if ext == sha256Ext {
|
|
sha256 = sha256Ext
|
|
}
|
|
|
|
n := filepath.Base(name) // Surprisingly still works even with 'gs://' urls
|
|
|
|
// try to get .ubuntu.docker.tar.gz.sha256 / .ubuntu.docker.tar.gz / docker.tar.gz to all just end in 'tar.gz'
|
|
normalized := strings.ReplaceAll(n, sha256Ext, "")
|
|
normalized = strings.ReplaceAll(normalized, ".ubuntu", "")
|
|
normalized = strings.ReplaceAll(normalized, ".docker", "")
|
|
|
|
opts := pipelines.TarOptsFromFileName(normalized)
|
|
|
|
// In grafana-build we just use "" to refer to "oss"
|
|
edition := "oss"
|
|
fullName := grafana
|
|
if opts.Edition != "" {
|
|
edition = opts.Edition
|
|
if edition == "pro" {
|
|
edition = proName
|
|
}
|
|
}
|
|
|
|
fullName += "-" + edition
|
|
ubuntu := ""
|
|
if strings.Contains(name, "ubuntu") {
|
|
ubuntu = "-ubuntu"
|
|
}
|
|
|
|
_, arch := backend.OSAndArch(opts.Distro)
|
|
if arch == "arm" {
|
|
arch += "v" + backend.ArchVersion(opts.Distro)
|
|
}
|
|
return []string{
|
|
fmt.Sprintf(dockerFormat, strings.TrimPrefix(opts.Version, "v"), fullName, ubuntu, arch, sha256),
|
|
}
|
|
}
|
|
|
|
func CDNHandler(name string) []string {
|
|
if IsMain() {
|
|
// This folder is is always ${dist}/${version}/${name}/${public}
|
|
dist, err := filepath.Rel(".", filepath.Join(name, "../../../"))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
path, err := filepath.Rel(dist, name)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
s := strings.Split(path, string(os.PathSeparator))
|
|
return []string{fmt.Sprintf(cdnMainFormat, s[0])}
|
|
}
|
|
version := strings.TrimPrefix(os.Getenv("DRONE_TAG"), "v")
|
|
return []string{fmt.Sprintf(cdnFormat, version, grafana)}
|
|
}
|
|
|
|
func StorybookHandler(name string) []string {
|
|
version := strings.TrimPrefix(os.Getenv("DRONE_TAG"), "v")
|
|
return []string{fmt.Sprintf(storybookFormat, version)}
|
|
}
|
|
|
|
// A hopefully temporary script that prints the gsutil commands that will move these artifacts into the location where they were expected previously.
|
|
// Just pipe this into bash or exec or whatever to do the actual copying.
|
|
// Run without redirecting stdout to verify the operations.
|
|
func main() {
|
|
prefix := os.Args[1]
|
|
|
|
ctx := context.Background()
|
|
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var (
|
|
scanner = bufio.NewScanner(os.Stdin)
|
|
authenticator = containers.GCSAuth(client, &containers.GCPOpts{
|
|
ServiceAccountKeyBase64: os.Getenv("GCP_KEY_BASE64"),
|
|
})
|
|
|
|
container = client.Container().From("google/cloud-sdk:alpine")
|
|
)
|
|
//
|
|
if c, err := authenticator.Authenticate(client, container); err == nil {
|
|
container = c
|
|
} else {
|
|
panic(err)
|
|
}
|
|
|
|
for scanner.Scan() {
|
|
var (
|
|
name = scanner.Text()
|
|
)
|
|
handler, ext := getHandler(name, Handlers)
|
|
destinations := handler(name)
|
|
if ext == "" {
|
|
for _, v := range destinations {
|
|
dir := filepath.Join(prefix, filepath.Dir(v))
|
|
v := filepath.Join(prefix, v)
|
|
|
|
log.Println("Creating dir", dir)
|
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
|
panic(err)
|
|
}
|
|
log.Println("Copying", name, "to", v)
|
|
//nolint:gosec
|
|
cmd := exec.Command("cp", "-r", strings.TrimPrefix(name, "file://"), v)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
if err := cmd.Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
continue
|
|
}
|
|
|
|
log.Println("File:", name, "to be copied as", destinations)
|
|
for _, v := range destinations {
|
|
dir := filepath.Join(prefix, filepath.Dir(v))
|
|
v := filepath.Join(prefix, v)
|
|
log.Println("Creating directory", dir)
|
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
log.Println("Copying", name, "to", dir, "as", v)
|
|
|
|
//nolint:gosec
|
|
cmd := exec.Command("cp", strings.TrimPrefix(name, "file://"), v)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
if err := cmd.Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
log.Println("Copying", prefix, "to gcs")
|
|
dst := os.Getenv("DESTINATION")
|
|
container = container.WithMountedDirectory("dist", client.Host().Directory(prefix)).
|
|
WithExec([]string{"gcloud", "storage", "cp", "-r", "/dist/*", dst})
|
|
|
|
stdout, err := container.Stdout(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
stderr, err := container.Stdout(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Fprint(os.Stdout, stdout)
|
|
fmt.Fprint(os.Stderr, stderr)
|
|
}
|
|
|
|
func getHandler(name string, handlers map[string]HandlerFunc) (HandlerFunc, string) {
|
|
ext := filepath.Ext(name)
|
|
// sha256 extensions should be handled the same way what precedes the extension
|
|
if ext == sha256Ext {
|
|
ext = filepath.Ext(strings.ReplaceAll(name, sha256Ext, ""))
|
|
}
|
|
|
|
// tar.gz extensions can also have docker.tar.gz so we need to make sure we don't skip that
|
|
if ext == ".gz" {
|
|
ext = ".tar.gz"
|
|
if filepath.Ext(strings.ReplaceAll(name, ".tar.gz", "")) == ".docker" ||
|
|
filepath.Ext(strings.ReplaceAll(name, ".tar.gz.sha256", "")) == ".docker" {
|
|
ext = ".docker.tar.gz"
|
|
}
|
|
}
|
|
|
|
handler := handlers[ext]
|
|
// If there is no extension, then we are either dealing with public assets
|
|
// or the storybook, which both require some extra handling:
|
|
if ext != "" {
|
|
return handler, ext
|
|
}
|
|
|
|
if filepath.Base(name) == "public" {
|
|
return CDNHandler, ""
|
|
}
|
|
if filepath.Base(name) == "storybook" {
|
|
return StorybookHandler, ""
|
|
}
|
|
if filepath.Base(name) == "npm-packages" {
|
|
return NPMHandler, ""
|
|
}
|
|
panic("no handler found")
|
|
}
|