Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: grafana-rpi and grafana armv7 deb packages #143

Merged
merged 7 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ var FlagPackage = &cli.StringSliceFlag{
Name: "package",
Usage: "Path to a grafana.tar.gz package used as input. This command will process each package provided separately and produce an equal number of applicable outputs",
}
var FlagNameOverride = &cli.StringFlag{
Name: "name",
Usage: "Overrides any calculation for name in the package with the value provided here",
}

// PackageInputFlags are used for commands that require a grafana package as input.
// These commands are exclusively used outside of the CI process and are typically used in the CD process where a grafana.tar.gz has already been created.
var PackageInputFlags = []cli.Flag{
FlagPackage,
FlagNameOverride,
}

// GCPFlags are used in commands that need to authenticate with Google Cloud platform using the Google Cloud SDK
Expand Down
4 changes: 4 additions & 0 deletions containers/package_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ import (
)

type PackageInputOpts struct {
// Name is used when overriding the artifact that is being produced. This is used in very specific scenarios where
// the source package's name does not match the package's metadata name.
Name string
Packages []string
}

func PackageInputOptsFromFlags(c cliutil.CLIContext) *PackageInputOpts {
return &PackageInputOpts{
Name: c.String("name"),
Packages: c.StringSlice("package"),
}
}
Expand Down
3 changes: 2 additions & 1 deletion pipelines/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
// It accepts publish args, so you can place the file in a local or remote destination.
func Deb(ctx context.Context, d *dagger.Client, args PipelineArgs) error {
installers, err := PackageInstaller(ctx, d, args, InstallerOpts{
PackageType: "deb",
NameOverride: args.PackageInputOpts.Name,
PackageType: "deb",
ConfigFiles: [][]string{
{"/src/packaging/deb/default/grafana-server", "/pkg/etc/default/grafana-server"},
{"/src/packaging/deb/init.d/grafana-server", "/pkg/etc/init.d/grafana-server"},
Expand Down
17 changes: 12 additions & 5 deletions pipelines/package_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

type InstallerOpts struct {
NameOverride string
PackageType string
ConfigFiles [][]string
AfterInstall string
Expand Down Expand Up @@ -106,17 +107,23 @@ func PackageInstaller(ctx context.Context, d *dagger.Client, args PipelineArgs,
fpmArgs = append(fpmArgs, fmt.Sprintf("--architecture=%s", arch))
}

packageName := "grafana"
// Honestly we don't care about making fpm installers for non-enterprise or non-grafana flavors of grafana
if tarOpts.Edition == "enterprise" {
fpmArgs = append(fpmArgs, fmt.Sprintf("--name=grafana-%s", tarOpts.Edition))
packageName = fmt.Sprintf("grafana-%s", tarOpts.Edition)
fpmArgs = append(fpmArgs, "--description=\"Grafana Enterprise\"")
fpmArgs = append(fpmArgs, "--conflicts=grafana")
} else {
fpmArgs = append(fpmArgs, "--name=grafana")
fpmArgs = append(fpmArgs, "--description=Grafana")
fpmArgs = append(fpmArgs, "--license=AGPLv3")
}

if n := opts.NameOverride; n != "" {
packageName = n
}

fpmArgs = append(fpmArgs, fmt.Sprintf("--name=%s", packageName))

// The last fpm arg which is required to say, "use the PWD to build the package".
fpmArgs = append(fpmArgs, ".")

Expand All @@ -141,7 +148,8 @@ func PackageInstaller(ctx context.Context, d *dagger.Client, args PipelineArgs,
container := opts.Container.
WithFile("/src/grafana.tar.gz", packages[i]).
WithEnvVariable("XZ_DEFAULTS", "-T0").
WithExec([]string{"tar", "--strip-components=1", "-xvf", "/src/grafana.tar.gz", "-C", "/src"})
WithExec([]string{"tar", "--exclude=storybook", "--strip-components=1", "-xvf", "/src/grafana.tar.gz", "-C", "/src"}).
WithExec([]string{"rm", "/src/grafana.tar.gz"})

container = container.
WithExec(append([]string{"mkdir", "-p"}, packagePaths...)).
Expand All @@ -154,8 +162,7 @@ func PackageInstaller(ctx context.Context, d *dagger.Client, args PipelineArgs,
}

container = container.WithExec(fpmArgs)

dst := strings.Join([]string{args.PublishOpts.Destination, name}, "/")
dst := strings.Join([]string{args.PublishOpts.Destination, strings.ReplaceAll(name, tarOpts.Name, packageName)}, "/")
installers[dst] = container.File("/src/" + name)
}

Expand Down
5 changes: 4 additions & 1 deletion pipelines/package_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

type TarFileOpts struct {
// Name is the name of the product in the package. 99% of the time, this will be "grafana" or "grafana-enterprise".
Name string
Version string
BuildID string
// Edition is the flavor text after "grafana-", like "enterprise".
Expand Down Expand Up @@ -82,11 +84,12 @@ func TarOptsFromFileName(filename string) TarFileOpts {
edition := ""
suffix := ""
if n := strings.Split(name, "-"); len(n) != 1 {
edition = n[1]
edition = strings.Join(n[1:], "-")
suffix = fmt.Sprintf("-%s", n[1])
}

return TarFileOpts{
Name: name,
Edition: edition,
Version: version,
BuildID: buildID,
Expand Down
37 changes: 37 additions & 0 deletions pipelines/package_names_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func TestTarFilename(t *testing.T) {
t.Errorf("name '%s' does not match expected name '%s'", name, expected)
}
})
t.Run("It should support editions with multiple hyphens", func(t *testing.T) {
distro := executil.Distribution("plan9/arm/v6")
opts := pipelines.TarFileOpts{
Edition: "enterprise-rpi",
Version: "v1.0.1-test",
BuildID: "333",
Distro: distro,
}

expected := "grafana-enterprise-rpi_v1.0.1-test_333_plan9_arm-6.tar.gz"
if name := pipelines.TarFilename(opts); name != expected {
t.Errorf("name '%s' does not match expected name '%s'", name, expected)
}
})
}

func TestOptsFromFile(t *testing.T) {
Expand Down Expand Up @@ -135,4 +149,27 @@ func TestOptsFromFile(t *testing.T) {
t.Errorf("got.Distro != expect.Distro, expected '%s', got '%s'", expect.Distro, got.Distro)
}
})
t.Run("It should support editions with multiple hyphens", func(t *testing.T) {
name := "somewhere/grafana-enterprise-rpi_v1.0.1-test_333_plan9_arm-6.tar.gz"
distro := executil.Distribution("plan9/arm/v6")
expect := pipelines.TarFileOpts{
Edition: "enterprise-rpi",
Version: "v1.0.1-test",
BuildID: "333",
Distro: distro,
}
got := pipelines.TarOptsFromFileName(name)
if got.Edition != expect.Edition {
t.Errorf("got.Edition != expect.Edition, expected '%s', got '%s'", expect.Edition, got.Edition)
}
if got.Version != expect.Version {
t.Errorf("got.Version != expect.Version, expected '%s', got '%s'", expect.Version, got.Version)
}
if got.BuildID != expect.BuildID {
t.Errorf("got.BuildID != expect.BuildID, expected '%s', got '%s'", expect.BuildID, got.BuildID)
}
if got.Distro != expect.Distro {
t.Errorf("got.Distro != expect.Distro, expected '%s', got '%s'", expect.Distro, got.Distro)
}
})
}
22 changes: 11 additions & 11 deletions scripts/drone_publish_tag_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
docker run --privileged --rm tonistiigi/binfmt --install all

# Build all of the grafana.tar.gz packages.
dagger run go run ./cmd \
dagger run --silent go run ./cmd \
package \
--yarn-cache=${YARN_CACHE_FOLDER} \
--distro=linux/amd64 \
Expand All @@ -27,7 +27,7 @@ dagger run go run ./cmd \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > grafana.txt &

# Build the grafana-pro tar.gz package.
dagger run go run ./cmd \
dagger run --silent go run ./cmd \
package \
--yarn-cache=${YARN_CACHE_FOLDER} \
--distro=linux/amd64 \
Expand Down Expand Up @@ -55,21 +55,21 @@ cat pro.txt grafana.txt > assets.txt
go run ./scripts/copy_npm $(cat assets.txt | grep tar.gz | grep linux | grep amd64 | grep -v enterprise | grep -v pro | grep -v sha256 -m 1) > npm.txt

# Copy only the linux/amd64 edition storybook into a separate folder
dagger run go run ./cmd storybook \
dagger run --silent go run ./cmd storybook \
$(cat assets.txt | grep tar.gz | grep linux | grep amd64 | grep -v enterprise | grep -v pro | grep -v sha256 | awk '{print "--package=" $0}') \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > storybook.txt &

# Use the non-pro, non-windows, non-darwin packages and create deb packages from them.
dagger run go run ./cmd deb \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | awk '{print "--package=" $0}') \
dagger run --silent go run ./cmd deb \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep -v arm-6 | awk '{print "--package=" $0}') \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > debs.txt &

# Make rpm installers for all the same Linux distros, and sign them because RPM packages are signed.
dagger run go run ./cmd rpm \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | awk '{print "--package=" $0}') \
dagger run --silent go run ./cmd rpm \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep -v arm-6 | awk '{print "--package=" $0}') \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} \
Expand All @@ -79,20 +79,20 @@ dagger run go run ./cmd rpm \
--gpg-passphrase="${$GPG_PASSPHRASE}" > rpms.txt &

