

Our Magento 2 Deployment Process
- technical
Our solution has two main components: a PWA headless frontend running on AWS Lambda and a Magento 2 backend deployed on Kubernetes powered by AWS EKS.
We described how we host the Magento 2 backend on Kubernetes in our previous article, and this article will focus on how our Continuous Deployment process works.
How are the modules set up
One of the differentiating advantages of Magento is its extensibility. So, following best practices, regardless of whether various functions are globally deployed on all our projects or selectively deployed, we separated each functionality and feature into its own Magento module.
All modules use Composer.
Github & Versioning
One of the initial requirements was to have versioning for modules, so the code ready for deployment is released with precise version numbers and release notes.
When developers push code to Github, CI Actions automatically start for code quality checks and validations. But for code to be deployable to production, a Release action in Github is needed.
Once we create a Release, a Github Action automatically starts and packages the code for Composer and deploys it to a private S3 repository, which will later serve as a source for deployment.
Deployment
We automate deployments through AWS Step Functions: when we want to launch a new project or update an existing project, a Step Function is started and updates the PWA frontend, Magento 2 backend, and related services.
For the Magento 2 part, the step function receives the Magento 2 version number and the list of modules the project uses, with the exact version number. The step function runs the following operations:
- Build backend Docker image
- Deploy Docker image to Kubernetes
- Execute Install or Upgrade operations
Knowing the Magento 2 version number and modules used by the project, a CodeBuild function starts. The CodeBuild process has the unpacked Magento codes, then installs each module from S3, using Composer.
The result is a folder containing the exact code that we need to run the project, and a Docker build process bundles the codes into a Docker image, for the current project.
CodeBuild uploads the resulting Docker image to AWS’s ECR (Elastic Container Registry), thus concluding the build.
Deploy to Kubernetes
Once we have the Docker image resulting from CodeBuild, the Step Function starts the deployment to EKS:
- create Namespace if needed
- create/update Pod Access
- create/update ConfigMap
- create/update M2-HTTP service & pods
- create/update M2-Cron service & pods
- create/update M2-Consumer service & pods
- create/update Varnish service & pods
The Pod Access Role regulates the access pods inside the project namespace have to other AWS services: S3 for storage, SES for email, SQS for various queues, CloudFront for invalidation, etc.
The M2-HTTP, M2-Cron, and M2-Consumer services are updated to use the new docker image built with CodeBuild, while Varnish is updated to use its latest service image.
One of the main advantages of this deployment strategy is that all the lengthy operations are performed in CodeBuild so that the launching of pods is light and fast (2-3s).
Execute Install or Upgrade operations
Once the latest code is built into the Docker image and deployed on Kubernetes, it’s time to execute the update or the install operations Magento needs to update the database.
The install operation executes the Magento install, as well as a suite of commands that configure Magento.
The update operation executed the Magento “setup upgrade” command, then clears caches and indexes.
Conclusions
Our goal with the deployment process was to be completely automated, fault-tolerant, fast for the Kubernetes auto-scaling operation, and produce zero downtime.
Our process is: automated (modules and versions provided as input, then everything happens automatically), fault-tolerant (if anything fails, the process stops without affecting the live shop), and fast to scale (all the heavy operations were kept out of the deployment part and moved to build). The result is zero-downtime deployments.