Deploy Application Without Dockerfile - Use Buildpacks

Buildpacks is a tool from the Cloud Native Computing Foundation (CNCF) that helps deploy applications without needing a Dockerfile.

It automatically detects the language and dependencies of your application, then builds a container image for you. This simplifies the deployment process, making it easier to manage and scale applications across different environments.

Buildpacks are particularly useful for developers who want to focus on writing code rather than dealing with the complexities of containerization.

Deploy NodeJS application using Cloud Native Builpacks

Pre-requisites:

  • AWS account

  • An Ubuntu EC2 machine t2.micro (t2.micro is ok, if you are using simple application)

  • Docker installed

Steps:

  • Update your machine
sudo apt update
  • Install docker
sudo apt install docker.io -y
  • Provide permission to ubuntu user to docker group
sudo usermod -aG docker $USER && newgrp docker
  • Install pack utility to build image

      sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
      sudo apt-get update
      sudo apt-get install pack-cli
    

  • Clone your code

git clone https://github.com/DevMadhup/node-todo-cicd.git
  • Go inside the directory
cd node-todo-cicd
  • Remove Dockerfile and docker-compose file to make sure we are not using it for building the image.
rm -rv Dockerfile
rm -rv docker-compose.yaml

  • Run the following command to get the pack builder
pack build suggest

It will help to suggest builder, so that we will get a builder to build our image in smooth way.

  • Copy the google builder and paste in the below command
pack build --builder=<your-builder-from-above-command> notes-app

[!Note] > This build will take some time be patient.

  • After build, check images
docker images

  • Run the image as a container
docker run -itd --name nodeapp -p 8000:8000 django-notes-app

Note:

This application runs on port 8000, that's why we mentioned 8000 in the above command

  • Open port 8000 from the security groups and access your application
http://<public-ip>:8000


The build process has 5 stages in the build pack:

  1. Analyzing
    In this stage, the system examines the application to understand its dependencies and configuration. It checks what is needed to build and run the app efficiently.

  2. Detecting
    Here, the system identifies the buildpacks that are suitable for the application. It determines which buildpacks can provide the necessary environment and tools.

  3. Restoring
    This step involves retrieving cached layers from previous builds. It helps speed up the build process by reusing existing components instead of creating them from scratch.

  4. Building
    During building, the application is compiled and packaged. This stage involves creating the actual runnable image of the application with all its dependencies.

  5. Exporting
    Finally, the built image is exported for deployment. This step includes saving the image to a registry or making it available for running as a container.