1 Star 0 Fork 0

eristin/magento2-kubernetes-devbox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
AFL-3.0

Magento 2 Kubernetes DevBox

Build Status

What You get

This project is under development and may become official Magento DevBox in the future. There is also a DevBox for Magento Cloud.

It's expected that the Magento 2 project source code will be located and managed on the host to allow quick indexing of project files by IDE. All other infrastructure is deployed in kubernetes cluster on Minikube.

Current DevBox aims to support multi-service multi-instance deployment in one click. Multiple Magento projects should be installed in a single Kubernetes cluster and share resoruces. Each of the Magento projects may be deployed as a monolith or a set of services. The DevBox is optimized for development scenarios using local environment.

The environment also suitable for for Magento Commerce and Magento B2B development.

The project initialization script configures a complete development environment:

  1. Configures all software necessary for Magento 2: Nginx, PHP 7.x, MySQL 5.6, Git, Composer, XDebug, Redis, Rabbit MQ, Varnish
  2. Installs Magento 2 from Git repositories or Composer packages (can be configured via checkout_source_from option in etc/instance/config.yaml)

How to install

If you never used Kubernetes before, read the Kubernetes Docs first.

Requirements

The software listed below should be available in PATH (except for PHP Storm).

  • Docker
  • Minikube
  • Helm
  • VirtualBox
  • Git - Ensure that SSH keys are generated and associated with your Github account. See how to check and how to configure, if not configured.
    To obtain the codebase without cloning, just use the Magento 2 codebase instead of devbox-magento/magento2ce. Either method will produce a successful installation.
  • PHP Storm, optional but recommended. To get Helm support in PhpStorm make sure to get v2018.3+
  • NFS server must be installed and running on *nix and OSX hosts; usually available, follow installation steps first

Installation steps

In case of any issues during installation, please read FAQ section

  1. Open terminal and change your directory to the one you want to contain Magento project.

  2. Download or clone the project with DevBox configuration:

    Do not open it in PhpStorm until init_project.sh has completed PhpStorm configuration in the initialize project step below.

    git clone --recursive git@github.com:magento/magento2-kubernetes-devbox.git magento2-devbox
    

    Optionally, if you use private repositories on GitHub or download packages from the Magento Marketplace using Composer.

    1. Copy etc/composer/auth.json.dist to etc/composer/auth.json.
    2. Specify your GitHub token by adding "github.com": "your-github-token" to the github-oauth section for GitHub authorization.
    3. Add the Magento Marketplace keys for Marketplace authorization to the repo.magento.com section.
    4. Copy (optional) etc/instance/config.yaml.dist as etc/instance/<instance_name>.yaml and make the necessary customizations. Instance name is Magento instance identifier that can only include letters and numbers.
    5. Copy (optional) etc/env/config.yaml.dist as etc/env/config.yaml and make the necessary customizations.
  3. Initialize the project (this will configure the environment, install Magento):

    cd magento2-devbox
    
    # NFS configuration is needed just once for each project, it will prompt for your password to make changes on the host
    
    bash scripts/host/configure_nfs_exports.sh
    
    bash init_project.sh
    
  4. Use the magento2-devbox directory as the project root in PHP Storm (not magento2-devbox/magento). This is important, because in this case PHP Storm will be configured automatically by init_project.sh.

  5. Configure the remote PHP interpreter in PHP Storm. Go to Preferences, then Languages and Frameworks. Click PHP and add a new remote interpreter. Select Deployment configuration as a source for connection details.

Default credentials and settings

Some of default settings are available for override. These settings can be found in the etc/instance/config.yaml.dist and etc/env/config.yaml.dist.

To override settings create a copy of etc/env/config.yaml.dist under the name 'config.yaml' and add your custom settings.

You can create multiple copies of etc/instance/config.yaml.dist, each of those copies will be responsible for a separate Magento instance deployed in the DevBox. Config file name must only include alpha-numeric characters and will be used to isolate instances (for instance domain name generation, DB name etc).

Upon a successful installation, you'll see the location and URL of the newly-installed Magento 2 application in console.

Web access:

  • Access storefront at http://magento.<instance_name> (can be found in etc/instance/<instance_name>.yaml)
  • Access admin panel at http://magento.<instance_name>/admin/
  • Magento admin user/password: admin/123123q
  • Rabbit MQ control panel: run bash k-open-rabbitmq, credentials admin/123123q

Your admin URL, storefront URL, and admin user and password are located in etc/instance/<instance_name>.yaml.

