Skip to content
Open
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
40 changes: 33 additions & 7 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import (

"github.com/invopop/jsonschema"
"github.com/railwayapp/railpack/core/plan"
denoconfig "github.com/railwayapp/railpack/core/providers/deno/config"
dotnetconfig "github.com/railwayapp/railpack/core/providers/dotnet/config"
elixirconfig "github.com/railwayapp/railpack/core/providers/elixir/config"
gleamconfig "github.com/railwayapp/railpack/core/providers/gleam/config"
golangconfig "github.com/railwayapp/railpack/core/providers/golang/config"
javaconfig "github.com/railwayapp/railpack/core/providers/java/config"
nodeconfig "github.com/railwayapp/railpack/core/providers/node/config"
phpconfig "github.com/railwayapp/railpack/core/providers/php/config"
pythonconfig "github.com/railwayapp/railpack/core/providers/python/config"
rubyconfig "github.com/railwayapp/railpack/core/providers/ruby/config"
rustconfig "github.com/railwayapp/railpack/core/providers/rust/config"
shellconfig "github.com/railwayapp/railpack/core/providers/shell/config"
staticfileconfig "github.com/railwayapp/railpack/core/providers/staticfile/config"
"github.com/railwayapp/railpack/internal/utils"
)

Expand All @@ -27,13 +40,26 @@ type StepConfig struct {
}

type Config struct {
Provider *string `json:"provider,omitempty" jsonschema:"description=The provider to use"`
BuildAptPackages []string `json:"buildAptPackages,omitempty" jsonschema:"description=List of apt packages to install during the build step"`
Steps map[string]*StepConfig `json:"steps,omitempty" jsonschema:"description=Map of step names to step definitions"`
Deploy *DeployConfig `json:"deploy,omitempty" jsonschema:"description=Deploy configuration"`
Packages map[string]string `json:"packages,omitempty" jsonschema:"description=Map of package name to package version"`
Caches map[string]*plan.Cache `json:"caches,omitempty" jsonschema:"description=Map of cache name to cache definitions. The cache key can be referenced in an exec command"`
Secrets []string `json:"secrets,omitempty" jsonschema:"description=Secrets that should be made available to commands that have useSecrets set to true"`
Provider *string `json:"provider,omitempty" jsonschema:"description=The provider to use"`
Deno *denoconfig.DenoConfig `json:"deno,omitempty" jsonschema:"description=Configuration for the deno provider"`
Dotnet *dotnetconfig.DotnetConfig `json:"dotnet,omitempty" jsonschema:"description=Configuration for the dotnet provider"`
Elixir *elixirconfig.ElixirConfig `json:"elixir,omitempty" jsonschema:"description=Configuration for the elixir provider"`
Gleam *gleamconfig.GleamConfig `json:"gleam,omitempty" jsonschema:"description=Configuration for the gleam provider"`
Golang *golangconfig.GolangConfig `json:"golang,omitempty" jsonschema:"description=Configuration for the golang provider"`
Java *javaconfig.JavaConfig `json:"java,omitempty" jsonschema:"description=Configuration for the java provider"`
Node *nodeconfig.NodeConfig `json:"node,omitempty" jsonschema:"description=Configuration for the node provider"`
Php *phpconfig.PhpConfig `json:"php,omitempty" jsonschema:"description=Configuration for the php provider"`
Python *pythonconfig.PythonConfig `json:"python,omitempty" jsonschema:"description=Configuration for the python provider"`
Ruby *rubyconfig.RubyConfig `json:"ruby,omitempty" jsonschema:"description=Configuration for the ruby provider"`
Rust *rustconfig.RustConfig `json:"rust,omitempty" jsonschema:"description=Configuration for the rust provider"`
Shell *shellconfig.ShellConfig `json:"shell,omitempty" jsonschema:"description=Configuration for the shell provider"`
Staticfile *staticfileconfig.StaticfileConfig `json:"staticfile,omitempty" jsonschema:"description=Configuration for the staticfile provider"`
BuildAptPackages []string `json:"buildAptPackages,omitempty" jsonschema:"description=List of apt packages to install during the build step"`
Steps map[string]*StepConfig `json:"steps,omitempty" jsonschema:"description=Map of step names to step definitions"`
Deploy *DeployConfig `json:"deploy,omitempty" jsonschema:"description=Deploy configuration"`
Packages map[string]string `json:"packages,omitempty" jsonschema:"description=Map of package name to package version"`
Caches map[string]*plan.Cache `json:"caches,omitempty" jsonschema:"description=Map of cache name to cache definitions. The cache key can be referenced in an exec command"`
Secrets []string `json:"secrets,omitempty" jsonschema:"description=Secrets that should be made available to commands that have useSecrets set to true"`
}

