Skip to content

[Bug]: Preview Deployments Fail for Static Sites #8238

@psampaio

Description

@psampaio

Error Message and Logs

Preview deployments (pull request deployments) for static websites fail with the error:

ERROR: failed to build: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory

Regular deployments of the same static site work correctly.

Steps to Reproduce

  1. Create an application with build_pack set to 'static'
  2. Configure the application to deploy from a Git repository
  3. Enable preview deployments for the application
  4. Create a pull request in the connected repository
  5. Trigger a preview deployment

Example Repository URL

No response

Coolify Version

v4.0.0-beta.462

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

No response

Additional Information

The issue is in the deployment routing logic in ApplicationDeploymentJob.php:

Main Deployment Handler (lines 462-476)

} elseif ($this->pull_request_id !== 0) {
    $this->deploy_pull_request();  // ← All preview deployments go here
} elseif ($this->application->dockerfile) {
    $this->deploy_simple_dockerfile();
} elseif ($this->application->build_pack === 'dockercompose') {
    $this->deploy_docker_compose_buildpack();
} elseif ($this->application->build_pack === 'dockerimage') {
    $this->deploy_dockerimage_buildpack();
} elseif ($this->application->build_pack === 'dockerfile') {
    $this->deploy_dockerfile_buildpack();
} elseif ($this->application->build_pack === 'static') {
    $this->deploy_static_buildpack();  // ← Regular static deployments go here
} else {
    $this->deploy_nixpacks_buildpack();
}

Problem: When pull_request_id !== 0, the code immediately calls deploy_pull_request() without checking the build_pack type. This bypasses all build pack-specific routing.

Preview Deployment Handler (lines 1878-1913)

private function deploy_pull_request()
{
    if ($this->application->build_pack === 'dockercompose') {
        $this->deploy_docker_compose_buildpack();
        return;
    }
    // ← Missing: No check for 'static' build pack!

    if ($this->use_build_server) {
        $this->server = $this->build_server;
    }
    $this->newVersionIsHealthy = true;
    $this->generate_image_names();
    $this->application_deployment_queue->addLogEntry("Starting pull request (#{$this->pull_request_id}) deployment...");
    $this->prepare_builder_image();
    $this->check_git_if_build_needed();
    $this->clone_repository();
    $this->cleanup_git();
    if ($this->application->build_pack === 'nixpacks') {
        $this->generate_nixpacks_confs();
    }
    $this->generate_compose_file();
    $this->save_buildtime_environment_variables();
    $this->generate_build_env_variables();
    if ($this->application->build_pack === 'dockerfile') {
        $this->add_build_env_variables_to_dockerfile();
    }
    $this->build_image();  // ← This expects a Dockerfile, which static sites don't have
    // ...
}

Problem: The deploy_pull_request() method:

  1. Has special handling for dockercompose build pack
  2. Has special handling for dockerfile and nixpacks build packs
  3. Missing: No special handling for static build pack
  4. Defaults to calling build_image() which expects a Dockerfile

For static sites, it should call build_static_image() instead, which creates an inline Dockerfile that copies static files to an nginx image.

Proposed Fix

Add a check for the static build pack in the deploy_pull_request() method, immediately after the dockercompose check:

File: app/Jobs/ApplicationDeploymentJob.php

Location: Line 1878-1887

Change:

private function deploy_pull_request()
{
    if ($this->application->build_pack === 'dockercompose') {
        $this->deploy_docker_compose_buildpack();

        return;
    }
    // ADD THIS BLOCK ↓
    if ($this->application->build_pack === 'static') {
        $this->deploy_static_buildpack();

        return;
    }
    // END NEW BLOCK ↑
    if ($this->use_build_server) {
        $this->server = $this->build_server;
    }
    // ... rest of the method
}

Why This Fix Works

  1. Consistency: The fix makes preview deployments respect the build_pack configuration, just like regular deployments
  2. Reuses Existing Logic: deploy_static_buildpack() already has all the correct logic for static deployments:
    • Uses build_static_image() which creates an inline Dockerfile
    • Copies static files to the nginx base image
    • Handles build-time and runtime environment variables correctly
  3. Follows Existing Pattern: The fix mirrors the existing dockercompose check, maintaining code consistency

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔍 TriageIssues that need assessment and prioritization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions