fix(railpack): query buildtime env vars directly instead of via computed attribute
Replace `railpack_environment_variables_collection()` helper (which returned pre-filtered Eloquent attribute collections) with inline queries on `environment_variables()` / `environment_variables_preview()` filtered by `is_buildtime`. This ensures Railpack build variables are sourced from the same query path as the rest of the deployment pipeline and avoids relying on a now-removed accessor that silently included all railpack vars regardless of build context.
This commit is contained in:
parent
ec71d33f5e
commit
ace643d3d8
2 changed files with 23 additions and 16 deletions
|
|
@ -2483,15 +2483,6 @@ private function generate_railpack_env_variables(): Collection
|
|||
return $variables;
|
||||
}
|
||||
|
||||
private function railpack_environment_variables_collection(): Collection
|
||||
{
|
||||
if ($this->pull_request_id === 0) {
|
||||
return $this->application->railpack_environment_variables;
|
||||
}
|
||||
|
||||
return $this->application->railpack_environment_variables_preview;
|
||||
}
|
||||
|
||||
private function normalize_resolved_build_variable_value(EnvironmentVariable $environmentVariable): ?string
|
||||
{
|
||||
$resolvedValue = $environmentVariable->getResolvedValueWithServer($this->mainServer);
|
||||
|
|
@ -2506,9 +2497,23 @@ private function normalize_resolved_build_variable_value(EnvironmentVariable $en
|
|||
return $resolvedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* All buildtime variables that must reach the Railpack build.
|
||||
*
|
||||
* Railpack's BuildKit frontend treats every `--env` passed to `railpack prepare`
|
||||
* as a build secret entry in the generated plan, then pairs it with `--secret id=,env=`
|
||||
* on `docker buildx build`. Because Railpack's schema disallows top-level `variables`
|
||||
* (unlike Nixpacks, which bakes variables into the plan), this `--env` → `--secret`
|
||||
* channel is the only way user-defined buildtime variables become available to
|
||||
* commands declared with `useSecrets: true`.
|
||||
*/
|
||||
private function railpack_build_variables(): Collection
|
||||
{
|
||||
$variables = $this->railpack_environment_variables_collection()
|
||||
$envCollection = $this->pull_request_id === 0
|
||||
? $this->application->environment_variables()->where('is_buildtime', true)->get()
|
||||
: $this->application->environment_variables_preview()->where('is_buildtime', true)->get();
|
||||
|
||||
$variables = $envCollection
|
||||
->mapWithKeys(function (EnvironmentVariable $environmentVariable) {
|
||||
$value = $this->normalize_resolved_build_variable_value($environmentVariable);
|
||||
if (is_null($value) || $value === '') {
|
||||
|
|
|
|||
|
|
@ -41,9 +41,10 @@
|
|||
]);
|
||||
$nullValue->shouldReceive('getResolvedValueWithServer')->once()->with(Mockery::type(Server::class))->andReturn(null);
|
||||
|
||||
$application->shouldReceive('getAttribute')
|
||||
->with('railpack_environment_variables')
|
||||
->andReturn(collect([$nodeVersion, $literalValue, $jsonValue, $nullValue]));
|
||||
$envQuery = Mockery::mock();
|
||||
$envQuery->shouldReceive('where')->with('is_buildtime', true)->once()->andReturnSelf();
|
||||
$envQuery->shouldReceive('get')->once()->andReturn(collect([$nodeVersion, $literalValue, $jsonValue, $nullValue]));
|
||||
$application->shouldReceive('environment_variables')->once()->andReturn($envQuery);
|
||||
|
||||
$job = Mockery::mock(ApplicationDeploymentJob::class)->makePartial();
|
||||
$job->shouldAllowMockingProtectedMethods();
|
||||
|
|
@ -94,9 +95,10 @@
|
|||
]);
|
||||
$previewValue->shouldReceive('getResolvedValueWithServer')->once()->with(Mockery::type(Server::class))->andReturn('preview-value');
|
||||
|
||||
$application->shouldReceive('getAttribute')
|
||||
->with('railpack_environment_variables_preview')
|
||||
->andReturn(collect([$previewValue]));
|
||||
$previewQuery = Mockery::mock();
|
||||
$previewQuery->shouldReceive('where')->with('is_buildtime', true)->once()->andReturnSelf();
|
||||
$previewQuery->shouldReceive('get')->once()->andReturn(collect([$previewValue]));
|
||||
$application->shouldReceive('environment_variables_preview')->once()->andReturn($previewQuery);
|
||||
|
||||
$job = Mockery::mock(ApplicationDeploymentJob::class)->makePartial();
|
||||
$job->shouldAllowMockingProtectedMethods();
|
||||
|
|
|
|||
Loading…
Reference in a new issue