Codebase and DB access:

  • Path to your Magento installation in the container is the same as on the host
  • MySQL DB host:
    • inside the container: localhost
    • remotely: run minikube ip to get the IP and use port 30306
  • MySQL DB name: magento_<instance_name>, magento_<instance_name>_integration_tests
  • MySQL DB user/password: root:123123q

Codebase on host

  • CE codebase: magento2-devbox/<instance_name>
  • Magento Commerce codebase will be available if path to commerce repository is specified in etc/instance/<instance_name>.yaml: magento2-devbox/<instance_name>/magento2ee

Getting updates and fixes

Current devbox project follows semantic versioning so feel free to pull the latest features and fixes, they will not break your project. For example your current branch is 2.0, then it will be safe to pull any changes from origin/2.0. However branch 3.0 will contain changes backward incompatible with 2.0. Note, that semantic versioning is only used for x.0 branches (not for develop or master).

To apply changes run bash k-upgrade-environment.

Day-to-day development scenarios

Access Magento

Use the following command to open current instance:

./m-open

Hostname can also be found in magento/host_name section of etc/instance/<instance_name>.yaml.

Reinstall Magento

Use commands described in Switch between CE and EE section with -f flag. Before doing actual re-installation, these commands update linking of EE codebase, clear cache, update composer dependencies.

If no composer update and relinking of EE codebase is necessary, use the following command. It will clear Magento DB, Magento caches and reinstall Magento instance.

Go to the root of the project in command line and execute:

./m-reinstall

Clear Magento cache

Go to the root of the project in command line and execute:

./m-clear-cache

Switch between CE and EE

Assume, that EE codebase is available in magento2-devbox/magento/magento2ee. The following commands will link/unlink EE codebase, clear cache, update composer dependencies and reinstall Magento. Go to 'magento2-devbox' created earlier and run in command line:

./m-switch-to-ce
# OR
./m-switch-to-ee

Force switch can be done using -f flag even if already switched to the target edition. May be helpful to relink EE modules after switching between branches.

Upgrade can be performed instead of re-installation using -u flag.

Sample data installation

To install Magento with sample data using Git:

  1. Uncomment the sample data repository link at additional_repositories in etc/instance/<instance_name>.yaml. To ensure the yaml file can be correctly parsed, only remove the # and the space afterwards.
  2. Run ./m-switch-to-ce -f or ./m-switch-to-ee -f, depending on the edition to be installed. To disable sample data, comment out additional repositories and force-switch to necessary edition (using the same commands).

If sample data is not showing, try the following:

  1. Navigate to the magento2-devbox/<instance_name> directory such as magento2-devbox/default.
  2. Run git clone git@github.com:magento/magento2-sample-data.git or git@github.com:magento/magento2-sample-data-ee.git depending on the edition to be installed.
  3. Navigate back up to the magento2-devbox directory.
  4. Run ./m-switch-to-ce -f or ./m-switch-to-ee -f, depending on the edition to be installed.

To install Magento with sample data using Composer:

Follow the steps outlined here.

Basic data generation

Several entities are generated for testing purposes by default using REST API after Magento installation:

  • Customer with address (credentials customer@example.com:123123qQ)
  • Category
  • Couple simple products
  • Configurable product

To disable this feature, set magento/generate_basic_data in etc/instance/<instance_name>.yaml to 0 and run ./m-switch-to-ce -f or ./m-switch-to-ee -f, depending on the edition to be installed.

Use Magento CLI (bin/magento)

Go to 'magento2-devbox' created earlier and run in command line:

./m-bin-magento <command_name>
# e.g.
./m-bin-magento list

Debugging with XDebug

XDebug is already configured to connect to the host machine automatically. So just:

  1. Set XDEBUG_SESSION=1 cookie (e.g. using 'easy Xdebug' extension for Firefox). See XDebug documentation for more details
  2. Start listening for PHP Debug connections in PhpStorm on default 9000 port. See how to integrate XDebug with PhpStorm
  3. Set beakpoint or set option in PhpStorm menu 'Run -> Break at first line in PHP scripts'

Connecting to MySQL DB

Go to 'magento2-devbox' created earlier and run in command line:

bash k-ssh-mysql

After successful login to the container run the following command and enter 123123q when prompted for a password:

mysql -uroot -p

To connect remotely run minikube ip to get the IP and use port 30306

View emails sent by Magento

Not available yet.

Accessing PHP and other config files

The following configuration files are used by default:

Upgrading Magento

Sometimes it is necessary to test upgrade flow. This can be easily done as follows (assuming that you have installed instance):

  • For git-based installation - check out codebase corresponding to the target Magento version. Or modify your composer.json in case of composer-based installation
  • Use commands described in Switch between CE and EE section with -u flag

