├── README.md ├── docker-compose.yml ├── m2ssh ├── m2ssh.bat ├── m2unison.bat └── m2unison.sh /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | This repository is part of the Magento DevBox project. The goal of this 4 | project is to minimize the effort to set up a local development machine 5 | (e.g. a laptop) for development of Magento 2 projects. 6 | 7 | This project uses Docker, a containerization technology similar to Virtual 8 | Machines. This allows developers to work on multiple projects concurrently, 9 | which may need different versions of tools, without the pain of having to 10 | install all those versions natively. 11 | 12 | The environment is designed for development of Magento 2 projects - the 13 | environment provided is not for production usage. 14 | 15 | Please note, a previous version of DevBox included a web site with GUI to 16 | preconfigure your installation. While useful to get going, developers still 17 | needed to understand the underlying commands. The new DevBox has less 'magic', 18 | resulting in these instructions being longer, but developers having more 19 | control. 20 | 21 | ## General Operation 22 | 23 | DevBox contains all the the software packages you need to develop a Magento 24 | site, except for IDEs and web browsers. A local development environment 25 | typically starts with a database container (holding MySQL) and a web server 26 | container (holding the Magento source code). On Mac and Windows, another 27 | container is used for file sharing (discussed below). Other containers can be 28 | added as required for Varnish (recommended), Redis, RabbitMQ, and 29 | ElasticSearch. All containers run Linux inside. 30 | 31 | Developers mainly interact with the web container. The other containers are 32 | relatively shrink wrap. For example, some commands must be run by using ssh to 33 | log into the web container. 34 | 35 | Normally you set up containers and use them for a long time, removing them only 36 | when no longer required. Containers can be 'stopped' without being 'removed' to 37 | save CPU and memory resources while not in use. This is particularly useful 38 | when you are working on multiple projects. 39 | 40 | # Installation 41 | 42 | This section walks you through how to install DevBox. 43 | 44 | ## 0. Prerequisites 45 | 46 | * Install a recent version of Docker from http://docker.com/. Docker is 47 | available for Windows, Mac, and Linux. 48 | * On Windows 10, as part of the Docker installation process you may need to 49 | turn on Hyper-V and then grant Docker access to the `C:` drive for Docker to 50 | mount volumes correctly. This is described in the Docker documentation. 51 | * On Windows, it is recommended to install "Git Bash" 52 | (https://git-for-windows.github.io/). This includes the git client, an ssh 53 | client, an xterm terminal emulator, and a useful collection of commonly used 54 | Linux commands. The following instructions assume you are using Git Bash. 55 | * On Mac, install "Brew" (https://brew.sh/) if you have not done so already. 56 | 57 | ## 1. Create a Local Project Directory 58 | 59 | Create a new directory per project. Use a short but meaningful directory name 60 | as it is also used as a prefix for DevBox containers. 61 | 62 | Download an initial set of files to the project directory. 63 | 64 | * Go to http://github.com/alankent/magento2devbox-skeleton 65 | * In the "Branch" drop down, select the tag closest to the project's version 66 | of Magento. This is to get the correct version of PHP, MySQL, etc. 67 | **[Note: this is a work in progress. Currently only "master" is avaialble.]** 68 | * Click on the green button "Clone or Download" and select "Download ZIP". 69 | * Extract the ZIP file contents into the project directory. 70 | 71 | It is common to modify these downloaded files and delete unwanted files. For 72 | example, on Mac feel free to delete any Windows BAT files. 73 | 74 | ## 2. Review and Update the docker-compose.yml File 75 | 76 | The following steps set up the Docker configuration files before the containers 77 | can be started. 78 | 79 | Review the `docker-compose.yml` file in a text editor, making necessary 80 | adjustments as described by comments in the file. This includes: 81 | 82 | * Mac and Windows uses a utility called Unison to bi-directionally synchronize 83 | files between the Docker containers and the local file system. Unison is 84 | similar in concept to rsync, but more fully featured. To enable Unison, 85 | make sure the `/var/www` volume is uncommented and the 86 | `./shared/www:/var/www` line is commented out (or deleted). Make sure the 87 | "unison" service is also uncommented. 88 | 89 | * For Linux, direct file sharing can be used if preferred. Make sure the 90 | `./shared/www:/var/www` line is uncommented and the `/var/www` line is 91 | commented out. Also comment out the "unison" service as it is not required. 92 | Direct file sharing is not recommended for Mac or Windows for performance 93 | reasons. 94 | 95 | * Check the port numbers. By default Docker will allocate random free port 96 | numbers. Change ports such as "80" to "8080:80" if you want the web server 97 | port to be always 8080. You cannot run different containers at the same time 98 | using the same port numbers. On Mac, there is a default web server running on 99 | port 80 so you must use a different port number for the web server container. 100 | 101 | * The recommended way to create and update projects is via Composer, a PHP 102 | package manager. Magento provides a Composer repository from which Magento 103 | (and extensions purchased from Magento Marketplace) can be downloaded. 104 | Composer caches downloads for performance. Mounting the cache directory on 105 | your laptop is enabled by uncommenting the "~/.composer" volume mount in the 106 | `docker-compose.yml` file. This allows downloads to be shared between 107 | containers (e.g. on different projects). If you do not mount a directory, the 108 | cache will discarded when the container is removed. 109 | 110 | * Add your Magento Marketplace download access keys as web service environment 111 | variables if you want to share these keys easily with other developers on the 112 | same project. (You can share the `docker-compose.yml` to ensure a consistent 113 | setup between team members.) Otherwise Composer will prompt you for the keys 114 | later. Keys are available from https://marketplace.magento.com/. (Go to "My 115 | Profile", "My Purchases", "Access Keys".) 116 | 117 | * If you plan to use Varnish during development, uncomment the appropriate 118 | lines to create the Varnish container. A common source of production defects 119 | is the lack of testing with Varnish during development. As such, some 120 | developers prefer to develop with Varnishing caching turned on to spot 121 | problems early. 122 | 123 | * Similarly, if you plan to use Redis, ElasticSearch, or RabbitMQ in 124 | production, uncomment the appropriate lines so you can test during 125 | developement. 126 | 127 | ## 3. Launch the Containers 128 | 129 | Launch the containers by changing to the project directory and then running: 130 | 131 | docker-compose up -d 132 | 133 | You can check what containers exist using 134 | 135 | docker ps -a 136 | 137 | To log into the web container, use the provided `m2ssh` BAT and bash scripts. 138 | These automatically pick up the SSH port number from the `docker-compose.yml` 139 | file and logs on to the 'magento2' account of the 'web' container. 140 | 141 | ./m2ssh 142 | 143 | If you are running Docker in VirtualBox, you may need to edit the provided 144 | scripts to replace "localhost" with the IP address allocated by VirtualBox. 145 | 146 | Note: If you destroy and recreate containers, SSH may report warnings about 147 | changes in identity and refuse to connect. Use a text editor to remove 148 | "localhost" lines from your `~/.ssh/known_hosts` file to overcome this issue 149 | (you will then be prompted to accept new fingerprints on restart). 150 | 151 | ## 4. Start Unison (Mac, Windows) 152 | 153 | If you are using Unison for file syncing the host and web container file system 154 | (recommended on Mac and Windows), you also need to start up a Unison process 155 | (and keep it running). 156 | 157 | Each time you log to your laptop, make sure you restart Unison, but be careful 158 | to not have multiple copies running in parallel. It is not recommended to do 159 | significant work on the project without Unison running to avoid merge conflicts 160 | (rare). 161 | 162 | **Mac** 163 | 164 | On Mac, first install Unison using "brew". This installs the correct command 165 | line version of Unison. Also install "unox" for a companion file watching 166 | utility. 167 | 168 | brew install unison 169 | brew tap eugenmayer/dockersync 170 | brew install eugenmayer/dockersync/unox 171 | 172 | Use the provided shell script to start up Unison. This shell script creates 173 | a Unison "profile" file in `~/.unison/m2devbox-{myproj}.prf` ({myproj} 174 | is the current directory name) then starts up Unison in file watching mode. 175 | 176 | ./m2unison.sh 177 | 178 | It is recommended to run Unison in a separate Terminal window so you can refer 179 | to its output if you ever need to do troubleshooting. This is also useful when 180 | synchronizing a large number of files for the first time to know when the copy 181 | has completed. 182 | 183 | If you ever restart the Docker containers, you may need to rerun `m2unison.sh` 184 | to pick up any port number changes. 185 | 186 | **Windows** 187 | 188 | On Windows, run the supplied BAT file to launch Unison in a separate window 189 | using the START command or by double clicking the BAT file via Windows file 190 | explorer. This will automatically retrieve a copy of the `unison.exe` binary 191 | from the web container. A profile is not required as the BAT file uses command 192 | line arguments. Close the window to kill Unison. 193 | 194 | START m2unison.bat 195 | 196 | Note: The shell script (`m2unison.sh`) is not intended for use on Windows. 197 | 198 | ## 5. Install Magento 199 | 200 | Next you need to install your Magento project inside the web container under 201 | the `/var/www/magento2` directory. (Apache is configured by default to use 202 | `/var/www/magento2` as the document root.) There are multiple options here. 203 | 204 | Note: The first time you run Composer in the following steps, it may prompt you 205 | for a username and password. Enter your 'public' and 'private' keys from 206 | http://marketplace.magento.com/, "My Profile", "Access keys" when prompoted. Be 207 | aware that an `auth.json` file holding your keys will be saved into 208 | `~/.composer/`. If you want to share the Composer downloaded files but have a 209 | different `auth.json` file per project, move the `auth.json` file into your 210 | project's home directory (`/var/www/magento2`). Most people add the `auth.json` 211 | file to their `.gitignore` file to avoid accental sharing of the keys. 212 | 213 | **Option 1: Existing Project** 214 | 215 | If you have an existing set of project files, place them under the 216 | `shared/www/magento2` directory on your laptop. If you use volume mounting, the 217 | code will automatically be visible; if you use Unison, Unison will copy files 218 | on your laptop into the web container when it is running. Also please note if 219 | using Unison, symbolic links will not be copied into the container. 220 | 221 | **Option 2: Creating a New Project with Composer** 222 | 223 | Log into the web container. 224 | 225 | ./m2ssh 226 | 227 | Create a new project under `/var/www/magento2` using the Composer 228 | "create-project" command. Update the project edition and version number as 229 | appropriate. This example uses Magento Open Source (formerly "Community 230 | Edition") version 2.2.0. 231 | 232 | cd /var/www/magento2 233 | composer create-project --repository=https://repo.magento.com/ magento/project-community-edition:2.2.0 . 234 | chmod +x bin/magento 235 | 236 | **Option 3: Getting Code from a GitHub Project** 237 | 238 | It is strongly recommended to save your project code in a private git 239 | repository on a hosting provider such as GitHub or BitBucket. The following 240 | describes how a new environment can get the code from such an environment. 241 | 242 | The first step is to decide whether you plan to run normally git on your laptop 243 | or inside the container. Running it on the laptop is more frequent as many IDEs 244 | have integrated git support 245 | 246 | On your laptop, check out the project into the `magento2` directory. 247 | 248 | cd shared/www 249 | rm -rf magento2 250 | git clone https://github.com/mycompany/myproject.git magento2 251 | 252 | Log into the web container: 253 | 254 | ./m2ssh 255 | 256 | Use Composer to download all the additional needed packages. 257 | 258 | cd /var/www/magento2 259 | composer install 260 | 261 | Alternatively, you can check out the project from inside the container if you 262 | plan to run all your git commands there. 263 | 264 | cd /var/www 265 | rm -rf magento2 266 | git clone https://github.com/mycompany/myproject.git magento2 267 | cd magento2 268 | composer install 269 | 270 | **Option 4: Magento Commerce (Cloud)** 271 | 272 | TODO: WARNING: THIS SECTION IS NOT COMPLETE. 273 | 274 | The following discussion is not a replacement for reading through the Magento 275 | Commerce Cloud documentation on http://devdocs.magento.com/, but it summarizes 276 | the main steps most users would take. 277 | 278 | 1. Create your project using the Magento Cloud console. 279 | 2. Make sure you have SSH keys set up to access the account. (See 280 | `magento-cloud ssh-keys` and `magento-cloud ssh-key:add`.) The 281 | `magento-cloud` CLI is preinstalled in the web service container. 282 | 3. In the Magento Cloud console, click on "GIT" next to the "CLI" button to 283 | show the git command to check out the project's source code. 284 | 4. Remove the default `magento2` directory. 285 | 5. Check out the cloud git repo under the `magento2` directory. MAKE SURE YOU 286 | CHANGE THE LAST GIT ARGUMENT TO `magento2`. 287 | 6. Run `composer install` to download all other dependencies. 288 | 7. If you have any cloud patches you wish to use during development, run the 289 | `patch.php` file from the cloud configuration package. 290 | 291 | The following is a sample session 292 | 293 | cd /var/www 294 | rm -rf magento2 295 | git clone --branch master 12myproj34@git.us.magento.cloud:12myproj34.git magento2 296 | cd magento2 297 | xdebug-off 298 | composer install 299 | php vendor/magento/magento-cloud-configuration/patch.php 300 | chmod +x bin/magento 301 | 302 | Note that `magento-cloud get` is an alternative to the `git clone` command 303 | above, but it is recommended to use `git` directly to check the code out into 304 | the correct directory name (`/var/www/magento2`) as required by DevBox. 305 | 306 | **Option 5: Internal Development** 307 | 308 | TODO: THIS SECTION IS INDICATIVE OF FUTURE DIRECTION, NOT SUPPORTED YET. 309 | 310 | This section is only relevant to internal Magento developers, or external 311 | developers wishing to submit a pull request. The following is not recommended 312 | for production sites. (It may however be worth exploring by extension 313 | developers.) 314 | 315 | Log into the web container: 316 | 317 | ./m2ssh 318 | 319 | Make a local clone of Magento Open Source (formerly Community Edition). Use 320 | your own fork repository URL if appropriate. 321 | 322 | cd /var/www 323 | rm -rf magento2 324 | git clone https://github.com/magento/magento2skeleton.git magento2 325 | 326 | git clone https://github.com/magento/magento2ce.git 327 | git clone https://github.com/magento/magento2ee.git 328 | git clone https://github.com/magento/magento2b2b.git 329 | 330 | cd magento2 331 | composer config repositories.ce path "../magento2ce/app/*/*/*" 332 | composer config repositories.ee path "../magento2ee/app/*/*/*" 333 | composer config repositories.b2b path "../magento2b2b/app/*/*/*" 334 | 335 | composer install 336 | 337 | **Option 6: Recreating Docker Containers** 338 | 339 | If you decide to remove and re-create the Docker containers, the existing code 340 | will remain under `shared/www/magento2` on your laptop. These files will be 341 | automatically picked up when the new set of containers are launched. 342 | 343 | If using Unison, symbolic links are not copied. You may need to run 344 | `composer install` inside the web container to recreate any symbolic links 345 | required by Composer. 346 | 347 | ## 6. Create the Database 348 | 349 | Magento DevBox runs MySQL in a separate database container. The MySQL 350 | container by default does not have a database created for Magento to use. The 351 | following creates the database `magento2`. 352 | 353 | Log on to the bash prompt inside the web container 354 | 355 | ./m2ssh 356 | 357 | Run the following commands to create a MyQL database for the web site to use 358 | (plus a second database for integration tests to use). 359 | 360 | mysql -e 'CREATE DATABASE IF NOT EXISTS magento2;' 361 | mysql -e 'CREATE DATABASE IF NOT EXISTS magento_integration_tests;' 362 | 363 | After the database is created, uncomment the line setting the default 364 | database in the MySQL `~/.my.cnf` file. 365 | 366 | sed -e 's/#database/database/' -i ~/.my.cnf 367 | 368 | The `mysql` command can now be used without arguments or selecting database. 369 | 370 | mysql 371 | > SHOW TABLES; 372 | > exit; 373 | 374 | Set up all the Magento 2 tables with the following command (adjusting command 375 | line parameter values as desired). (See below for extra arguments if you wish 376 | to use RabbitMQ as well.) 377 | 378 | magento setup:install --db-host=db --db-name=magento2 --db-user=root --db-password=root --admin-firstname=Magento --admin-lastname=Administrator --admin-email=user@example.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --backend-frontname=admin 379 | 380 | It is recommended to NOT include the `--base_url` option during development as 381 | Docker can allocate a port number at random (including when container is 382 | restarted). It also causes problems using BrowserSync and similar tools for 383 | frontend development. Some versions of Magento however have a bug requiring 384 | `--base_url` to be specified. If the URL to CSS files is incorrect, you may 385 | have a broken version of Magento. If this is the case, force the web server 386 | port number be a specific port (e.g. use "8080:80" in `docker-composer.yml`) 387 | and add the `--base_url` command line option (e.g. `--base_url=localhost:8080`). 388 | 389 | TODO: I THINK YOU CAN RUN A SEPARATE COMMAND LATER. IF CORRECT, MOVE THIS TO A SEPARATE SECTION. 390 | If you are using RabbitMQ (AMPQ), the following command line arguments should 391 | be added when the project was created above. 392 | 393 | --amqp-virtualhost=/ --ampq-host=ampq --amqp-port=TODO --amqp-user=guest --amqp-password=guest 394 | 395 | ## 7. Loading Sample Data (Optional) 396 | 397 | To download the Luma sample data, you may need to provide Composer 398 | authentication details. If you already have a `~/.composer/auth.json` file you 399 | can run 400 | 401 | COMPOSER_AUTH=$(cat ~/.composer/auth.json) magento sampledata:deploy 402 | 403 | If you don't have a `~/.composer/auth.json` file, just run 404 | `magento sampledata:deploy` and enter your public and private keys when 405 | prompted. 406 | 407 | To load the downloaded sample data into the database, run 408 | 409 | magento setup:upgrade 410 | 411 | ## 8. Cron (Optional) 412 | 413 | Cron is disabled by default as running cron may result in faster draining of 414 | laptop batteries. To manually trigger background index updates, run `magento 415 | cron:run` twice in a row (sometimes the first cron schedules jobs for the 416 | second cron to run). 417 | 418 | cd /var/www/magento2 419 | magento cron:run 420 | magento cron:run 421 | 422 | To enable cron permanently (recommended) run the following command. 423 | 424 | cron-install 425 | 426 | ## 9. Put Site into Developer Mode 427 | 428 | Magento supports developer and production modes. Production mode makes 429 | optimizations assuming files on the site will not change. Developer mode is 430 | suitable when making changes to a site during development. 431 | 432 | magento deploy:mode:set developer 433 | 434 | ## 10. Connect with a Web Browser 435 | 436 | You are now ready to connect to your installation with a web browser. 437 | 438 | If you did not specify a fixed port number in the `docker-composer.yml` file 439 | for your site, run the following command to determine the web server port 440 | number that was allocated to the web service container. (This is normally 441 | different to the port number used inside the container.) 442 | 443 | docker-compose port web 80 444 | 445 | If the response is, for example, port 8080, connect to the web server store 446 | front using 447 | 448 | http://localhost:8080/ 449 | 450 | Connect to the Magento Admin by appending `/admin` with username "admin" and 451 | password "admin123" (from the earlier `magento setup:install` command) 452 | 453 | http://localhost:8080/admin 454 | 455 | If you are running Docker inside VirtualBox, replace "localhost" with the IP 456 | address VirtalBox allocated to the VM Docker is running within. 457 | 458 | Be aware that in developer mode the slower PHP debug mode is on and missing 459 | CSS and similar files are created on demand. This means the first time you 460 | load a page you will see significantly longer load times. The more pages you 461 | access, the faster the site will become. 462 | 463 | ## 11. Configure PHP Storm (Optional) 464 | 465 | TODO: WARNING: THIS SECTION IS NOT COMPLETE. 466 | 467 | PHP Storm is a popular IDE for PHP development. This section describes common 468 | PHP Storm configuration settings for Magento 2 projects. PHP Storm has changed 469 | (and will continue to change) over time, so the following instructions are 470 | indicative only. 471 | 472 | The following instructions assume the previous steps have already been 473 | completed. 474 | 475 | **Create New Project** 476 | 477 | 1. Create a new project in PHP Storm using "Create New Project from Existing 478 | Files". 479 | 2. Use the option "Source files are in local directory, no Web server is yet 480 | configured." (We will add the web server by hand later.) 481 | 3. Select `shared/www` as the project root directory. 482 | 4. Go to "File" / "Settings" to bring up the project's "Settings" diaglog box. 483 | 5. Select "Directories" in the Settings Diaglog side bar. 484 | Suggested settings are: 485 | * Mark the root directory as "Sources". 486 | * Mark `magento2/dev/tests` as "Tests". 487 | * Mark `magento2/dev/tests/integration/tmp` as "Excluded". 488 | * Mark `magento2/pub/static` as "Excluded". (This directory may not exist 489 | until you access the site, triggering its creation.) 490 | * Mark `magento2/var` as "Excluded". 491 | * Mark `magento2/vendor/magento/magento2-base` as "Excluded". 492 | 6. Select "Editor" / "File Encodings" in the Settings Diaglog side bar. 493 | * Set "Project Encoding" to "UTF-8". 494 | 7. Select "Languages & Frameworks" / "PHP" in the Settings Diaglog side bar. 495 | * Select "7" from the drop down list of PHP versions. 496 | * Click "..." next to "CLI Interpreter" to bring up a list of "CLI 497 | Interpreters". 498 | * Click "+" then "From Docker, Vagrant, VM, Remote". 499 | * Select "SSH Credentials". (You may try "Docker Composer" if you prefer, 500 | but it is more complicated to set up.) Use: 501 | - Enter `localhost` for the host name (or the IP address allocated by 502 | VirtualBox if running Docker inside VirtualBox). 503 | - Enter the port number from `docker-compose port web 22` (e.g. 2222) 504 | for the port number. 505 | - Enter `magento2` for the user name. 506 | - Select "Password" as the "Auth type". 507 | - Leave the password field blank. 508 | - Set the PHP executable path to `/usr/local/bin/php`. 509 | 8. Select "Tools" / "SSH Terminal", and select the "Default Remote 510 | Interpreter" radio button. 511 | 512 | ## 12. Varnish Configuration (Optional) 513 | 514 | TODO: WARNING: THIS SECTION IS NOT COMPLETE. 515 | 516 | Varnish is a "HTTP accelerator" that sits in front the web server and caches 517 | content of HTTP responses. It is recommended to use Varnish during development 518 | to help identify caching issues as early as possible. 519 | 520 | To enable Varnish, run the following command. This updates configuration 521 | settings in the database. 522 | 523 | varnish-install 524 | # magento config:set --scope=default --scope-code=0 system/full_page_cache/caching_application 2 525 | 526 | To connect via your web browser to Varnish, you must use the Varnish port 527 | number instead of the web server port number. To determine the Varnish port 528 | number, use 529 | 530 | docker-compose port varnish 6081 531 | 532 | ## 13. Redis Configuration (Optional) 533 | 534 | Uncomment the Redis service in the `docker-compose.yml` if you wish to use 535 | Redis during development, keeping your local development environment closer to 536 | your production setup. Redis is recommended if you have a cluster of web 537 | servers in production as an efficient way to share state (such as current 538 | session information) between them. 539 | 540 | The Magento DevDocs site (http://devdocs.magento.com/) describes how to 541 | configuration Redis. The following instructions summarize the steps for 542 | Magento 2.2 onwards. 543 | 544 | To turn on usage of Redis for session caching, run 545 | 546 | cd /var/www/magento2 547 | rm var/session/* 548 | magento setup:config:set --session-save=redis --session-save-redis-host=redis --session-save-redis-log-level=3 --session-save-redis-timeout=10 549 | 550 | To turn on usage of Redis for default data caching, run 551 | 552 | magento setup:config:set --cache-backend=redis --cache-backend-redis-server=redis --cache-backend-redis-db=1 553 | 554 | To turn on usage of Redis for page caching (not needed if using Varnish), run 555 | 556 | magento setup:config:set --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=2 557 | 558 | ## 14. ElasticSearch Configuration (Optional) 559 | 560 | TODO 561 | 562 | ## 15. RabbitMQ Configuration (Optional) 563 | 564 | TODO 565 | 566 | ## 16. Grunt and Gulp Configuration (Optional) 567 | 568 | Grunt and Gulp are both frontend tool chains to speed up frontend development. 569 | They can both auto-recompile CSS files as soon as a file is written to disk. 570 | NodeJS is preinstalled in the web service container for use by Grunt and Gulp, 571 | along with grunt-cli, gulp-cli, and browsersync. 572 | 573 | To enable Grunt support, run the following commands 574 | 575 | cd /var/www/magento2 576 | cp Gruntfile.js.sample Gruntfile.js 577 | cp package.json.sample package.json 578 | npm install 579 | grunt refresh --force 580 | grunt watch 581 | 582 | For further details, please refer to the Grunt section in the "Frontend 583 | Developer Guide" on http://devdocs.magento.com/. 584 | 585 | Magento does not ship with Gulp support, but there are numerous articles on the 586 | web explaining how to use Gulp with Magento 2, such as 587 | https://alankent.me/2016/01/27/gulp-et-al-in-magento-2/. 588 | 589 | If you wish to run BrowserSync (https://www.browsersync.io/), with Gulp you 590 | need to ensure the BrowserSync ports (3000 and 3001) are left uncommented in 591 | the `docker-compose.yml` file. 592 | 593 | # Appendix 1: Developing Your Own Module or Extension 594 | 595 | This section contains suggested ways in which you can manage modules or 596 | extensions that are being developed in a separate git repository to your main 597 | project. For example, a system integrator may wish to share a set of locally 598 | developed modules across multiple customers. 599 | 600 | ## Single Module Projects 601 | 602 | Composer has special support when there is one module per git repository. 603 | Composer can perform a git clone of the code automatically, where the code ends 604 | up under the `vendor` directory, like other downloaded modules, but you can 605 | edit and change the source code and commit your changes afterwards. 606 | 607 | In this mode, you create your module in git first, then run the following 608 | commands to update the composer.json file. 609 | 610 | First add a repository entry for the git repository, replacing "myvendor" and 611 | "mymodule" with your vendor and module name. 612 | 613 | composer config repositories.mymodule vcs git@github.com:myvendor/module-mymodule.git 614 | 615 | Next, add the dependency on your module. A version number with the form of 616 | "dev-{branch}" checks out that branch from the git repository. 617 | 618 | composer require --prefer-source myvendor/module-mymodule:dev-master 619 | 620 | Refer to the Composer documentation for more details and variations supported. 621 | 622 | ## Multi-Module Projects 623 | 624 | If you want to keep multiple modules in one git repo (so they version 625 | together), a different approach is required. Note this can also be used for git 626 | repositories containing a single module if desired. 627 | 628 | First, check out your git repository under `/var/www` (alongside the `magento2` 629 | directory). 630 | 631 | cd /var/www 632 | git clone git@github.com:myvendor/myrepo.git 633 | 634 | Next, add a repository reference to all the directories containing packages 635 | (that is, all directories containing a `composer.json` file). You may use `*` 636 | in path wildcards to include multiple directories at a time. Make sure you use 637 | quotes to make sure the shell does not expand the wildcards. (The wildcard will 638 | match directories such as modules in `app/code/Magento/*` and themes in 639 | `app/design/MyVendor/*`.) 640 | 641 | composer config repositories.myrepo path "../myrepo/app/*/*/*" 642 | 643 | If developing a module, set the minimum stability to `dev` (and set it back to 644 | a stable level when going live). See the Composer documentation for more 645 | options. 646 | 647 | composer config minimum-stability dev 648 | 649 | You can then add dependencies to any of the packages in the specified 650 | directories. Composer will create a symlink from under the `vendor/myvendor` 651 | directory to the appropriate git repository directory. 652 | 653 | composer require "myvendor/module-mymodule:*" 654 | 655 | Note that while Unison will not sync the symlink, if you specify the 656 | `shared/www` local directory as the "source code root" in PHP Storm, it will 657 | find the PHP code under both `/var/www/magento2` and `/var/www/myrepo`. 658 | 659 | # Appendix 2: Tips and Tricks 660 | 661 | The following can be useful tips and tricks. 662 | 663 | ## Other Docker Commands 664 | 665 | To see what containers are running, use 666 | 667 | docker ps -a 668 | 669 | To stop the containers when not in use, use 670 | 671 | docker-compose stop 672 | 673 | If you are using Unison, it is generally recommended to exit it as well. 674 | 675 | Restart the containers later with 676 | 677 | docker-compose start 678 | 679 | If you are using Unison, remember to also restart Unison for file syncing 680 | to work. 681 | 682 | To get a bash prompt inside a container, use 683 | 684 | docker-compose exec --user magento2 web bash 685 | 686 | If you are using a Git Bash window on Windows, you may see an error message 687 | saying you need to use `winpty`. In that case you must use the following 688 | command. 689 | 690 | winpty docker-compose exec --user magento2 web bash 691 | 692 | This example specified the 'web' service container (see `docker-compose.yml` 693 | for the other service names). 694 | 695 | In general this works well, but on Windows the 'exec' command will exit if you 696 | press CTRL+Z. If you like using CTRL+Z in Linux, this is rather annoying, so 697 | SSH access is recommended instead when logging into the web container. (SSH is 698 | not enabled on the other containers.) 699 | 700 | ## Removing and Rebuilding Containers 701 | 702 | When you no longer need the DevBox, you can kill and remove all of the running 703 | containers. THIS WILL WIPE ALL FILES INSIDE THE WEB CONTAINER AND THE DATABASE, 704 | LOSING ANY CHANGES FOREVER. It will not remove any locally synchronized files 705 | under the `shared` directory. 706 | 707 | docker-compose kill 708 | docker-compose rm 709 | 710 | If you decide to change the settings in `docker-composer.yml` after the 711 | containers have been created, you will need to rebuild the containers. 712 | MAKE SURE THE SOURCE CODE IS UP TO DATE UNDER THE `shared/www` DIRECTORY ON 713 | YOUR LAPTOP BEFORE REBUILDING THE CONTAINERS TO MAKE SURE YOU DO NOT 714 | ACCIDENTALLY LOSE ANY OF YOUR WORK. 715 | 716 | There are two strategies you can use. The first is to delete all the containers 717 | as above and then recreate them. This will delete the database contents as 718 | well. 719 | 720 | docker-compose kill 721 | docker-compose rm 722 | # Make changes to docker-compose.yml 723 | docker-compose up -d 724 | 725 | If you are using Unison file syncing, when you restart Unison locally it will 726 | copy all the code from `shared/www` back into the `/var/www` directory inside 727 | the container. After that, `magento setup:install` can be run to rebuild the 728 | database. 729 | 730 | The second approach is to use the `--build` option of Docker Compose which 731 | will only rebuild affected containers. For example, if opening up a new port 732 | to the web service container, using `--build` will not remove the database 733 | container, preserving its contents. When the `/var/www` directory is restored 734 | (via Unison or Volume mounting) the database connection settings (in `env.php`) 735 | will also be restored. 736 | 737 | # Make changes to docker-compose.yml 738 | docker-compose up -d --build 739 | 740 | Note: If using Unison for file syncing, you may need to rerun 741 | `composer install` on your installation to recreate some symbolic links. 742 | 743 | ## Kitematic 744 | 745 | If you like GUIs, you may wish to install Kitematic from the Docker site as 746 | well. It provides a GUI to manage Docker containers. Kitematic does not 747 | understand Docker Compose, only individual containers. 748 | 749 | You can use Docker command line commands in combination with Kitematic to 750 | manage containers, but sometimes Kitematic will not notice command line 751 | changes, requiring Kitematic to be exited and restarted to refresh the 752 | container list it is aware of. 753 | 754 | ## Other Magento Commands 755 | 756 | To flush various caches: 757 | 758 | magento cache:flush 759 | 760 | Tell any configured external caches (e.g. Redis) to clean themselves. 761 | 762 | magento cache:clean 763 | 764 | Run shell script to remove all generated files and clean all caches. 765 | 766 | clean-generated 767 | 768 | To run cron by hand if not running automatically (run this twice to gurantee 769 | all jobs are queued and run). 770 | 771 | magento cron:run 772 | 773 | To check module statuses 774 | 775 | magento module:status 776 | 777 | To disable/enable a module 778 | 779 | magento module:disable Magento_Customer 780 | magento module:enable Magento_Customer 781 | 782 | To rebuild indexes 783 | 784 | magento indexer:reindex 785 | 786 | 787 | # Appendix 3: File Syncing 788 | 789 | The biggest issue with using Docker or other virtualization technologies is 790 | most developers (rightly) prefer using an IDE or text editor running natively 791 | (on the laptop). The challenge then is how to get the editor to be able to 792 | access the Magento source code where that code is also available to the web 793 | container. 794 | 795 | Docker supports "volume mounting" which allows a Docker container to directly 796 | access the laptop file system. This works very well on Linux, but has 797 | performance issues on Mac and Windows when you have large numbers of files 798 | (such as with Magento). 799 | 800 | Where volume mounts are not suitable (specifically, the Magento source code 801 | directory on Mac and Windows), DevBox syncs the local and container file 802 | systems using a program called Unison. Whenever a file in the watched local 803 | file system is changed, it is copied into the web container, and vice versa. 804 | This allows IDEs to be natively used on a laptop (or desktop) - Unison copies 805 | file changes as soon as they are written to disk into the web conatiner. 806 | 807 | DevBox uses a similar approach to the "Docker Sync" project 808 | (http://docker-sync.io/) for file sharing, but only supports Unison. 809 | 810 | Insiders secret: Unison is written in a language called OCaml. OCaml 4.01 and 811 | 4.02 changed a serialization algorithm in a backwards incompatible way. So you 812 | need to make sure you have Unison binaries on Windows, Mac, and Linux compiled 813 | with the same version of OCaml. Brew + Debian:Stretch + the supplied Windows 814 | binary currently all match. If you try experimenting with other binaries, 815 | beware the pit of despair when things start going strange for no apparent 816 | reason! 817 | 818 | There are a number of implications from the above. 819 | 820 | * Most developers prefer to use a IDE such as PHP Storm for development. PHP 821 | Storm has special support for "remote PHP interpeters" via ssh. This makes 822 | source code development and debugging using PHP Storm relatively painless 823 | even when PHP and the web server are running inside a Docker container. 824 | However, PHP Storm still needs access to the the source code for editing and 825 | debugging, which is why Unison is required. 826 | 827 | * There are several directories (such as log directories) which you can choose 828 | to mount via Docker volumes for easy access directly from your laptop. These 829 | files are generally small in number and size for which Docker volume mounting 830 | works fine. By default the volume mounts are commented out in the 831 | `docker-compose.yml` file for improved performance. 832 | 833 | * Some frontend developer tools like Gulp and Grunt rely on file watching 834 | "iNotify" file system events. Docker Volume mounting on Windows does not 835 | support iNotify events at this time. 836 | 837 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | ## 2 | # Services needed to run Magento2 application on Docker 3 | # 4 | # Docker Compose defines required services and attach them together through aliases 5 | ## 6 | version: '2' 7 | services: 8 | web: 9 | restart: always 10 | image: alankent/magento2devbox-web:latest 11 | 12 | depends_on: 13 | - db 14 | #- rabbitmq 15 | #- elastic 16 | #- rabbitmq 17 | 18 | volumes: 19 | 20 | # Uncomment the first line for use with Unison and the "unison" 21 | # service below (Mac, Windows). Uncomment the second line instead 22 | # to mount the volume directly (Linux). Comment out both lines if 23 | # file sharing is not required. 24 | - "/var/www" 25 | #- "./shared/www:/var/www" 26 | 27 | # Uncomment to share your ~/.ssh directory with the container. 28 | # This can be useful for GitHub ssh keys and similar. 29 | #- "~/.ssh:/home/magento2/.ssh" 30 | 31 | # Uncomment this line if you want to share your composer 32 | # download cache between projects (more efficient, but 33 | # means the auth.json file will also be shared). 34 | #- "~/.composer:/home/magento2/.composer" 35 | 36 | # Uncomment to mount local directory for apache log files. 37 | #- "./shared/logs/apache2:/var/log/apache2" 38 | 39 | # Uncomment to mount local directory for FPM log files. 40 | #- "./shared/logs/php-fpm:/var/log/php-fpm" 41 | 42 | # Uncomment to share Magento cloud CLI settings between projects. 43 | #- "./shared/.magento-cloud:/home/magento2/.magento-cloud" 44 | 45 | environment: 46 | # Optional. If set, container will create a default auth.json 47 | # file for Composer to use (if one does not already exist). 48 | # (Download keys are a long hex sequence available from 49 | # http://marketplace.magento.com/, "My Profile", "My Access Keys") 50 | # Generally it is not recommended to commit keys to a git repo 51 | # for security reasons - it grants all viewers permission to download 52 | # all your Marketplace purchases. 53 | - MAGENTO_PUBLIC_KEY= 54 | - MAGENTO_PRIVATE_KEY= 55 | 56 | # The following exposes ports inside the container publicly. 57 | # Docker maps the public port numbers to ports inside the container 58 | # using Linux iptables support. If a single number is specified, 59 | # Docker will pick an unused port number at random every time the 60 | # container restarts. Use 8080:80 to bind the public port number 61 | # of 8080 to the internal port number of 80. (The internal port 62 | # number never changes - you may pick any external port number 63 | # to avoid collisions between different containers or projects.) 64 | ports: 65 | 66 | # Pick a random unused web server port. 67 | # (Use "8080:80" for force external port to be 8080.) 68 | - "80" 69 | 70 | # Use port 2222 for SSH (make sure unique across projects). 71 | # (If using the PHP Storm IDE, It is strongly recommended to pick a 72 | # dedicated port using the "2222:22" syntax so the port number does 73 | # not change each time the container is restarted, requiring PHP 74 | # Storm reconfiguration.) 75 | - "2222:22" 76 | 77 | # Expose the BrowserSync ports. 78 | # (Only needed if using BrowserSync for frontend development.) 79 | - "3000" 80 | - "3001" 81 | 82 | # This container contains the Unison process. 83 | # Comment out / remove this service if not using Unison (e.g. on Linux). 84 | unison: 85 | restart: always 86 | image: alankent/magento2devbox-unison:latest 87 | 88 | depends_on: 89 | - "web" 90 | 91 | # Mount the /var/www directory from the "web" container. 92 | volumes_from: 93 | - "web" 94 | 95 | ports: 96 | # Pick a random unused unison "socket" port. 97 | # This can be commented out if "ssh" access is used instead. 98 | - "5000" 99 | 100 | # Pick a random port for ssh based Unison connections (developers 101 | # normally do not log in to this container). 102 | # Use "2223:22" to lock the port number across container restarts. 103 | - "22" 104 | 105 | db: 106 | restart: always 107 | image: mysql:5.6 108 | 109 | ports: 110 | - "3306" 111 | 112 | environment: 113 | - MYSQL_ROOT_PASSWORD=root 114 | - MYSQL_DATABASE=magento2 115 | 116 | # Uncomment the following line if you uncomment a volume mount 117 | #volumes: 118 | 119 | # Uncomment to mount log files locally. 120 | #- "./shared/logs/mysql:/var/log/mysql" 121 | 122 | # Uncomment if you want the database to last after removing the 123 | # container. (Not recommended.) 124 | #- "./shared/db:/var/lib/mysql" 125 | 126 | # Uncomment the following to enable Varnish support. 127 | # (Make sure the service name indentation remains exactly aligned with 128 | # the previous service names) 129 | #varnish: 130 | # restart: always 131 | # depends_on: 132 | # - "web" 133 | # image: magento/magento2devbox-varnish:latest 134 | # ports: 135 | # - 6081 136 | 137 | # Uncomment the following lines to enable Redis support. 138 | # (Make sure the service name indentation remains exactly aligned with 139 | # the previous service names) 140 | #redis: 141 | # restart: always 142 | # image: redis:3.0.7 143 | 144 | # Uncomment the following to enable ElasticSearch support. 145 | # (Make sure the service name indentation remains exactly aligned with 146 | # the previous service names) 147 | #elastic: 148 | # restart: always 149 | # image: elasticsearch:2 150 | # ports: 151 | # - 9200 152 | 153 | # Uncomment the following to enable RabbitMQ support. 154 | # (Make sure the service name indentation remains exactly aligned with 155 | # the previous service names) 156 | #rabbitmq: 157 | # restart: always 158 | # image: rabbitmq:latest 159 | -------------------------------------------------------------------------------- /m2ssh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -f docker-compose.yml ]]; then 4 | echo "Warning: No `docker-compose.yml` file found." 5 | echo "Are you running this script from the correct directory?" 6 | exit 1 7 | fi 8 | 9 | SSH_HOST=$(docker-compose port web 22 | awk -F: '{ 10 | host = $1 11 | if (host == "") host = "localhost" 12 | if (host == "0.0.0.0") host = "localhost" 13 | print host 14 | }') 15 | 16 | SSH_PORT=$(docker-compose port web 22 | awk -F: '{print $2}') 17 | 18 | exec ssh -p ${SSH_PORT} magento2@${SSH_HOST} $* 19 | 20 | # The following version quietens more messages due to recreating containers 21 | exec ssh -o LogLevel=error -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${SSH_PORT} magento2@${SSH_HOST} $* 22 | -------------------------------------------------------------------------------- /m2ssh.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Fetch the external Docker SSH port number 4 | FOR /f "delims=" %%A IN ('docker-compose port web 22') DO SET "CMD_OUTPUT=%%A" 5 | FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "SSH_PORT=%%B" 6 | 7 | REM Run SSH 8 | ssh -p %SSH_PORT% magento2@localhost %* 9 | 10 | REM This version avoids problems when containers are destroyed and recreated 11 | REM ssh -o LogLevel=error -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p %SSH_PORT% magento2@localhost %* 12 | -------------------------------------------------------------------------------- /m2unison.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Set to '1' to use direct socket, '0' for SSH. 4 | REM Note: Some have reported occasional hangs using socket, SSH has been more 5 | REM reliable. 6 | SET USE_SOCKET=0 7 | 8 | IF "%USE_SOCKET" == "1" GOTO skipssh 9 | REM Fetch the external Docker SSH port number 10 | FOR /f "delims=" %%A IN ('docker-compose port unison 22') DO SET "CMD_OUTPUT=%%A" 11 | FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "SSH_PORT=%%B" 12 | REM Run SSH to allow user to accept the fingerprint on first connection. 13 | ssh -p %SSH_PORT% magento2@localhost echo SSH connection established 14 | :skipssh 15 | 16 | SET PROJ=%COMPOSE_PROJECT_NAME% 17 | IF [%PROJ%] == [] ( 18 | REM Get current directory name. 19 | FOR %%a IN (.) DO SET PROJ=%%~nxa 20 | ) 21 | 22 | IF NOT EXIST unison.exe ( 23 | REM **** Getting unison.exe binary from unison container. 24 | docker cp %PROJ%_unison_1:/windows/unison.exe . 25 | docker cp %PROJ%_unison_1:/windows/unison-fsmonitor.exe . 26 | ) 27 | 28 | REM Add Windows\system32 to start of path to find the right "timeout" command 29 | REM Cygwin can end up with 'unix like' timeout in path instead otherwise 30 | PATH C:\Windows\System32;%PATH% 31 | 32 | SET LOCAL_ROOT=./shared/www 33 | 34 | SET IGNORE= 35 | 36 | REM Magento files not worth pulling locally. 37 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/cache" 38 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/composer_home" 39 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/log" 40 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/page_cache" 41 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/session" 42 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/tmp" 43 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/.setup_cronjob_status" 44 | SET IGNORE=%IGNORE% -ignore "Path magento2/var/.update_cronjob_status" 45 | 46 | REM Other files not worth pushing to the container. 47 | SET IGNORE=%IGNORE% -ignore "Path magento2/.git" 48 | SET IGNORE=%IGNORE% -ignore "Path magento2/.gitignore" 49 | SET IGNORE=%IGNORE% -ignore "Path magento2/.gitattributes" 50 | SET IGNORE=%IGNORE% -ignore "Path magento2/.magento" 51 | SET IGNORE=%IGNORE% -ignore "Name {.idea}" 52 | SET IGNORE=%IGNORE% -ignore "Name {.*.swp}" 53 | SET IGNORE=%IGNORE% -ignore "Name {.unison.*}" 54 | 55 | IF "%USE_SOCKET%" == "1" GOTO usesock1 56 | REM Fetch the external Docker SSH port number 57 | FOR /f "delims=" %%A IN ('docker-compose port unison 22') DO SET "CMD_OUTPUT=%%A" 58 | FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "SSH_PORT=%%B" 59 | SET REMOTE_ROOT=ssh://magento2@localhost//var/www 60 | SET SSH_ARGS=-p %SSH_PORT% 61 | GOTO done1 62 | :usesock1 63 | REM Fetch the external Docker Unison port number 64 | FOR /f "delims=" %%A IN ('docker-compose port unison 5000') DO SET "CMD_OUTPUT=%%A" 65 | FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "UNISON_PORT=%%B" 66 | SET REMOTE_ROOT=socket://localhost:%UNISON_PORT%//var/www 67 | :done1 68 | 69 | SET UNISONARGS=%LOCAL_ROOT% %REMOTE_ROOT% -sshargs "%SSH_ARGS%" -prefer %LOCAL_ROOT% -preferpartial "Path var -> %REMOTE_ROOT%" -auto -batch %IGNORE% 70 | 71 | IF NOT EXIST %LOCAL_ROOT%/magento2/vendor ( 72 | @ECHO ON 73 | REM **** Pulling files from container (faster quiet mode) **** 74 | .\unison %UNISONARGS% -silent >NUL: 75 | @ECHO OFF 76 | ) 77 | 78 | @ECHO ON 79 | REM **** Entering file watch mode **** 80 | @ECHO OFF 81 | :loop_sync 82 | @ECHO ON 83 | .\unison %UNISONARGS% -repeat watch 84 | TIMEOUT 5 85 | @ECHO OFF 86 | 87 | REM Re-fetch the external Docker port number in case it changed. 88 | IF "%USE_SOCKET%" == "1" GOTO usesock2 89 | REM Fetch the external Docker SSH port number 90 | FOR /f "delims=" %%A IN ('docker-compose port unison 22') DO SET "CMD_OUTPUT=%%A" 91 | FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "SSH_PORT=%%B" 92 | SET REMOTE_ROOT=ssh://magento2@localhost//var/www 93 | SET SSH_ARGS=-p %SSH_PORT% 94 | GOTO done2 95 | :usesock2 96 | REM Fetch the external Docker Unison port number 97 | FOR /f "delims=" %%A IN ('docker-compose port unison 5000') DO SET "CMD_OUTPUT=%%A" 98 | FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "UNISON_PORT=%%B" 99 | SET REMOTE_ROOT=socket://localhost:%UNISON_PORT%//var/www 100 | :done2 101 | 102 | set UNISONARGS=%LOCAL_ROOT% %REMOTE_ROOT% -sshargs "%SSH_ARGS%" -prefer %LOCAL_ROOT% -preferpartial "Path var -> %REMOTE_ROOT%" -auto -batch %IGNORE% 103 | 104 | @ECHO ON 105 | REM **** Unison exited - Restarting file watch mode **** 106 | @ECHO OFF 107 | 108 | GOTO loop_sync 109 | 110 | PAUSE 111 | -------------------------------------------------------------------------------- /m2unison.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # Unison can connect over SSH or via a socket. SSH is used be default as there 5 | # have been some reports of the socket mode hanging at times. 6 | USE_SOCKET=0 7 | 8 | 9 | PROJ=$COMPOSE_PROJECT_NAME 10 | if [[ -z $PROJ ]]; then 11 | PROJ=$(basename $PWD) 12 | fi 13 | M2PROFILE=m2devbox-$PROJ 14 | 15 | mkdir -p ~/.unison 16 | 17 | LOCAL_ROOT=$(pwd)/shared/www 18 | if [[ $USE_SOCKET == 1 ]]; then 19 | # Fetch the external Docker Unison port number 20 | SSH_ARGS_LINE= 21 | UNISON_PORT=$(docker-compose port unison 5000 | awk -F: '{print $2}') 22 | REMOTE_ROOT=socket://localhost:$UNISON_PORT//var/www 23 | else 24 | SSH_PORT=$(docker-compose port unison 22 | awk -F: '{print $2}') 25 | echo "Testing 'ssh' connection to container..." 26 | ssh -p $SSH_PORT magento2@localhost echo Connection successful 27 | SSH_ARGS_LINE="sshargs = -p $SSH_PORT" 28 | REMOTE_ROOT=ssh://magento2@localhost//var/www 29 | fi 30 | 31 | cat << EOF > ~/.unison/$M2PROFILE.prf 32 | 33 | # WARNING: This file is automatically generated. Changes may be over-written. 34 | 35 | $SSH_ARGS_LINE 36 | 37 | # Local root 38 | root = $LOCAL_ROOT 39 | 40 | # Remote root (Docker container) 41 | root = $REMOTE_ROOT 42 | 43 | # Magento files not worth pulling locally. 44 | ignore = Path magento2/var/cache 45 | ignore = Path magento2/var/composer_home 46 | ignore = Path magento2/var/log 47 | ignore = Path magento2/var/page_cache 48 | ignore = Path magento2/var/session 49 | ignore = Path magento2/var/tmp 50 | ignore = Path magento2/var/.setup_cronjob_status 51 | ignore = Path magento2/var/.update_cronjob_status 52 | 53 | # Magento files not worth pushing remotely. 54 | ignore = Path magento2/.git 55 | ignore = Path magento2/.gitignore 56 | ignore = Path magento2/.gitattributes 57 | ignore = Path magento2/.magento 58 | ignore = Name .idea 59 | ignore = Name .*.swp 60 | ignore = Name .unison.* 61 | 62 | prefer = $LOCAL_ROOT 63 | preferpartial = Path var -> $REMOTE_ROOT 64 | auto = true 65 | batch = true 66 | 67 | EOF 68 | 69 | echo "Unison profile '$M2PROFILE' has been created in '~/.unison'." 70 | 71 | echo "Now running 'unison -repeat watch $M2PROFILE' for file syncing mode." 72 | unison -repeat watch $M2PROFILE 73 | --------------------------------------------------------------------------------