diff --git a/fixtures/default/relative_gemspec_path/Gemfile.lock b/fixtures/default/relative_gemspec_path/Gemfile.lock index b1b5dc242..a21484c85 100644 --- a/fixtures/default/relative_gemspec_path/Gemfile.lock +++ b/fixtures/default/relative_gemspec_path/Gemfile.lock @@ -27,3 +27,9 @@ DEPENDENCIES hola! sinatra webrick + +RUBY VERSION + ruby 3.2.0p0 + +BUNDLED WITH + 2.4.1 diff --git a/fixtures/default/sinatra_jruby/Gemfile.lock b/fixtures/default/sinatra_jruby/Gemfile.lock index 050435b45..b58c4f97a 100644 --- a/fixtures/default/sinatra_jruby/Gemfile.lock +++ b/fixtures/default/sinatra_jruby/Gemfile.lock @@ -23,7 +23,7 @@ DEPENDENCIES webrick RUBY VERSION - ruby 3.1.4p0 (jruby 9.4.3.0) + ruby 3.1.4p0 (jruby 9.4.8.0) BUNDLED WITH - 2.4.14 + 2.6.5 diff --git a/fixtures/default/specified_ruby_version/Gemfile b/fixtures/default/specified_ruby_version/Gemfile index edab86451..12ddaea63 100644 --- a/fixtures/default/specified_ruby_version/Gemfile +++ b/fixtures/default/specified_ruby_version/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby "~>3.1.0" +ruby "~>3.2.0" gem "webrick" gem 'sinatra' diff --git a/fixtures/default/specified_ruby_version/Gemfile.lock b/fixtures/default/specified_ruby_version/Gemfile.lock index 75dc105ca..e01dd3ed1 100644 --- a/fixtures/default/specified_ruby_version/Gemfile.lock +++ b/fixtures/default/specified_ruby_version/Gemfile.lock @@ -1,15 +1,19 @@ GEM remote: https://rubygems.org/ specs: - rack (1.5.2) - rack-protection (1.5.2) - rack - sinatra (1.4.4) - rack (~> 1.4) - rack-protection (~> 1.4) - tilt (~> 1.3, >= 1.3.4) - tilt (1.4.1) - webrick (1.7.0) + mustermann (3.0.0) + ruby2_keywords (~> 0.0.1) + rack (2.2.8) + rack-protection (3.1.0) + rack (~> 2.2, >= 2.2.4) + ruby2_keywords (0.0.5) + sinatra (3.1.0) + mustermann (~> 3.0) + rack (~> 2.2, >= 2.2.4) + rack-protection (= 3.1.0) + tilt (~> 2.0) + tilt (2.3.0) + webrick (1.8.1) PLATFORMS ruby @@ -17,3 +21,9 @@ PLATFORMS DEPENDENCIES sinatra webrick + +RUBY VERSION + ruby 3.2.0p0 + +BUNDLED WITH + 2.4.1 diff --git a/go.mod b/go.mod index 7b2873195..d69f0f203 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,13 @@ module github.com/cloudfoundry/ruby-buildpack -go 1.22.5 +go 1.23.0 + +toolchain go1.24.0 require ( github.com/blang/semver v3.5.1+incompatible github.com/cloudfoundry/libbuildpack v0.0.0-20240717165421-f2ae8069fcba - github.com/cloudfoundry/switchblade v0.6.0 + github.com/cloudfoundry/switchblade v0.9.0 github.com/golang/mock v1.6.0 github.com/kr/text v0.2.0 github.com/onsi/ginkgo v1.16.5 diff --git a/go.sum b/go.sum index 76ea39c55..b115f64ce 100644 --- a/go.sum +++ b/go.sum @@ -807,6 +807,8 @@ github.com/cloudfoundry/libbuildpack v0.0.0-20240717165421-f2ae8069fcba h1:RdbOe github.com/cloudfoundry/libbuildpack v0.0.0-20240717165421-f2ae8069fcba/go.mod h1:kn4FHMwI8bTd9gT92wPGjXHzUvGcj8CkPxG8q3AGBAQ= github.com/cloudfoundry/switchblade v0.6.0 h1:Opid6YAp7a9+lzdvwlYIUUGnxV87QfCpizV+FYMt1MQ= github.com/cloudfoundry/switchblade v0.6.0/go.mod h1:3nNqkW8dEecI9bxj8p1cHz3XG6AgPfp7jcmGHZYleos= +github.com/cloudfoundry/switchblade v0.9.0 h1:4yxlAb526G4XIDEoH9Vp+erCCYcXTD3aYaz5THKhskY= +github.com/cloudfoundry/switchblade v0.9.0/go.mod h1:lbxYZXU/aSVmEafP0NZgQaxrf9nBfdT8t2EIiwrP4bU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= diff --git a/src/ruby/integration/default_test.go b/src/ruby/integration/default_test.go index b4e81fc3e..5f4078c70 100644 --- a/src/ruby/integration/default_test.go +++ b/src/ruby/integration/default_test.go @@ -37,7 +37,7 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T Execute(name, filepath.Join(fixtures, "default", "specified_ruby_version")) Expect(err).NotTo(HaveOccurred()) - Eventually(deployment).Should(Serve(ContainSubstring("ruby 3.1.6")).WithEndpoint("/ruby")) + Eventually(deployment).Should(Serve(MatchRegexp(`ruby 3\.2\.\d+`)).WithEndpoint("/ruby")) }) }) diff --git a/src/ruby/integration/init_test.go b/src/ruby/integration/init_test.go index af9022e57..e3ca10d80 100644 --- a/src/ruby/integration/init_test.go +++ b/src/ruby/integration/init_test.go @@ -44,7 +44,7 @@ func TestIntegration(t *testing.T) { var Expect = NewWithT(t).Expect format.MaxLength = 0 - SetDefaultEventuallyTimeout(10 * time.Second) + SetDefaultEventuallyTimeout(20 * time.Second) root, err := filepath.Abs("./../../..") Expect(err).NotTo(HaveOccurred()) @@ -98,6 +98,7 @@ func TestIntegration(t *testing.T) { Expect(platform.Delete.Execute(proxyName)).To(Succeed()) Expect(os.Remove(os.Getenv("BUILDPACK_FILE"))).To(Succeed()) Expect(os.Remove(goBuildpackFile)).To(Succeed()) + Expect(platform.Deinitialize()).To(Succeed()) } func downloadBuildpack(name string) (string, error) { diff --git a/vendor/github.com/cloudfoundry/switchblade/cloudfoundry.go b/vendor/github.com/cloudfoundry/switchblade/cloudfoundry.go index 100548f9f..91b22a77d 100644 --- a/vendor/github.com/cloudfoundry/switchblade/cloudfoundry.go +++ b/vendor/github.com/cloudfoundry/switchblade/cloudfoundry.go @@ -9,15 +9,17 @@ import ( ) //go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface InitializePhase --name CloudFoundryInitializePhase --output fakes/cloudfoundry_initialize_phase.go +//go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface DeinitializePhase --name CloudFoundryDeinitializePhase --output fakes/cloudfoundry_deinitialize_phase.go //go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface SetupPhase --name CloudFoundrySetupPhase --output fakes/cloudfoundry_setup_phase.go //go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface StagePhase --name CloudFoundryStagePhase --output fakes/cloudfoundry_stage_phase.go //go:generate faux --package github.com/cloudfoundry/switchblade/internal/cloudfoundry --interface TeardownPhase --name CloudFoundryTeardownPhase --output fakes/cloudfoundry_teardown_phase.go -func NewCloudFoundry(initialize cloudfoundry.InitializePhase, setup cloudfoundry.SetupPhase, stage cloudfoundry.StagePhase, teardown cloudfoundry.TeardownPhase, workspace string) Platform { +func NewCloudFoundry(initialize cloudfoundry.InitializePhase, deinitialize cloudfoundry.DeinitializePhase, setup cloudfoundry.SetupPhase, stage cloudfoundry.StagePhase, teardown cloudfoundry.TeardownPhase, workspace string) Platform { return Platform{ - initialize: cloudFoundryInitializeProcess{initialize: initialize}, - Deploy: cloudFoundryDeployProcess{setup: setup, stage: stage, workspace: workspace}, - Delete: cloudFoundryDeleteProcess{teardown: teardown, workspace: workspace}, + initialize: cloudFoundryInitializeProcess{initialize: initialize}, + deinitialize: cloudFoundryDeinitializeProcess{deinitialize: deinitialize}, + Deploy: cloudFoundryDeployProcess{setup: setup, stage: stage, workspace: workspace}, + Delete: cloudFoundryDeleteProcess{teardown: teardown, workspace: workspace}, } } @@ -37,6 +39,14 @@ func (p cloudFoundryInitializeProcess) Execute(buildpacks ...Buildpack) error { return p.initialize.Run(bps) } +type cloudFoundryDeinitializeProcess struct { + deinitialize cloudfoundry.DeinitializePhase +} + +func (p cloudFoundryDeinitializeProcess) Execute() error { + return p.deinitialize.Run() +} + type cloudFoundryDeployProcess struct { setup cloudfoundry.SetupPhase stage cloudfoundry.StagePhase diff --git a/vendor/github.com/cloudfoundry/switchblade/docker.go b/vendor/github.com/cloudfoundry/switchblade/docker.go index de528fd20..e940b6faf 100644 --- a/vendor/github.com/cloudfoundry/switchblade/docker.go +++ b/vendor/github.com/cloudfoundry/switchblade/docker.go @@ -9,16 +9,18 @@ import ( ) //go:generate faux --package github.com/cloudfoundry/switchblade/internal/docker --interface InitializePhase --name DockerInitializePhase --output fakes/docker_initialize_phase.go +//go:generate faux --package github.com/cloudfoundry/switchblade/internal/docker --interface DeinitializePhase --name DockerDeinitializePhase --output fakes/docker_deinitialize_phase.go //go:generate faux --package github.com/cloudfoundry/switchblade/internal/docker --interface SetupPhase --name DockerSetupPhase --output fakes/docker_setup_phase.go //go:generate faux --package github.com/cloudfoundry/switchblade/internal/docker --interface StagePhase --name DockerStagePhase --output fakes/docker_stage_phase.go //go:generate faux --package github.com/cloudfoundry/switchblade/internal/docker --interface StartPhase --name DockerStartPhase --output fakes/docker_start_phase.go //go:generate faux --package github.com/cloudfoundry/switchblade/internal/docker --interface TeardownPhase --name DockerTeardownPhase --output fakes/docker_teardown_phase.go -func NewDocker(initialize docker.InitializePhase, setup docker.SetupPhase, stage docker.StagePhase, start docker.StartPhase, teardown docker.TeardownPhase) Platform { +func NewDocker(initialize docker.InitializePhase, deinitialize docker.DeinitializePhase, setup docker.SetupPhase, stage docker.StagePhase, start docker.StartPhase, teardown docker.TeardownPhase) Platform { return Platform{ - initialize: dockerInitializeProcess{initialize: initialize}, - Deploy: dockerDeployProcess{setup: setup, stage: stage, start: start}, - Delete: dockerDeleteProcess{teardown: teardown}, + initialize: dockerInitializeProcess{initialize: initialize}, + deinitialize: dockerDeinitializeProcess{deinitialize: deinitialize}, + Deploy: dockerDeployProcess{setup: setup, stage: stage, start: start}, + Delete: dockerDeleteProcess{teardown: teardown}, } } @@ -35,9 +37,15 @@ func (p dockerInitializeProcess) Execute(buildpacks ...Buildpack) error { }) } - p.initialize.Run(bps) + return p.initialize.Run(bps) +} - return nil +type dockerDeinitializeProcess struct { + deinitialize docker.DeinitializePhase +} + +func (p dockerDeinitializeProcess) Execute() error { + return p.deinitialize.Run() } type dockerDeployProcess struct { diff --git a/vendor/github.com/cloudfoundry/switchblade/internal/cloudfoundry/deinitialize.go b/vendor/github.com/cloudfoundry/switchblade/internal/cloudfoundry/deinitialize.go new file mode 100644 index 000000000..061ac2421 --- /dev/null +++ b/vendor/github.com/cloudfoundry/switchblade/internal/cloudfoundry/deinitialize.go @@ -0,0 +1,17 @@ +package cloudfoundry + +// This is noop functionality for the time being to reflect the docker structure + +type DeinitializePhase interface { + Run() error +} + +type Deinitialize struct{} + +func NewDeinitialize() Deinitialize { + return Deinitialize{} +} + +func (d Deinitialize) Run() error { + return nil +} diff --git a/vendor/github.com/cloudfoundry/switchblade/internal/docker/deinitialize.go b/vendor/github.com/cloudfoundry/switchblade/internal/docker/deinitialize.go new file mode 100644 index 000000000..8bd447812 --- /dev/null +++ b/vendor/github.com/cloudfoundry/switchblade/internal/docker/deinitialize.go @@ -0,0 +1,36 @@ +package docker + +import ( + "context" + "fmt" +) + +//go:generate faux --interface DeinitializeNetworkManager --output fakes/deinitialize_network_manager.go +type DeinitializeNetworkManager interface { + Delete(ctx context.Context, name string) error +} + +type DeinitializePhase interface { + Run() error +} + +type Deinitialize struct { + network DeinitializeNetworkManager +} + +func NewDeinitialize(network DeinitializeNetworkManager) Deinitialize { + return Deinitialize{ + network: network, + } +} + +func (d Deinitialize) Run() error { + ctx := context.Background() + + err := d.network.Delete(ctx, InternalNetworkName) + if err != nil { + return fmt.Errorf("failed to delete network: %w", err) + } + + return nil +} diff --git a/vendor/github.com/cloudfoundry/switchblade/internal/docker/initialize.go b/vendor/github.com/cloudfoundry/switchblade/internal/docker/initialize.go index b3040f5bb..5422c71e5 100644 --- a/vendor/github.com/cloudfoundry/switchblade/internal/docker/initialize.go +++ b/vendor/github.com/cloudfoundry/switchblade/internal/docker/initialize.go @@ -1,19 +1,44 @@ package docker +import ( + "context" + "fmt" +) + +const ( + InternalNetworkName = "switchblade-internal" +) + +//go:generate faux --interface InitializeNetworkManager --output fakes/initialize_network_manager.go +type InitializeNetworkManager interface { + Create(ctx context.Context, name, driver string, internal bool) error +} + type InitializePhase interface { - Run([]Buildpack) + Run([]Buildpack) error } type Initialize struct { registry BPRegistry + network InitializeNetworkManager } -func NewInitialize(registry BPRegistry) Initialize { +func NewInitialize(registry BPRegistry, network InitializeNetworkManager) Initialize { return Initialize{ registry: registry, + network: network, } } -func (i Initialize) Run(buildpacks []Buildpack) { +func (i Initialize) Run(buildpacks []Buildpack) error { i.registry.Override(buildpacks...) + + ctx := context.Background() + + err := i.network.Create(ctx, InternalNetworkName, "bridge", true) + if err != nil { + return fmt.Errorf("failed to create network: %w", err) + } + + return nil } diff --git a/vendor/github.com/cloudfoundry/switchblade/internal/docker/setup.go b/vendor/github.com/cloudfoundry/switchblade/internal/docker/setup.go index ca83fa582..a9735f95b 100644 --- a/vendor/github.com/cloudfoundry/switchblade/internal/docker/setup.go +++ b/vendor/github.com/cloudfoundry/switchblade/internal/docker/setup.go @@ -19,7 +19,6 @@ import ( const ( BuildpackAppLifecycleRepoURL = "https://github.com/cloudfoundry/buildpackapplifecycle/archive/refs/heads/main.zip" - InternalNetworkName = "switchblade-internal" BridgeNetworkName = "bridge" ) @@ -118,11 +117,6 @@ func (s Setup) Run(ctx context.Context, logs io.Writer, name, path string) (stri return "", fmt.Errorf("failed to copy image pull logs: %w", err) } - err = s.networks.Create(ctx, InternalNetworkName, "bridge", true) - if err != nil { - return "", fmt.Errorf("failed to create network: %w", err) - } - env := []string{fmt.Sprintf("CF_STACK=%s", s.stack)} for key, value := range s.env { env = append(env, fmt.Sprintf("%s=%s", key, value)) diff --git a/vendor/github.com/cloudfoundry/switchblade/internal/docker/start.go b/vendor/github.com/cloudfoundry/switchblade/internal/docker/start.go index d438f4332..314512855 100644 --- a/vendor/github.com/cloudfoundry/switchblade/internal/docker/start.go +++ b/vendor/github.com/cloudfoundry/switchblade/internal/docker/start.go @@ -4,15 +4,18 @@ import ( "context" "encoding/json" "fmt" + "io" + "net/url" + "os" + "path/filepath" + "sort" + "strings" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" "github.com/docker/go-connections/nat" specs "github.com/opencontainers/image-spec/specs-go/v1" - "io" - "os" - "path/filepath" - "sort" ) type StartPhase interface { @@ -169,7 +172,7 @@ func (s Start) Run(ctx context.Context, logs io.Writer, name, command string) (s if ok { for _, binding := range bindings { if binding.HostIP == "0.0.0.0" { - externalURL = fmt.Sprintf("http://%s:%s", binding.HostIP, binding.HostPort) + externalURL = fmt.Sprintf("http://%s:%s", host(), binding.HostPort) } } } @@ -183,6 +186,20 @@ func (s Start) Run(ctx context.Context, logs io.Writer, name, command string) (s return externalURL, internalURL, nil } +func host() string { + val, ok := os.LookupEnv("DOCKER_HOST") + if !ok || strings.HasPrefix(val, "unix://") { + return "localhost" + } + + url, err := url.Parse(val) + if err != nil { + return "localhost" + } + + return url.Hostname() +} + func (s Start) WithStack(stack string) StartPhase { s.stack = stack return s diff --git a/vendor/github.com/cloudfoundry/switchblade/internal/docker/teardown.go b/vendor/github.com/cloudfoundry/switchblade/internal/docker/teardown.go index c0cd6db60..c2f5a580c 100644 --- a/vendor/github.com/cloudfoundry/switchblade/internal/docker/teardown.go +++ b/vendor/github.com/cloudfoundry/switchblade/internal/docker/teardown.go @@ -20,21 +20,14 @@ type TeardownClient interface { ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error } -//go:generate faux --interface TeardownNetworkManager --output fakes/teardown_network_manager.go -type TeardownNetworkManager interface { - Delete(ctx context.Context, name string) error -} - type Teardown struct { client TeardownClient - networks TeardownNetworkManager workspace string } -func NewTeardown(client TeardownClient, networks TeardownNetworkManager, workspace string) Teardown { +func NewTeardown(client TeardownClient, workspace string) Teardown { return Teardown{ client: client, - networks: networks, workspace: workspace, } } @@ -45,11 +38,6 @@ func (t Teardown) Run(ctx context.Context, name string) error { return fmt.Errorf("failed to remove container: %w", err) } - err = t.networks.Delete(ctx, InternalNetworkName) - if err != nil { - return fmt.Errorf("failed to delete network: %w", err) - } - err = os.Remove(filepath.Join(t.workspace, "droplets", fmt.Sprintf("%s.tar.gz", name))) if err != nil && !errors.Is(err, os.ErrNotExist) { return fmt.Errorf("failed to delete droplet tarball: %w", err) diff --git a/vendor/github.com/cloudfoundry/switchblade/platform.go b/vendor/github.com/cloudfoundry/switchblade/platform.go index c452502c8..a23df2a95 100644 --- a/vendor/github.com/cloudfoundry/switchblade/platform.go +++ b/vendor/github.com/cloudfoundry/switchblade/platform.go @@ -19,7 +19,8 @@ type Buildpack struct { type Service map[string]interface{} type Platform struct { - initialize initializeProcess + initialize initializeProcess + deinitialize deinitializeProcess Deploy DeployProcess Delete DeleteProcess @@ -44,6 +45,10 @@ type initializeProcess interface { Execute(buildpacks ...Buildpack) error } +type deinitializeProcess interface { + Execute() error +} + const ( CloudFoundry = "cf" Docker = "docker" @@ -60,11 +65,12 @@ func NewPlatform(platformType, token, stack string) (Platform, error) { cli := pexec.NewExecutable("cf") initialize := cloudfoundry.NewInitialize(cli, stack) + deinitialize := cloudfoundry.NewDeinitialize() setup := cloudfoundry.NewSetup(cli, filepath.Join(home, ".cf"), stack) stage := cloudfoundry.NewStage(cli) teardown := cloudfoundry.NewTeardown(cli) - return NewCloudFoundry(initialize, setup, stage, teardown, os.TempDir()), nil + return NewCloudFoundry(initialize, deinitialize, setup, stage, teardown, os.TempDir()), nil case Docker: client, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { @@ -81,13 +87,14 @@ func NewPlatform(platformType, token, stack string) (Platform, error) { buildpacksManager := docker.NewBuildpacksManager(archiver, buildpacksCache, buildpacksRegistry) networkManager := docker.NewNetworkManager(client) - initialize := docker.NewInitialize(buildpacksRegistry) + initialize := docker.NewInitialize(buildpacksRegistry, networkManager) + deinitialize := docker.NewDeinitialize(networkManager) setup := docker.NewSetup(client, lifecycleManager, buildpacksManager, archiver, networkManager, workspace, stack) stage := docker.NewStage(client, archiver, workspace) start := docker.NewStart(client, networkManager, workspace, stack) - teardown := docker.NewTeardown(client, networkManager, workspace) + teardown := docker.NewTeardown(client, workspace) - return NewDocker(initialize, setup, stage, start, teardown), nil + return NewDocker(initialize, deinitialize, setup, stage, start, teardown), nil } return Platform{}, fmt.Errorf("unknown platform type: %q", platformType) @@ -96,3 +103,7 @@ func NewPlatform(platformType, token, stack string) (Platform, error) { func (p Platform) Initialize(buildpacks ...Buildpack) error { return p.initialize.Execute(buildpacks...) } + +func (p Platform) Deinitialize() error { + return p.deinitialize.Execute() +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 82f9d982e..511495c93 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -26,8 +26,8 @@ github.com/cloudfoundry/libbuildpack/cutlass github.com/cloudfoundry/libbuildpack/cutlass/docker github.com/cloudfoundry/libbuildpack/cutlass/glow github.com/cloudfoundry/libbuildpack/packager -# github.com/cloudfoundry/switchblade v0.6.0 -## explicit; go 1.19 +# github.com/cloudfoundry/switchblade v0.9.0 +## explicit; go 1.23.0 github.com/cloudfoundry/switchblade github.com/cloudfoundry/switchblade/internal/cloudfoundry github.com/cloudfoundry/switchblade/internal/docker