Skip to content

Commit

Permalink
Merge pull request #24 from EmakinaFR/feature/composer
Browse files Browse the repository at this point in the history
Refactoring of the Composer installation
  • Loading branch information
ajardin authored Nov 22, 2018
2 parents 265abb9 + 71931bc commit f1ccd56
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 102 deletions.
32 changes: 21 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@ version: 2

jobs:
build:
docker:
- image: docker/compose:1.22.0
machine:
image: circleci/classic:201808-01
steps:
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Install required packages
command: 'apk add --no-cache git make openssh-client'
- checkout
name: Create a Magento Open Source project
command: |
ssh-keyscan github.com >> ~/.ssh/known_hosts
git clone git@github.com:magento/magento2.git ~/magento
- run:
name: Install the Composer dependencies
command: 'docker run --rm -it -v ~/magento:/app composer install --ignore-platform-reqs'
- run:
name: Install the Docker environment through Composer
command: 'docker run --rm -it -v ~/magento:/app composer require --dev emakinafr/docker-magento2:dev-${CIRCLE_BRANCH} --ignore-platform-reqs'
- run:
name: Execute the post-install process
command: 'docker run --rm -it -v ~/magento:/app composer exec docker-local-install -vvv'
- run:
name: Configure the environment variables
command: 'sudo cp ~/magento/docker/local/.env.dist ~/magento/docker/local/.env'
- run:
name: Start the environment
command: 'make start'
command: 'cd ~/magento && make start && make ps'
- run:
name: List all containers managed by the environment
command: 'make ps'

name: Try to access the setup page of Magento 2
command: 'curl --insecure --location --resolve "www.magento.localhost:443:127.0.0.1" https://www.magento.localhost/'
workflows:
version: 2
build:
Expand Down
1 change: 0 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
DOCKER_PHP_IMAGE=magento2_php_xdebug
DOCKER_MOUNT_POINT=..

##### BLACKFIRE
BLACKFIRE_PORT=8707
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/nginx/servers/*
!/nginx/servers/magento.conf
!/nginx/servers/magento.conf.sample
/.env
/vendor/
composer.lock
23 changes: 10 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
# This Makefile is designed to be included by another Makefile located in your project directory.
# ==> https://github.com/EmakinaFR/docker-magento2/wiki/Makefile

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}')
export PROJECT_LOCATION := $(shell echo ${MAKEFILE_DIRECTORY})
export DOCKER_PHP_IMAGE := $(shell grep DOCKER_PHP_IMAGE ${MAKEFILE_DIRECTORY}docker/local/.env | awk -F '=' '{print $$NF}')

##
## ----------------------------------------------------------------------------
Expand All @@ -35,7 +30,7 @@ cache: ## Flush cache stored in Redis
docker-compose exec redis sh -c "redis-cli -n 2 FLUSHDB"

composer: ## Install Composer dependencies from the "php" container
$(PHP_SERVICE) "composer install --optimize-autoloader --prefer-dist --working-dir=$(PROJECT_PATH)"
$(PHP_SERVICE) "composer install --optimize-autoloader --prefer-dist --working-dir=/var/www/html"

logs: ## Follow logs generated by all containers
docker-compose logs -f --tail=0
Expand All @@ -52,6 +47,8 @@ php: ## Open a terminal in the "php" container
ps: ## List all containers managed by the environment
docker-compose ps

restart: stop start ## Restart the environment

restore: ## Restore the "mysql" volume
docker run --rm \
--volumes-from $$(docker-compose ps -q mysql) \
Expand All @@ -70,9 +67,9 @@ stop: ## Stop the environment
docker-compose stop

yarn: ## Install Composer dependencies from the "php" container
$(PHP_SERVICE) "yarn install --cwd=$(PROJECT_PATH)"
$(PHP_SERVICE) "yarn install --cwd=/var/www/html"

.PHONY: backup build cache composer logs logs-full nginx php ps restore start stats stop yarn
.PHONY: backup build cache composer logs logs-full nginx php ps restart restore start stats stop yarn

.DEFAULT_GOAL := help
help:
Expand Down
7 changes: 3 additions & 4 deletions Makefile.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Project specific variables
DOCKER_PATH := ./docker
PROJECT_PATH := /var/www/html
DOCKER_PATH := ./vendor/emakinafr/docker-magento2
MAKEFILE_DIRECTORY := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Retrieve the Makefile used to manage the Docker environment
export COMPOSE_FILE := $(DOCKER_PATH)/docker-compose.yml
export COMPOSE_FILE := $(DOCKER_PATH)/docker-compose.yml
include $(DOCKER_PATH)/Makefile
33 changes: 33 additions & 0 deletions bin/docker-local-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php

require __DIR__ . '/../../../autoload.php';

use Symfony\Component\Filesystem\Filesystem;

const SOURCE_DIRECTORY = 'vendor/emakinafr/docker-magento2';
const TARGET_DIRECTORY = 'docker/local';

$filesystem = new Filesystem();

/**
* Create the Docker directory at the project root
*/
if ($filesystem->exists(TARGET_DIRECTORY) === false) {
$filesystem->mkdir(TARGET_DIRECTORY);
}

