in cmd/ruby/runtime/main.go [75:130]
func buildFn(ctx *gcp.Context) error {
version, err := ruby.DetectVersion(ctx)
if err != nil {
return fmt.Errorf("determining runtime version: %w", err)
}
rl, err := ctx.Layer("ruby", gcp.BuildLayer, gcp.CacheLayer, gcp.LaunchLayerUnlessSkipRuntimeLaunch)
if err != nil {
return fmt.Errorf("creating layer: %w", err)
}
// Rails asset precompilation needs Node.js installed. Set the version if customer has not set it.
if os.Getenv(nodejs.EnvNodeVersion) == "" {
railsNodeVersion := getRailsNodeVersion(ctx)
ctx.Logf("Setting Nodejs runtime version %s: %s", nodejs.EnvNodeVersion, railsNodeVersion)
rl.BuildEnvironment.Override(nodejs.EnvNodeVersion, railsNodeVersion)
}
_, err = runtime.InstallTarballIfNotCached(ctx, runtime.Ruby, version, rl)
if err != nil {
return err
}
versionInstalled, _ := runtime.ResolveVersion(ctx, runtime.Ruby, version, runtime.OSForStack(ctx))
// Store the installed Ruby version for subsequent buildpacks (like RubyGems) that depend on it.
rl.BuildEnvironment.Override(ruby.RubyVersionKey, versionInstalled)
ctx.Exec([]string{"ldd", filepath.Join(rl.Path, "lib/ruby/3.1.0/x86_64-linux/psych.so")})
// For GAE and GCF, install RubyGems and Bundler in the same layer to maintain compatibility
// with existing builder images.
if env.IsGAE() || env.IsGCF() {
err = runtime.PinGemAndBundlerVersion(ctx, version, rl)
if err != nil {
return fmt.Errorf("updating rubygems and bundler: %w", err)
}
}
// Ruby sometimes writes to local directories tmp/ and log/, so we link these to writable areas.
localTemp := filepath.Join(ctx.ApplicationRoot(), "tmp")
localLog := filepath.Join(ctx.ApplicationRoot(), "log")
ctx.Logf("Removing 'tmp' and 'log' directories in user code")
if err := ctx.RemoveAll(localTemp); err != nil {
return err
}
if err := ctx.RemoveAll(localLog); err != nil {
return err
}
if err := ctx.Symlink("/tmp", localTemp); err != nil {
return err
}
if err := ctx.Symlink("/var/log", localLog); err != nil {
return err
}
return nil
}