Skip to content

Commit

Permalink
Merge pull request #19 from EmakinaFR/feature/composer
Browse files Browse the repository at this point in the history
Add the possibility to install the environment via Composer
  • Loading branch information
ajardin authored Oct 15, 2018
2 parents 7f9d64d + b54d5d8 commit 0e14f23
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
DOCKER_PHP_IMAGE=magento2_php_xdebug
DOCKER_MOUNT_POINT=..

##### BLACKFIRE
BLACKFIRE_PORT=8707
BLACKFIRE_LOG_LEVEL=4
Expand All @@ -14,6 +17,5 @@ MYSQL_PASSWORD=
MYSQL_DATABASE=

##### PHP
DOCKER_PHP_IMAGE=magento2_php_xdebug
PHP_IDE_CONFIG=serverName=
XDEBUG_CONFIG=remote_host= idekey=PHPSTORM remote_port=9001 remote_enable=1 remote_connect_back=0
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
PHP_SERVICE := docker-compose exec php sh -c

# Define a static project name that will be prepended to each service name
export COMPOSE_PROJECT_NAME := magento2

# This Makefile is designed to be extended by another Makefile located in your project directory.
# ==> https://github.com/EmakinaFR/docker-magento2/wiki/Makefile

# Create configuration files needed by the environment
SETUP_ENV := $(shell (test -f $(SELF_DIR).env || cp $(SELF_DIR).env.dist $(SELF_DIR).env))
SETUP_SERVER := $(shell (test -f $(SELF_DIR)nginx/servers/custom.conf || touch $(SELF_DIR)nginx/servers/custom.conf))

# Extract environment variables needed by the environment
export DOCKER_PHP_IMAGE := $(shell grep DOCKER_PHP_IMAGE $(SELF_DIR).env | awk -F '=' '{print $$NF}')
export DOCKER_MOUNT_POINT := $(shell grep DOCKER_MOUNT_POINT $(SELF_DIR).env | awk -F '=' '{print $$NF}')

##
## ----------------------------------------------------------------------------
Expand Down Expand Up @@ -48,11 +57,9 @@ restore: ## Restore the "mysql" volume
--volumes-from $$(docker-compose ps -q mysql) \
-v $$(pwd):/backup \
busybox sh -c "tar xvf /backup/backup.tar var/lib/mysql/"
@make restart
docker-compose restart mysql

start: ## Start the environment
-@test -f $(SELF_DIR).env || cp $(SELF_DIR).env.dist $(SELF_DIR).env
-@test -f $(SELF_DIR)nginx/servers/custom.conf || touch $(SELF_DIR)nginx/servers/custom.conf
docker-compose build
docker-compose up -d --remove-orphans

Expand Down
7 changes: 7 additions & 0 deletions Makefile.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Project specific variables
DOCKER_PATH := ./docker
PROJECT_PATH := /var/www/html

# Retrieve the Makefile used to manage the Docker environment
export COMPOSE_FILE := $(DOCKER_PATH)/docker-compose.yml
include $(DOCKER_PATH)/Makefile
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Docker for Magento2 [![Build Status](https://travis-ci.org/EmakinaFR/docker-magento2.svg?branch=master)](https://travis-ci.org/EmakinaFR/docker-magento2) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
This repository allows the creation of a Docker environment that meets
[Magento2](http://devdocs.magento.com/guides/v2.2/install-gde/system-requirements-tech.html) requirements.
[Magento 2](http://devdocs.magento.com/guides/v2.2/install-gde/system-requirements-tech.html) requirements.

## Architecture
![Architecture overview](docs/architecture.png "Architecture")
Expand Down
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "emakinafr/docker-magento2",
"description": "Docker environment that meets Magento 2 requirements",
"license": "MIT",
"authors": [
{
"name": "Alexandre Jardin",
"email": "aja@emakina.fr"
}
]
}
38 changes: 38 additions & 0 deletions composer_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euo pipefail

# Validate arguments passed to the script
if [[ $# -eq 1 && -n "$1" && -d "$1" ]]; then
script_path=$(cd $(dirname $0) && pwd)
project_path=$1
else
echo "Usage: bash composer_deploy.sh <project_path>"
exit 1
fi

# Copy only required files to the project directory
mkdir -p "$1"/docker
cp -r "${script_path}"/elasticsearch "$1"/docker/
cp -r "${script_path}"/nginx "$1"/docker/
cp -r "${script_path}"/php "$1"/docker/
cp "${script_path}"/.dockerignore "$1"/docker/
cp "${script_path}"/.env.dist "$1"/docker/
cp "${script_path}"/docker-compose.yml "$1"/docker/
cp "${script_path}"/Makefile "$1"/docker/

# Install the Makefile in the project directory
if [[ ! -f "$1"/Makefile ]]; then
cp "${script_path}"/Makefile.sample "$1"/Makefile

project_directory=$(basename $(cd $(dirname $1) && pwd))
perl -pi -e "s|^PROJECT_PATH := .*|PROJECT_PATH := /var/www/html/${project_directory}|g" "$1"/Makefile

echo -e "\e[32mA new Makefile has been installed in your project directory.\e[0m"
echo -e "\e[32mYou can type \"make\" to display the list of available commands.\e[0m"
else
echo -e "\e[33mYou already have a Makefile in your project directory.\e[0m"
echo -e "\e[33mTo take advantage of the Docker integration, add the snippet below at the top of your Makefile.\e[0m"

content=$(cat "${script_path}"/Makefile.sample)
echo -e "\n\e[3;33m${content}\e[0m"
fi
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
ports:
- 443:443
volumes:
- ~/www:/var/www/html:rw,delegated
- ${DOCKER_MOUNT_POINT}:/var/www/html:rw,delegated
# Custom configuration
- ./nginx/servers/magento.conf:/etc/nginx/conf.d/magento.conf:ro
- ./nginx/servers/custom.conf:/etc/nginx/conf.d/custom.conf:ro
Expand All @@ -48,7 +48,7 @@ services:
target: ${DOCKER_PHP_IMAGE}
env_file: .env
volumes:
- ~/www:/var/www/html:rw,delegated
- ${DOCKER_MOUNT_POINT}:/var/www/html:rw,delegated
# Custom configuration
- ./php/conf.d/custom.ini:/usr/local/etc/php/conf.d/custom.ini:ro
# SSH keys
Expand Down
Binary file modified docs/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion nginx/servers/magento.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ upstream fastcgi_backend {
# ssl_certificate /etc/nginx/ssl/server.crt;
# ssl_certificate_key /etc/nginx/ssl/server.key;
#
# set $MAGE_ROOT /var/www/html/magento;
# set $MAGE_ROOT /var/www/html;
# set $MAGE_MODE developer;
#
# include /etc/nginx/conf.d/magento.conf.sample;
Expand Down

0 comments on commit 0e14f23

Please sign in to comment.