All Products
Search
Document Center

CloudOps Orchestration Service:Local debug buildpacks build

Last Updated:Mar 11, 2025

To build and deploy applications quickly and successfully, it is advisable to debug buildpacks builds locally. Debugging locally helps identify and resolve issues swiftly, reducing the risk of deployment failures and enhancing development efficiency.

Preparations

  • Network preparation

    Ensure normal access to Docker Hub from your local environment, as buildpacks-related container images are hosted there.

  • Install Docker

    Before using the Pack tool, Docker must be installed on your system. For Alibaba Cloud Linux operating systems, use the following installation commands:

    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    yum makecache
    yum install -y curl git docker-ce
    systemctl enable docker && systemctl start docker
  • Application code: Ensure that your application code repository is ready.

Procedure

Step 1: Install the Pack tool

Download and install the Pack tool using the following commands. This example is for the Alibaba Cloud Linux operating system.

# Download and install pack
PACK_VERSION="0.36.4"
DOWNLOAD_URL="https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz"
CHECKSUM_URL="${DOWNLOAD_URL}.sha256"
# Download and verify the pack file
echo "Downloading pack v${PACK_VERSION}..."
if ! curl -fsSL "$DOWNLOAD_URL" -o pack-v${PACK_VERSION}-linux.tgz; then
    echo "Failed to download pack v${PACK_VERSION}."
    exit 1
fi
echo "Downloading completed."
echo "Verifying checksum..."
if ! curl -fsSL "$CHECKSUM_URL" -o pack.tgz.sha256; then
    echo "Failed to download checksum file."
    exit 1
fi
if ! sha256sum --check --status pack.tgz.sha256; then
    echo "Checksum verification failed."
    exit 1
fi
echo "Checksum verified successfully."
tar xvzf pack-v${PACK_VERSION}-linux.tgz -C /usr/local/bin/

# Check if the installation was successful
pack --version

Step 2: Use the Pack tool to debug the application

  1. Build the application and create an image using the pack build command.

    • Command: Replace <your-image-name> with the name of the container image to be generated, and replace Replace with the name of the container image to be generated,<path-to-your-app> with the local path of the application code.

      pack build <your-image-name> --path <path-to-your-app> --builder heroku/builder:24
    • Example: In this example, the image name is my-app, and the path is ./my-app.

      pack build my-app --path ./my-app --builder heroku/builder:24
  2. Run the generated image with the following command.

    # Specify environment variables and ports according to your application code
    docker run -e PORT=8080 -p8080:8080 my-app
  3. Access http://localhost:<port-number> to test your application.

    In this example, replace <port-number> with 8080.

Step 3: Debug and adapt the application

If the application encounters issues during build or runtime, debug and adapt it accordingly.

  1. Examine the application build logs.

    For detailed build logs, use the --verbose parameter. The command is as follows:

    pack build my-app --path ./my-app --builder heroku/builder:24 --verbose
  2. Modify the application code and debug once more.

    Based on the debugging information, modify the code and execute pack build once more.

  3. Incorporate environment variables.

    Pass environment variables using the --env option. The command is as follows:

    pack build my-app --path ./my-app --builder heroku/builder:24 --env MY_ENV=production
  4. Conduct further local testing and verification.

    Ensure the application's functionality and performance meet the requirements by running and testing it within the container.

References