# For Windows we distribute zips and exes
dagger run go run ./cmd zip \
dagger run --silent go run ./cmd zip \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep windows | awk '{print "--package=" $0}') \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} \
--checksum > zips.txt &

dagger run go run ./cmd windows-installer \
dagger run --silent go run ./cmd windows-installer \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep windows | awk '{print "--package=" $0}') \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} \
--checksum > exes.txt &

# Build a docker image for all Linux distros except armv6
dagger run go run ./cmd docker \
dagger run --silent go run ./cmd docker \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep -v arm-6 | awk '{print "--package=" $0}') \
--checksum \
--ubuntu-base="ubuntu:22.10" \
Expand All @@ -101,7 +101,7 @@ dagger run go run ./cmd docker \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > docker.txt &

# Copy only the linux/amd64 edition frontends into a separate folder
dagger run go run ./cmd cdn \
dagger run --silent go run ./cmd cdn \
$(cat assets.txt | grep tar.gz | grep pro | grep linux | grep amd64 | grep -v docker | grep -v sha256 | awk '{print "--package=" $0}') \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > cdn.txt &
Expand Down
16 changes: 11 additions & 5 deletions scripts/drone_publish_tag_enterprise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ dagger run --silent go run ./cmd \

echo "Done building tar.gz packages..."