func EmptyConfig() *Config {
Expand Down
5 changes: 5 additions & 0 deletions core/providers/deno/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

type DenoConfig struct {
Version string `json:"version,omitempty" jsonschema:"description=Override the Deno version for the deno provider"`
}
26 changes: 24 additions & 2 deletions core/providers/deno/deno.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/railwayapp/railpack/core/generate"
"github.com/railwayapp/railpack/core/plan"
denoconfig "github.com/railwayapp/railpack/core/providers/deno/config"
)

const (
Expand Down Expand Up @@ -84,13 +85,34 @@ func (p *DenoProvider) Build(ctx *generate.GenerateContext, build *generate.Comm
func (p *DenoProvider) InstallMisePackages(ctx *generate.GenerateContext, miseStep *generate.MiseStepBuilder) {
deno := miseStep.Default("deno", DEFAULT_DENO_VERSION)

if envVersion, varName := ctx.Env.GetConfigVariable("DENO_VERSION"); envVersion != "" {
miseStep.Version(deno, envVersion, varName)
if denoVersion, source := p.denoVersion(ctx); denoVersion != "" {
miseStep.Version(deno, denoVersion, source)
}

miseStep.UseMiseVersions(ctx, []string{"deno"})
}

func (p *DenoProvider) providerConfig(ctx *generate.GenerateContext) *denoconfig.DenoConfig {
if ctx.Config == nil {
return nil
}

return ctx.Config.Deno
}

func (p *DenoProvider) denoVersion(ctx *generate.GenerateContext) (string, string) {
if envVersion, varName := ctx.Env.GetConfigVariable("DENO_VERSION"); envVersion != "" {
return envVersion, varName
}

providerConfig := p.providerConfig(ctx)
if providerConfig != nil && providerConfig.Version != "" {
return providerConfig.Version, "deno.version"
}

return "", ""
}

func (p *DenoProvider) findMainFile(ctx *generate.GenerateContext) string {
files := []string{"main.ts", "main.js", "main.mjs", "main.mts"}
for _, file := range files {
Expand Down
39 changes: 39 additions & 0 deletions core/providers/deno/deno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,42 @@ func TestDeno(t *testing.T) {
})
}
}

func TestDenoProviderConfigFromFile(t *testing.T) {
t.Run("deno version from provider config", func(t *testing.T) {
ctx := testingUtils.CreateGenerateContext(t, "../../../examples/deno-2")
testingUtils.ClearConfigVariable(ctx, "DENO_VERSION")
testingUtils.SetConfigFromJSON(t, ctx, `{
"deno": {
"version": "2.1.0"
}
}`)

provider := DenoProvider{}
require.NoError(t, provider.Initialize(ctx))
require.NoError(t, provider.Plan(ctx))

denoVersion := ctx.Resolver.Get("deno")
require.Equal(t, "2.1.0", denoVersion.Version)
require.Equal(t, "deno.version", denoVersion.Source)
})

t.Run("deno env var takes precedence over provider config", func(t *testing.T) {
ctx := testingUtils.CreateGenerateContext(t, "../../../examples/deno-2")
testingUtils.ClearConfigVariable(ctx, "DENO_VERSION")
ctx.Env.SetVariable("RAILPACK_DENO_VERSION", "2.4.0")
testingUtils.SetConfigFromJSON(t, ctx, `{
"deno": {
"version": "2.1.0"
}
}`)

provider := DenoProvider{}
require.NoError(t, provider.Initialize(ctx))
require.NoError(t, provider.Plan(ctx))

denoVersion := ctx.Resolver.Get("deno")
require.Equal(t, "2.4.0", denoVersion.Version)
require.Equal(t, "RAILPACK_DENO_VERSION", denoVersion.Source)
})
}
5 changes: 5 additions & 0 deletions core/providers/dotnet/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

type DotnetConfig struct {
Version string `json:"version,omitempty" jsonschema:"description=Override the .NET version for the dotnet provider"`
}
26 changes: 24 additions & 2 deletions core/providers/dotnet/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/railwayapp/railpack/core/generate"
"github.com/railwayapp/railpack/core/plan"
dotnetconfig "github.com/railwayapp/railpack/core/providers/dotnet/config"
"github.com/railwayapp/railpack/internal/utils"
)

Expand Down Expand Up @@ -164,13 +165,34 @@ func (p *DotnetProvider) InstallMisePackages(ctx *generate.GenerateContext, mise
}
}

