×
Community Blog Blog 2: Factor 2 – Dependencies: How to Declare and Isolate for Reliable Builds on Alibaba Cloud

Blog 2: Factor 2 – Dependencies: How to Declare and Isolate for Reliable Builds on Alibaba Cloud

This article explores Factor 2: Dependencies from the 12 Factor App methodology, emphasizing the importance of explicitly declaring and isolating appl...

Blog 3: Factor 2 – Dependencies: Declare and Isolate for Reliable Builds on Alibaba Cloud

In the last post, we explored Factor 1: Codebase and how a single source of truth keeps deployments consistent across environments.

Now, let’s move on to Factor 2: Dependencies—one of the most important steps for ensuring your app runs the same way in development, staging, and production.


What the “Dependencies” Principle Means

"Explicitly declare and isolate dependencies."12factor.net

Every application relies on third-party packages, libraries, or frameworks to function. Without a clear list of these dependencies, developers risk running into the classic:

"It works on my machine!"

By declaring dependencies explicitly, you:

  • Remove guesswork when setting up the application.
  • Ensure staging and production environments behave exactly like development.
  • Enable reproducible builds in CI/CD pipelines.

By isolating dependencies, you:

  • Avoid version conflicts between applications.
  • Keep each project self-contained.
  • Maintain consistent runtime behavior across environments.

Declaring Dependencies

Most programming languages use a manifest file to declare dependencies:

  • Pythonrequirements.txt or pyproject.toml
  • Node.jspackage.json
  • Javapom.xml or build.gradle

Best practice: list every required dependency—including specific versions—to avoid unplanned upgrades or mismatched behavior.


Isolating Dependencies

Isolation prevents conflicts between different applications that use the same packages.

Options include:

  • Pythonvenv or pipenv
  • Node.js → local node_modules in each project
  • Java → build tool–managed classpaths
  • Containers → self-contained runtime images with all dependencies included

In cloud-native environments, containerization has become the preferred method, offering the highest level of isolation and consistency.


How Alibaba Cloud Supports This Principle

Alibaba Cloud provides a robust set of services to help declare, package, and isolate dependencies effectively:

1. Alibaba Cloud Container Registry (ACR)

  • Store Docker images containing your app and its dependencies.
  • Tag images for different environments to control deployment versions.
  • Share images securely across teams and projects.

2. Function Compute

  • Package code with dependencies for serverless workloads.
  • Each function runs in an isolated environment.
  • Perfect for microservices that require lightweight, independent deployments.

3. Cloud Build (in CodePipeline)

  • Automate dependency installation during build stages.
  • Use your manifest files to install exact versions.
  • Generate reproducible artifacts for consistent deployments.

4. Alibaba Cloud Kubernetes (ACK)

  • Run each service in its own containerized environment.
  • Prevent dependency leakage between services.
  • Ideal for multi-service or microservice applications.

Example: Node.js with Alibaba Cloud

Here’s a sample workflow using Node.js, Docker, and Alibaba Cloud:

dockerfile

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["node", "server.js"]

Process:

  1. Declare dependencies in package.json with exact versions.
  2. Build the Docker image locally or in Cloud Build.
  3. Push the image to ACR.
  4. Deploy to ACK or Function Compute.

This ensures every environment runs with the exact same dependencies, eliminating inconsistencies.


Key Takeaways

  • Declare every dependency in a manifest file.
  • Isolate them so they don’t interfere with other apps.
  • Automate dependency management in your CI/CD pipeline.
  • Use Alibaba Cloud’s ACR, Function Compute, Cloud Build, and ACK to achieve consistent, reliable deployments.

Coming Up Next

In Factor 3 – Config, we’ll talk about separating configuration from code and how Alibaba Cloud’s Secrets Manager and ConfigMaps make it simple and secure.


Disclaimer

This article is based on my own understanding and experience applying the 12 Factor App methodology using Alibaba Cloud services. All Alibaba Cloud service names and features mentioned are publicly available and documented by Alibaba Cloud.

0 1 0
Share on

kervs

3 posts | 0 followers

You may also like

Comments