Multiple Magento instances

Not available yet.

Update Composer dependencies

Go to 'magento2-devbox' created earlier and run in command line:

./m-composer install
# OR
./m-composer update

Running Magento tests

See how to run Magento tests from PhpStorm using remote PHP in Kubernetes cluster

Environment configuration

Switch between PHP versions

Not available yet.

Activating Varnish

Use the following commands to enable/disable varnish : m-varnish disable or m-varnish enable.

You can also set use_varnish: 1 in etc/env/config.yaml to use varnish. Changes will be applied on init_project.sh -f.

The VCL content can be found in configmap.yaml.

Activating ElasticSearch

Set search_engine: "elasticsearch" in etc/env/config.yaml to use ElasticSearch as current search engine or search_engine: "mysql" to use MySQL. Changes will be applied on m-reinstall.

Use the following commands to switch between search engines without reinstalling Magento: m-search-engine elasticsearch or m-search-engine mysql.

Redis for caching

Redis is configured as cache backend by default.

Reset environment

It is possible to reset project environment to default state, which you usually get just after project initialization. The following command will re-initialize Kubernetes cluster. Magento 2 code base (magento directory) and etc/instance/<instance_name>.yaml and PhpStorm settings will stay untouched.

Go to 'magento2-devbox' created earlier and run in command line:

./init_project.sh -f

It is possible to reset Magento 2 code base at the same time. Magento 2 code base will be deleted and then cloned from the repositories specified in etc/config.yaml

./init_project.sh -fc

To reset PhpStorm project configuration, in addition to -f specify -p option:

./init_project.sh -fp

Ultimate project reset can be achieved by combining all available flags:

./init_project.sh -fcp

Switch NodeJS Versions

NodeJS not available yet.

DevBox tests

The tests are executed on every PR on Travis CI. It is possible to configure the same tests to run on the forked repository. In order to run composer-based Magento tests for the fork, repo.magento.com credentials must be set to COMPOSER_AUTH environment variable on Travis CI, the variable value should be:

'{"http-basic": {"repo.magento.com": {"username": "<public_key>","password": "<secret_key>"}}}'

An extended testsuite by default is executed against the master branch only. It is possible to execute an extended testsuite on every build by commenting out if: branch = master in the .travis.yaml

The same tests can be run on local using the following command. only one devbox can be running on the same host at the same time. The tests will destroy existing devbox installation.

cd tests
bash ./<test-name>.sh

FAQ

  1. To debug any CLI script in current Devbox project, set debug:devbox_project option in etc/env/config.yaml to 1
  2. Make sure that you used magento2-devbox directory as project root in PHP Storm (not magento2-devbox/magento)
  3. If project opened in PhpStorm looks broken, close PhpStorm and remove magento2-devbox/.idea. Run ./magento2-devbox/scripts/host/configure_php_storm.sh. After opening project in PhpStorm again everything should look good
  4. Please make sure that currently installed software, specified in requirements section, meets minimum version requirement
  5. Be careful if your OS is case-insensitive, NFS might break the symlinks if you cd into the wrong casing and you power the devbox up. Just be sure to cd in to the casing the directory was originally created as.
  6. Cannot run unit tests from PHPStorm on Magento 2.2, see possible solution here
  7. Permission denied (publickey)
  8. If you get minikube time out error restarting cluster while initializing project, run minikube stop && minikube delete && ./init_project.sh.
  9. To modify the docker image used for php-fpm container:
    • Make changes in etc/docker/monolith/Dockerfile
    • Run ./k-upgrade-environment
    • Run ./k-status to open kubernetes dashboard and delete Replica Set named magento2-monolith-*. The container should be restarted and its Age should reset
  10. If you face Input/output error command terminated with exit code 1 try to run the same command again, it will succeed after several trials.
  11. The project was working initially, but Magento instance domain name stopped resolving. In some cases minikube IP may be changed, run ./scripts/host/configure_etc_hosts.sh
Academic Free License ("AFL") v. 3.0 This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: Licensed under the Academic Free License version 3.0 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: 1. to reproduce the Original Work in copies, either alone or as part of a collective work; 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; 4. to perform the Original Work publicly; and 5. to display the Original Work publicly. 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.

简介

暂无描述 展开 收起
AFL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xkxuetang/magento2-kubernetes-devbox.git
git@gitee.com:xkxuetang/magento2-kubernetes-devbox.git
xkxuetang
magento2-kubernetes-devbox
magento2-kubernetes-devbox
master

搜索帮助