How can I reduce build times in my application?

Last updated: April 1, 2025

Context

When deploying applications through CI/CD pipelines, build times can sometimes be lengthy (10+ minutes). Users may want to optimize these build times to improve their development workflow.

Answer

There are two main approaches to building applications on our platform, each with different optimization capabilities:

Build Pack Approach

If your application uses Heroku build packs (the default approach), there are currently no available methods to implement build caching or optimize build times. This is due to limited control over the Heroku build pack system.

Dockerfile Approach (Recommended for Build Optimization)

Using a Dockerfile approach allows you to implement build caching, which can significantly reduce build times. To implement this:

  1. Create a Dockerfile for your application following the Docker documentation

  2. Configure your application to use the Dockerfile build method

  3. Enable build caching by adding the following environment variable to your GitHub Actions workflow:

    DOCKER_BUILDKIT: 1

When using build caching, you may need to run a few builds initially for the layers to be cached. After this initial setup, you should see significant improvements in build times.

For optimal results when using Dockerfiles, we recommend following Docker build best practices, which include:

  • Organizing your layers efficiently

  • Using multi-stage builds when appropriate

  • Minimizing the number of layers