if envVersion, varName := ctx.Env.GetConfigVariable("DOTNET_VERSION"); envVersion != "" {
miseStep.Version(dotnet, envVersion, varName)
if dotnetVersion, source := p.dotnetVersion(ctx); dotnetVersion != "" {
miseStep.Version(dotnet, dotnetVersion, source)
}

miseStep.UseMiseVersions(ctx, []string{"dotnet"})
}

func (p *DotnetProvider) providerConfig(ctx *generate.GenerateContext) *dotnetconfig.DotnetConfig {
if ctx.Config == nil {
return nil
}

return ctx.Config.Dotnet
}

func (p *DotnetProvider) dotnetVersion(ctx *generate.GenerateContext) (string, string) {
if envVersion, varName := ctx.Env.GetConfigVariable("DOTNET_VERSION"); envVersion != "" {
return envVersion, varName
}

providerConfig := p.providerConfig(ctx)
if providerConfig != nil && providerConfig.Version != "" {
return providerConfig.Version, "dotnet.version"
}

return "", ""
}

func (p *DotnetProvider) getDotnetVersion(ctx *generate.GenerateContext) string {
miseStepBuilder := ctx.GetMiseStepBuilder()
pkg := miseStepBuilder.Resolver.Get("dotnet")
Expand Down
39 changes: 39 additions & 0 deletions core/providers/dotnet/dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,42 @@ func TestDotnet(t *testing.T) {
})
}
}

func TestDotnetProviderConfigFromFile(t *testing.T) {
t.Run("dotnet version from provider config", func(t *testing.T) {
ctx := testingUtils.CreateGenerateContext(t, "../../../examples/dotnet-cli")
testingUtils.ClearConfigVariable(ctx, "DOTNET_VERSION")
testingUtils.SetConfigFromJSON(t, ctx, `{
"dotnet": {
"version": "9.0"
}
}`)

provider := DotnetProvider{}
require.NoError(t, provider.Initialize(ctx))
require.NoError(t, provider.Plan(ctx))

dotnetVersion := ctx.Resolver.Get("dotnet")
require.Equal(t, "9.0", dotnetVersion.Version)
require.Equal(t, "dotnet.version", dotnetVersion.Source)
})

t.Run("dotnet env var takes precedence over provider config", func(t *testing.T) {
ctx := testingUtils.CreateGenerateContext(t, "../../../examples/dotnet-cli")
testingUtils.ClearConfigVariable(ctx, "DOTNET_VERSION")
ctx.Env.SetVariable("RAILPACK_DOTNET_VERSION", "8.0")
testingUtils.SetConfigFromJSON(t, ctx, `{
"dotnet": {
"version": "9.0"
}
}`)

provider := DotnetProvider{}
require.NoError(t, provider.Initialize(ctx))
require.NoError(t, provider.Plan(ctx))

dotnetVersion := ctx.Resolver.Get("dotnet")
require.Equal(t, "8.0", dotnetVersion.Version)
require.Equal(t, "RAILPACK_DOTNET_VERSION", dotnetVersion.Source)
})
}
6 changes: 6 additions & 0 deletions core/providers/elixir/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

