The buildpack strategy in Blossom allows you to customize your Docker image after the buildpack has created the base image. This is perfect for adding additional packages, setting environment variables, or performing any custom setup without having to learn the intricacies of the build process.
Note: This applies when your project is using the auto (the default) or buildpack build config build type strategy. You also achieve customization by using a Dockerfile build type instead. For most users, I think using the .blossom/build
is easiest.
How It Works
- Blossom uses
pack
to build your application with the Heroku buildpack - A Dockerfile is generated that uses the buildpack image as the base
- If a custom build script is detected, it’s automatically included in the Dockerfile
- The final Docker image is built with your customizations
Custom Build Script
To add customizations, simply create an executable script at .blossom/build
in your project root:
.blossom/build
#!/bin/bash
echo "===> Running custom build script..."
# Install additional packages
apt-get update && apt-get install -y curl jq
# Set environment variables
echo "export CUSTOM_VAR=value" >> /etc/environment
# Create custom directories
mkdir -p /workspace/custom
# Copy additional files
cp -r /tmp/custom-files/* /workspace/
echo "===> Custom build script completed"
What You Can Do
Your custom build script can:
- Install packages: Use
apt-get
since the heroku buildpack is ubuntu based - Set environment variables: Add custom environment variables
- Run commands: Execute any commands needed for your application
Example Use Cases
Installing Additional Tools
#!/bin/bash
set -e
echo "===> Installing additional tools..."
curl -sSL https://get.docker.com | sh
Detection
Blossom automatically detects your custom build script when:
- The file
.blossom/build
exists
You’ll see a log message when the script is detected:
===> Detected custom build script: .blossom/build
Troubleshooting
If your script isn’t being detected:
- Ensure the file is at
.blossom/build
(not.blossom/build.sh
)
If your script fails during build:
- Check the Docker build logs for error messages
- Test your script locally first
- Use
set -e
to catch errors early - Add debug output with
echo
statements