Code Assembly

Managing dependencies with Code Assembly

This page provides information about how Code Assembly manages the dependencies of applications.

After you enable Code Assembly, it monitors your hosting repository, detects new commits, and checks the commit for key markers to determine its next steps.

For Composer, Code Assembly checks for the following:

  • Presence of a composer.json file
  • Absence of a vendor directory
  • Definition of php_version in the composer.json file

    To add php_version in the composer.json file, run the following command:

    composer config extra.acquia.code-assembly.php_version 8.3

    The command adds the following lines to the composer.json file:

    "extra": {
    	"acquia": {
    		"code-assembly.php_version": "8.3"
    	}
    }

For NPM, Code Assembly checks for the following:

  • Presence of a package.json file
  • Absence of a node_modules directory
  • Definition of node_version in the package.json file

    To add node_version in the package.json file, add it in the extra section as follows:

    "extra": {
    	"acquia": {
    		"code-assembly.node_version": "18",
    		"code-assembly.install_command": "npm i",
    		"code-assembly.root_directory": "./"
    	}
    }
    Note

    The parameters in the extra section vary depending on the method used for generating content for the Static Site Generation (SSG), Server Side Rendering (SSR), or Incremental Site Generation (ISG) application.

If Code Assembly detects the appropriate markers, it executes the necessary steps to install dependencies and build a hosting artifact. This process might take several minutes to build the code and push the artifacts. If Code Assembly does not detect an appropriate .json file or it detects the presence of a directory managed by the dependency manager, the task fails and Code Assembly sends appropriate messages to the task log present in the Cloud Platform user interface. The messages help users to know the reason for failure, such as absence of the composer.json file or the package.json file, presence of the vendor directory or the node_modules directory, absence of the definition of php_version or the node_version, and so on.

During the execution, Code Assembly places the output of the composer install command or the npm install command into a build branch. The name of the build branch is based on the branch where the commit was made. For instance, if you have a branch named <BRANCH_NAME>, then Code Assembly commits the resulting build artifact into CODE-ASSEMBLY-BUILD-<BRANCH_NAME>.

After Code Assembly makes a commit into CODE-ASSEMBLY-BUILD-<BRANCH_NAME>, Cloud Platform deploys the resulting code into any environments that follow the CODE-ASSEMBLY-BUILD-<BRANCH_NAME> naming convention. If none of the branches follows the CODE-ASSEMBLY-BUILD-<BRANCH_NAME> naming convention, Cloud Platform does not follow automatic deployments.

If a branch does not follow the CODE-ASSEMBLY-BUILD-<BRANCH_NAME> naming convention, you can still deploy it to an environment. However, such a deployment does not install the necessary dependencies that allow the application to bootstrap and run. If you build the dependencies on your own and commit to this branch, Cloud Platform will not deploy automatic updates made to this branch, into the environments that follow it. The reason is that the branch is not considered to be deployable when you enable Code Assembly. Therefore, you must disable Code Assembly to manage dependencies on your own.

If you use Code Assembly, ensure that Cloud Platform deploys only the build branches and those branches follow the CODE-ASSEMBLY-BUILD-<BRANCH> naming convention for deployable branches.

If you use another tool to install and manage dependencies, you must not use Code Assembly to deploy a branch that is not managed by Code Assembly.

Scenario: Workflow using Code Assembly

Assumptions

  • The project under consideration is a Drupal project
  • A new version of Drupal is released
  • Code Assembly is configured for your Drupal or Node.js application

Context

  • The project is deployed and is in production on Cloud Next
  • Drupal was last updated approximately 1 month ago when the last feature release came out
  • The development environment is tracking a branch named CODE-ASSEMBLY-BUILD-develop
  • The name of the primary branch in the hosting repository is develop
  • Cloud IDEs are in use
  • Cloud Actions are configured to update the database, import configuration changes, and flush caches on each deployment

A new security release of Drupal is released. Your team wants to update to this most recent security release.

Workflow

  1. A user opens their Cloud IDE and pulls the most recent commit from the develop branch in the hosting repository using Git:

    git checkout develop
  2. The user updates Drupal core in their Cloud IDE by running:

    composer update drupal/core --with-all-dependencies
  3. The user commits the resulting changes to the composer.json file and the composer.lock file.
  4. The user pushes these changes to the develop branch of the hosting Git repository.

    As you enable Code Assembly, the workflow involves working with the following types of branches:

    • Unbuild branches: Branches that do not have the <BRANCHNAME> prefix
    • Fully built branches: Branches that contain the CODE-ASSEMBLY-BUILD-<BRANCHNAME> prefix
  5. The user makes commits on unbuild branches, and Code Assembly performs the build process.

  6. Code Assembly detects the change and installs dependencies.
  7. Code Assembly commits the changes from its build into CODE-ASSEMBLY-BUILD-develop.

    The user works on a pair of branches that are dependent on each other:

    <BRANCHNAME>: The non-deployable branch where the user makes commits.

    CODE-ASSEMBLY-BUILD-<BRANCHNAME>: The deployable branch built from the commits to <BRANCHNAME>. This branch can be deployed to any environment.

    Any commits made to this branch are overridden with every new build.

  8. The development environment deploys the changes because it tracks the build branch.
  9. Cloud Actions execute in the development environment during the deployment to update the database, import configuration changes, and flush caches on each deployment.
  10. The customer team reviews the new version of Drupal in the development environment. After testing, a production deployment can be performed by creating a tag from the CODE-ASSEMBLY-BUILD-develop branch.

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Acquia Help

Filter by product:

Code Assembly common questions