|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +group: cloud |
| 4 | +subgroup: 01_welcome |
| 5 | +title: Deployment process |
| 6 | +menu_title: Deployment process |
| 7 | +menu_order: 4 |
| 8 | +menu_node: |
| 9 | +version: 2.2 |
| 10 | +github_link: cloud/discover-deploy.md |
| 11 | +--- |
| 12 | + |
| 13 | +Deploying Magento means simply pushing the source code to your Git repository. The Git repository is part of your projects cluster so it is totally isolated from |
| 14 | +other clients. |
| 15 | + |
| 16 | +The built-in Git repository is at the same time "just a normal Git repository" and a very smart piece of software. When you push to it, it will parse the configuration files you committed to your repository so it knows what it needs to deploy. |
| 17 | + |
| 18 | +If you are pushing directly to the Magento Enterprise Cloud Edition Git repository, you will see in your terminal |
| 19 | +what is happening in real-time. The same information is going to get streamed in real-time to the Web Interface. |
| 20 | + |
| 21 | +## GitHub and Bitbucket {#cloud-deploy-over-gh} |
| 22 | +If you are using external Bitbucket or GitHub repositories, the log |
| 23 | +of the operations does not display in the GitHub session. You can still follow what's happening in their interface and in the Magento Enterprise Cloud Edition's Web Interface. |
| 24 | + |
| 25 | +## Project configuration {#cloud-deploy-conf} |
| 26 | +What makes it all work is a set of YAML configuration files located in the project root directory. These files define your Magento installation and describe its dependencies. Configuration files specify, for |
| 27 | +example, that Magento uses MySQL, some PHP extensions, and Elasticsearch. (These are referred to as *services*.) |
| 28 | + |
| 29 | +## Five phases of deployment {#cloud-deploy-over-phases} |
| 30 | +Deployment consists of the following phases: |
| 31 | + |
| 32 | +1. [Phase 1: Configuration validation and code retrieval](#cloud-deploy-over-phases-conf) |
| 33 | +2. [Phase 2: Build](#cloud-deploy-over-phases-build) |
| 34 | +3. [Phase 3: Prepare slug](#cloud-deploy-over-phases-slug) |
| 35 | +4. [Phase 4: Deploy slugs and cluster](#cloud-deploy-over-phases-slugclus) |
| 36 | +5. [Phase 5: Deployment hooks](#cloud-deploy-over-phases-hook) |
| 37 | +6. [Post-deployment: configure routing](#cloud-deploy-over-phases-route) |
| 38 | + |
| 39 | +### Phase 1: Configuration validation and code retrieval {#cloud-deploy-over-phases-conf} |
| 40 | +The remote server gets your code using Git. When you initially set up a project from a template, we retrieve the code from the [the Magento ECE template](https://github.com/magento/magento-cloud){:target="_blank"}. |
| 41 | + |
| 42 | +The built-in Git server checks what you are pushing: if you have a syntax error in a configuration file, our Git server refuses the push. |
| 43 | + |
| 44 | +Suppose you had a single MySQL database in your cluster and now you want two of those, or maybe you want to add an Elasticsearch instance. The built-in Git server detects this and verifies that the topology of your cluster is modified to your new needs. |
| 45 | + |
| 46 | +This phase also runs `composer install` to retrieve dependencies. |
| 47 | + |
| 48 | +### Phase 2: Build {#cloud-deploy-over-phases-build} |
| 49 | +We build only what has changed since the last build. This is one of the things that |
| 50 | +make Magento Enterprise Cloud Edition so fast in deployment. |
| 51 | + |
| 52 | +Magento Enterprise Cloud Edition builds the codebase. It runs hooks in the `build` section of `.magento.app.yaml`. |
| 53 | + |
| 54 | +The default Magento build hook is a CLI command called `magento-cloud:build`. It does the following: |
| 55 | + |
| 56 | +* Applies patches located in vendor/magento/magento-cloud-configuration/patches, as well as optional project-specific patches in m2-hotfixes |
| 57 | +* Enables all modules |
| 58 | +* Regenerates code and the dependency injection configuration (that is, the Magento `generated/code` and `generated/metadata` directories) using `bin/magento setup:di:compile`. |
| 59 | + |
| 60 | +It is important to note that at this point the cluster has not been |
| 61 | +created yet. So you should not try to connect to a database or imagine |
| 62 | +anything was daemonized. |
| 63 | + |
| 64 | +But also know that once the application has been built it is going to be |
| 65 | +mounted on a read-only file system (you will be able to configure specific |
| 66 | +mount points that are going to be read/write). |
| 67 | + |
| 68 | +This means you cannot FTP to the server and add modules. Instead, you must add code to your git repo and run `git push`, which builds and deploys the environment. |
| 69 | + |
| 70 | +### Phase 3: Prepare the slug {#cloud-deploy-over-phases-slug} |
| 71 | +The result of the build phase is a read-only file system we refer to as a *slug*. In this phase, we create an archive and put it in permanent storage. The next time |
| 72 | +you push code, if a service did not change, you can use a slug from the archive. |
| 73 | + |
| 74 | +It also means that reverting a deployment is basically |
| 75 | +instantaneous. |
| 76 | + |
| 77 | +### Phase 4: Deploy slugs and cluster {#cloud-deploy-over-phases-slugclus} |
| 78 | +Now we provision your applications and all the backend services you |
| 79 | +need: |
| 80 | + |
| 81 | +* Mounts each service in its own container |
| 82 | +* Mounts the read-write file system is mounted on a highly available distributed storage grid |
| 83 | +* Configures the network so Magento's services can "see" each other (and only each other) |
| 84 | + |
| 85 | +<div class="bs-callout bs-callout-info" id="info"> |
| 86 | + <p>The main file system is <em>read-only</em>. This |
| 87 | +is what guarantees we can do deterministic deployments. The read-only file system also dramatically improves your site's security because no process can write to the file system.</p> |
| 88 | +</div> |
| 89 | + |
| 90 | +### Phase 5: Deployment hooks {#cloud-deploy-over-phases-hook} |
| 91 | +The last step runs a deployment script. You can use this for example to anonymize data in development environments, clear caches, ping external continuous integration tools, and so on. |
| 92 | + |
| 93 | +When this script runs, you have access to all the services in your environment (Redis, database, and so on). |
| 94 | + |
| 95 | +There are two default deploy hooks. One is `pre-deploy.php`, which does some necessary cleanup and retrieval of |
| 96 | +resources that were generated in the build hook. The second is `bin/magento magento-cloud:deploy`, which does the following |
| 97 | + |
| 98 | +* If Magento is not installed, it installs Magento with `bin/magento setup:install`, updates the deployment configuration, `app/etc/env.php`, and the database for your specified environment (for example, Redis and website URLs). |
| 99 | + |
| 100 | +* If Magento is installed, performs any necessary upgrades. |
| 101 | + |
| 102 | + The deployment script runs [`bin/magento setup:upgrade`]({{ page.baseurl }}install-gde/install/cli/install-cli-subcommands-db-upgr.html) to update the database schema and data (which is necessary after extension or core code updates), and also updates the [deployment configuration]({{ page.baseurl }}config-guide/config/config-php.html), `app/etc/env.php`, and the database for your environment. |
| 103 | + |
| 104 | + Finally, the deployment script and clears the Magento cache. |
| 105 | + |
| 106 | +* Sets the mode to either [`developer`]({{ page.baseurl}}config-guide/bootstrap/magento-modes.html#mode-developer}}) or [`production`]({{ page.baseurl}}config-guide/bootstrap/magento-modes.html#mode-production) based on the environment variable [`APPLICATION_MODE`]({{ page.baseurl }}cloud/env/environment-vars_magento.html). |
| 107 | + |
| 108 | + In `production` mode, the script optionally generates static web content using the command |
| 109 | + [`magento setup:static-content:deploy`]({{ page.baseurl }}config-guide/cli/config-cli-subcommands-static-view.html). |
| 110 | + |
| 111 | +<div class="bs-callout bs-callout-info" id="info"> |
| 112 | + <p>Our deploy script uses the values defined by configuration files in the <code>.magento</code> directory, then the script deletes the directory and its contents. Your local development environment isn't affected.</p> |
| 113 | +</div> |
| 114 | + |
| 115 | +### Post-deployment: configure routing {#cloud-deploy-over-phases-route} |
| 116 | +While the deployment is running, we freeze the incoming traffic at the entry point |
| 117 | +for 60 seconds. We are now ready to configure routing so your |
| 118 | +web traffic will arrive at your newly created cluster. |
| 119 | + |
| 120 | +#### Related topics |
| 121 | +* [Get started with a project]({{page.baseurl}}cloud/project/project-start.html) |
| 122 | +* [Get started with an environment]({{page.baseurl}}cloud/env/environments-start.html) |
| 123 | +* [`.magento.app.yaml`]({{page.baseurl}}cloud/project/project-conf-files_magento-app.html) |
| 124 | +* [`routes.yaml`]({{page.baseurl}}cloud/project/project-conf-files_routes.html) |
| 125 | +* [`services.yaml`]({{page.baseurl}}cloud/project/project-conf-files_services.html) |
0 commit comments