Skip to content

Starter environment for Magento 2 demo and development using Docker and Docker Compose

Notifications You must be signed in to change notification settings

dnunez24/magento2ce-starter

Repository files navigation

Magento 2 Project Starter

Requirements

  • Docker for Mac (>= 1.12.x)
  • Docker Compose

Setup

git clone https://github.com/dnunez24/magento2-docker-starter.git my-project
cd my-project

Modify the .env file to provide environment variables to Docker Compose

Existing Database

To use an existing Magento 2 database, copy a MySQL dump file into the project directory and uncomment the SQL import line for the db service in the docker-compose.yml file.

cp $HOME/my-magento-data.sql.gz conf/data.sql.gz

Start the Services

# Start the Docker Compose environment
docker-compose up -d

Install Magento

If you didn't already use existing data in the last step...

# Installs without enterprise args by default
bin/install

Install Sample Data (optional)

bin/magento sampledata:deploy
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento indexer:reindex
bin/magento cache:flush

Develop

Add your theme, module or language pack to src directory.

mkdir src/module-my-feature

Add your local module directory as a Composer repository with the path type.

composer config repositories.my-feature path ./src/module-my-feature

Add a composer.json file to your module directory.

touch src/module-my-feature/composer.json

Configure your component in the composer.json file you created. Its contents should look something like the following:

{
    "name": "my-vendor/module-my-feature",
    "description": "Some new feature",
    "type": "magento2-module",
    "version": "dev-master",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/magento-composer-installer": "*",
        "magento/framework": "100.1.*"
    },
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "MyVendor\\MyFeature\\": ""
        }
    }
}

Add your registration.php file for Composer autoloading.

touch src/module-my-feature/registration.php

Configure your module registration. It should look something like the following:

<?php

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'MyVendor_MyModule',
    __DIR__
);

Require your module through Composer.

composer require my-vendor/module-my-feature:dev-master

The project root level composer.json should then look something like the following:

"require": {
    "composer/composer": "@alpha",
    "magento/magento-composer-installer": "*",
    "magento/product-community-edition": "2.1.4",
    "my-vendor/module-my-feature": "dev-master"
},

Enable and set up your module in Magento.

bin/magento module:enable MyVendor_MyFeature
bin/magento setup:upgrade

Linting & Testing

Linting

You can manually run static analysis tools during development

phpcs

Or, better yet, configure your editor to support on-the-fly linting. Here are some resources for common editors:

Atom
Sublime Text
PHP Storm
Vim

Testing

TODO

Roadmap

  • Add HTTPS capability and docs
  • Configure Behat bootstraps for Magento 2 testing

About

Starter environment for Magento 2 demo and development using Docker and Docker Compose

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published