diff --git a/.circleci/config.yml b/.circleci/config.yml index 63bb786..e7c2476 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/.env.dist b/.env.dist index 0652826..b63d768 100644 --- a/.env.dist +++ b/.env.dist @@ -1,5 +1,4 @@ DOCKER_PHP_IMAGE=magento2_php_xdebug -DOCKER_MOUNT_POINT=.. ##### BLACKFIRE BLACKFIRE_PORT=8707 diff --git a/.gitignore b/.gitignore index f2f41a6..3a9875b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -/nginx/servers/* -!/nginx/servers/magento.conf -!/nginx/servers/magento.conf.sample -/.env +/vendor/ +composer.lock diff --git a/Makefile b/Makefile index 958d66f..2cc0d63 100644 --- a/Makefile +++ b/Makefile @@ -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}') ## ## ---------------------------------------------------------------------------- @@ -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 @@ -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) \ @@ -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: diff --git a/Makefile.sample b/Makefile.sample index f71dc1d..e81b58a 100644 --- a/Makefile.sample +++ b/Makefile.sample @@ -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 diff --git a/bin/docker-local-install b/bin/docker-local-install new file mode 100644 index 0000000..4553eba --- /dev/null +++ b/bin/docker-local-install @@ -0,0 +1,33 @@ +#!/usr/bin/env php +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'); diff --git a/composer.json b/composer.json index 1877624..53941ea 100644 --- a/composer.json +++ b/composer.json @@ -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" + ] } diff --git a/composer_deploy.sh b/composer_deploy.sh deleted file mode 100644 index 2f4a996..0000000 --- a/composer_deploy.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 " - exit 1 -fi - -# Copy environment files to the project directory -cp -r "${script_path}" "$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 diff --git a/docker-compose.yml b/docker-compose.yml index 7d970ff..f73824f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,19 +3,19 @@ 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: @@ -23,7 +23,7 @@ services: mysql: image: mysql:5.7 - env_file: .env + env_file: ${PROJECT_LOCATION}/docker/local/.env ports: - 3306:3306 volumes: @@ -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 @@ -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 diff --git a/nginx.conf.sample b/nginx.conf.sample new file mode 100644 index 0000000..4db265a --- /dev/null +++ b/nginx.conf.sample @@ -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; +} diff --git a/nginx/servers/magento.conf b/nginx/servers/magento.conf deleted file mode 100644 index 459142e..0000000 --- a/nginx/servers/magento.conf +++ /dev/null @@ -1,18 +0,0 @@ -upstream fastcgi_backend { - server php:9000; -} - -#server { -# listen 443 ssl http2; -# listen [::]:443 ssl http2; -# server_name magento.test; -# -# 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; -#}