type ElixirConfig struct {
Version string `json:"version,omitempty" jsonschema:"description=Override the Elixir version for the elixir provider"`
ErlangVersion string `json:"erlangVersion,omitempty" jsonschema:"description=Override the Erlang version for the elixir provider"`
}
43 changes: 39 additions & 4 deletions core/providers/elixir/elixir.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/railwayapp/railpack/core/app"
"github.com/railwayapp/railpack/core/generate"
"github.com/railwayapp/railpack/core/plan"
elixirconfig "github.com/railwayapp/railpack/core/providers/elixir/config"
"github.com/railwayapp/railpack/core/providers/node"
"github.com/railwayapp/railpack/internal/utils"
)
Expand Down Expand Up @@ -202,8 +203,8 @@ func (p *ElixirProvider) InstallMisePackages(ctx *generate.GenerateContext, mise
miseStep.Version(elixir, strings.TrimSpace(string(versionFile)), ".elixir-version")
}

if envVersion, varName := ctx.Env.GetConfigVariable("ELIXIR_VERSION"); envVersion != "" {
miseStep.Version(elixir, envVersion, varName)
if elixirVersion, source := p.elixirVersion(ctx); elixirVersion != "" {
miseStep.Version(elixir, elixirVersion, source)
}

erlang := miseStep.Default("erlang", DEFAULT_ERLANG_VERSION)
Expand Down Expand Up @@ -235,13 +236,47 @@ func (p *ElixirProvider) InstallMisePackages(ctx *generate.GenerateContext, mise
miseStep.Version(erlang, strings.TrimSpace(string(versionFile)), ".erlang-version")
}

if envVersion, varName := ctx.Env.GetConfigVariable("ERLANG_VERSION"); envVersion != "" {
miseStep.Version(erlang, envVersion, varName)
if erlangVersion, source := p.erlangVersion(ctx); erlangVersion != "" {
miseStep.Version(erlang, erlangVersion, source)
}

miseStep.UseMiseVersions(ctx, []string{"elixir", "erlang"})
}

func (p *ElixirProvider) providerConfig(ctx *generate.GenerateContext) *elixirconfig.ElixirConfig {
if ctx.Config == nil {
return nil
}

return ctx.Config.Elixir
}

func (p *ElixirProvider) elixirVersion(ctx *generate.GenerateContext) (string, string) {
if envVersion, varName := ctx.Env.GetConfigVariable("ELIXIR_VERSION"); envVersion != "" {
return envVersion, varName
}

providerConfig := p.providerConfig(ctx)
if providerConfig != nil && providerConfig.Version != "" {
return providerConfig.Version, "elixir.version"
}

return "", ""
}

func (p *ElixirProvider) erlangVersion(ctx *generate.GenerateContext) (string, string) {
if envVersion, varName := ctx.Env.GetConfigVariable("ERLANG_VERSION"); envVersion != "" {
return envVersion, varName
}

providerConfig := p.providerConfig(ctx)
if providerConfig != nil && providerConfig.ErlangVersion != "" {
return providerConfig.ErlangVersion, "elixir.erlangVersion"
}

return "", ""
}

func (p *ElixirProvider) GetEnvVars(ctx *generate.GenerateContext) map[string]string {
return map[string]string{
"LANG": "en_US.UTF-8",
Expand Down
Loading
Loading