From be3875ef38412e8f19a944c3c52848f0522a1e1c Mon Sep 17 00:00:00 2001 From: Justin Vreeland Date: Tue, 19 Nov 2024 09:45:04 -0800 Subject: [PATCH] convert/gem: Update convert gem to reflect the state of ruby3.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Update default ruby to 3.3 - Remove keyring entries wolfictl lint rejects them ``` ❯ wolfictl lint ruby3.2-diff-lcs.yaml 2024/11/19 09:51:17 INFO Package: ruby3.2-diff-lcs: [forbidden-repository-used]: forbidden repository https://packages.wolfi.dev/os is used (ERROR) [forbidden-keyring-used]: forbidden keyring https://packages.wolfi.dev/os/wolfi-signing.rsa.pub is used (ERROR) ``` - Remove README it causes build to fial - Remove patch people will notice when it fails and the sed in pipelines/ruby/build should account for it - Truncate dscription becuase it breaks index generation ``` 2024/11/19 10:01:40 ERRO failed to build package: unable to generate index: updating index: failed to parse package packages/aarch64/ruby3.2-diff-lcs-1.5.1-r0.apk: ini.ShadowLoad(): key-value delimiter not found: McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities ``` --- pkg/convert/gem/gem.go | 33 ++++++++++++----------------- pkg/convert/gem/gem_test.go | 41 +++++++++---------------------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/pkg/convert/gem/gem.go b/pkg/convert/gem/gem.go index bc866087b..8afc6680f 100644 --- a/pkg/convert/gem/gem.go +++ b/pkg/convert/gem/gem.go @@ -34,7 +34,7 @@ import ( ) const ( - DefaultRubyVersion = "3.2" + DefaultRubyVersion = "3.3" DefaultBaseURIFormat = "https://rubygems.org/api/v1/gems/%s.json" ) @@ -237,6 +237,7 @@ func (c *GemContext) generateManifest(ctx context.Context, g GemMeta) (manifest. generated.Environment = c.generateEnvironment() generated.Vars = c.generateVars(g) generated.Pipeline = c.generatePipeline(ctx, g) + generated.VarTransforms = c.generateVarTransforms() return generated, nil } @@ -249,7 +250,7 @@ func (c *GemContext) generatePackage(g GemMeta) config.Package { pkg := config.Package{ Epoch: 0, Name: fmt.Sprintf("ruby%s-%s", c.RubyVersion, g.Name), - Description: g.Info, + Description: strings.Split(g.Info, "\n")[0], Version: g.Version, Copyright: []config.Copyright{}, Dependencies: config.Dependencies{ @@ -279,20 +280,12 @@ func (c *GemContext) generateEnvironment() apkotypes.ImageConfiguration { "busybox", "ca-certificates-bundle", "git", - fmt.Sprintf("ruby-%s", c.RubyVersion), - fmt.Sprintf("ruby-%s-dev", c.RubyVersion), + "ruby-${{rubyMM}}", + "ruby-${{rubyMM}}-dev", }, }, } - if len(c.AdditionalRepositories) > 0 { - env.Contents.BuildRepositories = append(env.Contents.BuildRepositories, c.AdditionalRepositories...) - } - - if len(c.AdditionalKeyrings) > 0 { - env.Contents.Keyring = append(env.Contents.Keyring, c.AdditionalKeyrings...) - } - return env } @@ -323,16 +316,10 @@ func (c *GemContext) generatePipeline(ctx context.Context, g GemMeta) []config.P Uses: "fetch", With: map[string]string{ "uri": strings.ReplaceAll(artifactURI, g.Version, "${{package.version}}"), - "README": fmt.Sprintf("CONFIRM WITH: curl -L %s | sha256sum", artifactURI), "expected-sha256": artifactSHA, }, - }, { - Uses: "patch", - With: map[string]string{ - "README": "This is only required if the gemspec is using a signing key", - "patches": "patches/${{package.name}}.patch", - }, - }, { + }, + { Uses: "ruby/build", With: map[string]string{ "gem": "${{vars.gem}}", @@ -385,3 +372,9 @@ func (c *GemContext) generateVars(g GemMeta) map[string]string { "gem": g.Name, } } + +// generateTransforms handles mapping package name to a ruby version +func (c *GemContext) generateVarTransforms() []config.VarTransforms { + return []config.VarTransforms{{From: "${{package.name}}", Match: "^ruby(\\d.\\d+)-.", Replace: "$1", To: "rubyMM"}} + +} diff --git a/pkg/convert/gem/gem_test.go b/pkg/convert/gem/gem_test.go index f3f15a679..cbb7ca0df 100644 --- a/pkg/convert/gem/gem_test.go +++ b/pkg/convert/gem/gem_test.go @@ -143,10 +143,6 @@ func TestGenerateManifest(t *testing.T) { gemctx.RubyVersion = DefaultRubyVersion - // Add additionalReposities and additionalKeyrings - gemctx.AdditionalRepositories = []string{"https://packages.wolfi.dev/os"} - gemctx.AdditionalKeyrings = []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub"} - // Read the gem meta into data, err := os.ReadFile(filepath.Join(gemMetaDir, "async.json")) assert.NoError(t, err) @@ -171,19 +167,17 @@ func TestGenerateManifest(t *testing.T) { assert.Equal(t, "MIT", got.Package.Copyright[0].License) // Check Environment - assert.Equal(t, []string{"https://packages.wolfi.dev/os"}, got.Environment.Contents.BuildRepositories) - assert.Equal(t, []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub"}, got.Environment.Contents.Keyring) assert.Equal(t, []string{ "build-base", "busybox", "ca-certificates-bundle", "git", - fmt.Sprintf("ruby-%s", DefaultRubyVersion), - fmt.Sprintf("ruby-%s-dev", DefaultRubyVersion), + "ruby-${{rubyMM}}", + "ruby-${{rubyMM}}-dev", }, got.Environment.Contents.Packages) // Check Pipeline - assert.Equal(t, 5, len(got.Pipeline)) + assert.Equal(t, 4, len(got.Pipeline)) // Check Pipeline - fetch assert.Equal(t, "fetch", got.Pipeline[0].Uses) @@ -191,33 +185,25 @@ func TestGenerateManifest(t *testing.T) { // directory, which is just a tarball of the async.json, not the // actual artifact. It's simply used for testing. assert.Equal(t, map[string]string{ - "README": fmt.Sprintf("CONFIRM WITH: curl -L %s/archive/refs/tags/v2.3.1.tar.gz | sha256sum", server.URL), "expected-sha256": "2481a44fc272b64a4a1775edf57c52b5367c8a07afd7996901d3c57c77542e6c", "uri": fmt.Sprintf("%s/archive/refs/tags/v${{package.version}}.tar.gz", server.URL), }, got.Pipeline[0].With) - // Check Pipeline - patch - assert.Equal(t, "patch", got.Pipeline[1].Uses) - assert.Equal(t, map[string]string{ - "README": "This is only required if the gemspec is using a signing key", - "patches": "patches/${{package.name}}.patch", - }, got.Pipeline[1].With) - // Check Pipeline - ruby/build - assert.Equal(t, "ruby/build", got.Pipeline[2].Uses) + assert.Equal(t, "ruby/build", got.Pipeline[1].Uses) assert.Equal(t, map[string]string{ "gem": "${{vars.gem}}", - }, got.Pipeline[2].With) + }, got.Pipeline[1].With) // Check Pipeline - ruby/install - assert.Equal(t, "ruby/install", got.Pipeline[3].Uses) + assert.Equal(t, "ruby/install", got.Pipeline[2].Uses) assert.Equal(t, map[string]string{ "gem": "${{vars.gem}}", "version": "${{package.version}}", - }, got.Pipeline[3].With) + }, got.Pipeline[2].With) // Check Pipeline - ruby/clean - assert.Equal(t, "ruby/clean", got.Pipeline[4].Uses) + assert.Equal(t, "ruby/clean", got.Pipeline[3].Uses) } // TestGeneratePackage tests when a gem has multiple licenses @@ -252,29 +238,22 @@ func TestGeneratePackage(t *testing.T) { assert.Equal(t, expected, got) } -// TestGenerateEnvironment tests when there are additional keyring and -// repository entries func TestGenerateEnvironment(t *testing.T) { expected := apkotypes.ImageConfiguration{ Contents: apkotypes.ImageContents{ - BuildRepositories: []string{"https://packages.wolfi.dev/os", "local /github/workspace/packages"}, - Keyring: []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub", "melange.rsa.pub"}, Packages: []string{ "build-base", "busybox", "ca-certificates-bundle", "git", - fmt.Sprintf("ruby-%s", DefaultRubyVersion), - fmt.Sprintf("ruby-%s-dev", DefaultRubyVersion), + fmt.Sprintf("ruby-${{rubyMM}}"), + fmt.Sprintf("ruby-${{rubyMM}}-dev"), }, }, } gemctx := testGemContext("unused") - // Add additionalReposities and additionalKeyrings - gemctx.AdditionalRepositories = []string{"https://packages.wolfi.dev/os", "local /github/workspace/packages"} - gemctx.AdditionalKeyrings = []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub", "melange.rsa.pub"} gemctx.RubyVersion = DefaultRubyVersion got := gemctx.generateEnvironment()