/**
* Define the default environment variables
*/
$filesystem->copy(SOURCE_DIRECTORY . '/.env.dist', TARGET_DIRECTORY . '/.env.dist');

/**
* Define the default Nginx configuration
*/
$filesystem->copy(SOURCE_DIRECTORY . '/nginx.conf.sample', TARGET_DIRECTORY . '/nginx.conf');

/**
* Copy the default Makefile at the project root
*/
$filesystem->copy(SOURCE_DIRECTORY . '/Makefile.sample', 'Makefile');
25 changes: 16 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"name": "emakinafr/docker-magento2",
"description": "Docker environment that meets Magento 2 requirements",
"license": "MIT",
"authors": [
{
"name": "Alexandre Jardin",
"email": "aja@emakina.fr"
}
]
"name": "emakinafr/docker-magento2",
"type": "library",
"description": "Docker environment that meets Magento 2 requirements",
"license": "MIT",
"authors": [
{
"name": "Alexandre Jardin",
"email": "aja@emakina.fr"
}
],
"require": {
"symfony/filesystem": "^3.0 || ^4.0"
},
"bin": [
"bin/docker-local-install"
]
}
31 changes: 0 additions & 31 deletions composer_deploy.sh

This file was deleted.

21 changes: 10 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ version: "3.4"
services:
blackfire:
image: blackfire/blackfire
env_file: .env
env_file: ${PROJECT_LOCATION}/docker/local/.env
depends_on:
- php

elasticsearch:
build: elasticsearch
env_file: .env
env_file: ${PROJECT_LOCATION}/docker/local/.env
volumes:
- elasticsearch:/usr/share/elasticsearch/data

maildev:
image: djfarrelly/maildev
env_file: .env
env_file: ${PROJECT_LOCATION}/docker/local/.env
depends_on:
- php
ports:
- 1080:80

mysql:
image: mysql:5.7
env_file: .env
env_file: ${PROJECT_LOCATION}/docker/local/.env
ports:
- 3306:3306
volumes:
Expand All @@ -32,23 +32,22 @@ services:

nginx:
build: nginx
env_file: .env
env_file: ${PROJECT_LOCATION}/docker/local/.env
ports:
- 443:443
volumes:
- ${DOCKER_MOUNT_POINT}:/var/www/html:rw,delegated
- ${PROJECT_LOCATION}:/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
- ${PROJECT_LOCATION}/docker/local/nginx.conf:/etc/nginx/conf.d/custom.conf:ro
tty: true

php:
build:
context: ./php
target: ${DOCKER_PHP_IMAGE}
env_file: .env
env_file: ${PROJECT_LOCATION}/docker/local/.env
volumes:
- ${DOCKER_MOUNT_POINT}:/var/www/html:rw,delegated
- ${PROJECT_LOCATION}:/var/www/html:rw,delegated
# Custom configuration
- ./php/conf.d/custom.ini:/usr/local/etc/php/conf.d/custom.ini:ro
# SSH keys
Expand All @@ -57,7 +56,7 @@ services:

redis:
image: redis:3.2-alpine
env_file: .env
env_file: ${PROJECT_LOCATION}/docker/local/.env
volumes:
- redis:/data
tty: true
Expand Down
18 changes: 18 additions & 0 deletions nginx.conf.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
upstream fastcgi_backend {
server php:9000;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name magento.localhost;

ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;

set $MAGE_ROOT /var/www/html;
set $MAGE_MODE developer;

include /etc/nginx/conf.d/magento.conf.sample;
}
18 changes: 0 additions & 18 deletions nginx/servers/magento.conf

This file was deleted.

0 comments on commit f1ccd56

Please sign in to comment.