Skip to content

Commit

Permalink
Fixes: Only upload 1 rpi deb package (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
kminehart authored Aug 29, 2023
1 parent 4f5059e commit 1fd0b44
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 35 deletions.
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 @@ -58,21 +58,21 @@ dagger run go run ./cmd npm \
--gcp-service-account-key-base64=${GCP_KEY_BASE64} > 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 @@ -82,20 +82,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 @@ -104,7 +104,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 @@ -40,19 +40,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

0 comments on commit 1fd0b44

Please sign in to comment.