Build Context
The "Build Context" field specifies the directory that will be utilized during the build process. Proper configuration of this field is crucial to ensure that the build process can locate all necessary files and resources. Below are the details on how to use this field effectively for different builders:
Default Behavior
The "Build Context" is set to / by default. If the specified directory does not contain a Dockerfile, CloudStation will default to using the Nixpacks builder. You only need to update this field if your project has a special directory structure or specific build requirements.
Usage
For Docker Builder
Project Root
Description: Use this option if the root directory of your project contains all the necessary files for building your application.
Example: If your project structure is as follows:
/ ├── app/ ├── config/ ├── Dockerfile └── src/Set the "Build Context" to
/.
Subdirectory with Dockerfile
Description: Use this option if your Dockerfile is located in a subdirectory within your project.
Example: If your project structure is as follows:
/ ├── app/ ├── config/ ├── docker/ │ └── Dockerfile └── src/Set the "Build Context" to
/docker.
For Nixpacks Builder
Project Root
Description: Use this option if the root directory of your project contains all the necessary files for building your application using Nixpacks.
Example: If your project structure is as follows:
/ ├── app/ ├── config/ └── src/Set the "Build Context" to
/.
Subdirectory with Build Configurations
Description: Use this option if your build configurations or necessary build files are located in a subdirectory within your project.
Example: If your project structure is as follows:
/ ├── app/ ├── config/ ├── build/ │ └── build.config └── src/Set the "Build Context" to
/build.
Common Scenarios
Frontend Applications
Scenario 1: Single Page Application (SPA) with Docker Builder
Project Structure:
/ ├── public/ ├── src/ ├── Dockerfile └── package.jsonBuild Context: Set the "Build Context" to
/.
Scenario 2: SPA with Nixpacks Builder
Project Structure:
/ ├── public/ ├── src/ └── package.jsonBuild Context: Set the "Build Context" to
/.
Backend Applications
Scenario 3: Node.js Backend with Docker Builder
Project Structure:
/ ├── src/ ├── Dockerfile └── package.jsonBuild Context: Set the "Build Context" to
/.
Scenario 4: Node.js Backend with Nixpacks Builder
Project Structure:
/ ├── src/ └── package.jsonBuild Context: Set the "Build Context" to
/.
Mono-repo with Multiple Services
Scenario 5: Mono-repo with Separate Dockerfiles
Project Structure:
/ ├── service1/ │ ├── src/ │ ├── Dockerfile │ └── package.json ├── service2/ │ ├── src/ │ ├── Dockerfile │ └── package.json └── common/Build Context for Service 1: Set the "Build Context" to
/service1.Build Context for Service 2: Set the "Build Context" to
/service2.
Scenario 6: Mono-repo with Nixpacks
Project Structure:
/ ├── service1/ │ ├── src/ │ └── package.json ├── service2/ │ ├── src/ │ └── package.json └── common/Build Context for Service 1: Set the "Build Context" to
/service1.Build Context for Service 2: Set the "Build Context" to
/service2.
Using Multiple Dockerfiles
Scenario 7: Backend Service with Separate Dockerfiles for Development and Production
Project Structure:
/ ├── src/ ├── Dockerfile.dev ├── Dockerfile.prod └── package.jsonBuild Context for Development: Set the "Build Context" to
/Dockerfile.devin your build configuration.Build Context for Production: Set the "Build Context" to /
Dockerfile.prodin your build configuration.
Troubleshooting
File Not Found: If the build process cannot find certain files, double-check the path specified in the "Build Context" and ensure it is correct relative to the root of your repository.
Build Failures: If you encounter build failures, review the build configuration and the context directory to ensure all necessary dependencies and files are included.
By following these guidelines, you can effectively configure the "Build Context" field to ensure smooth and efficient build processes for your applications, whether using Docker or Nixpacks builders.