# Use the non-windows, non-darwin packages and create deb packages from them.
# Use the non-windows, non-darwin, non-rpi packages and create deb packages from them.
dagger run --silent go run ./cmd deb \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | awk '{print "--package=" $0}') \
--parallel=16 \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep -v arm-7 | grep -v arm-6 | awk '{print "--package=" $0}') \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > debs.txt

# Use the armv7 package to build the `rpi` specific version.
dagger run --silent go run ./cmd deb \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep arm-7 | awk '{print "--package=" $0}') \
--name=grafana-enterprise-rpi \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} >> debs.txt

# Make rpm installers for all the same Linux distros, and sign them because RPM packages are signed.
dagger run --silent go run ./cmd rpm \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | awk '{print "--package=" $0}') \
--parallel=16 \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep -v arm-6 | awk '{print "--package=" $0}') \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} \
Expand Down
16 changes: 11 additions & 5 deletions scripts/drone_publish_tag_grafana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@ dagger run --silent go run ./cmd storybook \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > storybook.txt

# Use the non-windows, non-darwin packages and create deb packages from them.
# Use the non-windows, non-darwin, non-rpi packages and create deb packages from them.
dagger run --silent go run ./cmd deb \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | awk '{print "--package=" $0}') \
--parallel=16 \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep -v arm-7 | grep -v arm-6 | awk '{print "--package=" $0}') \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > debs.txt

# Use the armv7 package to build the `rpi` specific version.
dagger run --silent go run ./cmd deb \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep arm-7 | awk '{print "--package=" $0}') \
--name=grafana-rpi \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} >> debs.txt

# Make rpm installers for all the same Linux distros, and sign them because RPM packages are signed.
dagger run --silent go run ./cmd rpm \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | awk '{print "--package=" $0}') \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | grep -v windows | grep -v darwin | grep -v arm-6 | awk '{print "--package=" $0}') \
--checksum \
--parallel=16 \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} \
--sign=true \
Expand Down
8 changes: 4 additions & 4 deletions scripts/drone_publish_tag_pro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
docker run --privileged --rm tonistiigi/binfmt --install all

# Build all of the grafana.tar.gz packages.
dagger run go run ./cmd \
dagger run --silent go run ./cmd \
package \
--yarn-cache=${YARN_CACHE_FOLDER} \
--distro=linux/amd64 \
Expand All @@ -30,14 +30,14 @@ dagger run go run ./cmd \
echo "Done building tar.gz packages..."

# Use the .tar.gz packages and create deb packages from them.
dagger run go run ./cmd deb \
dagger run --silent go run ./cmd deb \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | awk '{print "--package=" $0}') \
--checksum \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > debs.txt &

# Build a docker image for all .tar.gz packages
dagger run go run ./cmd docker \
dagger run --silent go run ./cmd docker \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | awk '{print "--package=" $0}') \
--checksum \
--ubuntu-base="ubuntu:22.10" \
Expand All @@ -46,7 +46,7 @@ dagger run go run ./cmd docker \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > docker.txt &

# Copy only the linux/amd64 edition frontends into a separate folder
dagger run go run ./cmd cdn \
dagger run --silent go run ./cmd cdn \
$(cat assets.txt | grep tar.gz | grep -v docker | grep -v sha256 | awk '{print "--package=" $0}') \
--destination=${local_dst} \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > cdn.txt &
Expand Down
10 changes: 9 additions & 1 deletion scripts/move_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ func DebHandler(name string) []string {
// 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}
Expand All @@ -195,7 +203,7 @@ func DebHandler(name string) []string {
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, fullName + "-rpi"}
names = []string{fullName}
}

dst := []string{}
Expand Down
Loading
Loading