Skip to content

Commit

Permalink
Merge pull request #5 from pablobae/feature/detecting_system
Browse files Browse the repository at this point in the history
Feature/detecting system
  • Loading branch information
pablobae authored Mar 12, 2021
2 parents bc7db13 + 3eaecaa commit 2132a5c
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 29 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Version](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added

### Changed

### Removed

## [1.0.1] - 12-03-2021
### Added
* Changelog file

### Changed
* Fix OS detect on create-project script
* Update documentation

## [1.0] - 29-09-2020
* First working version
60 changes: 40 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Dockerized Magento 2 devel environment

Docker environment for Magento 2 projects development with **PHPFPM**, **Percona**, **Nginx** and **mailhog**.
Docker environment for Magento 2 projects development with **PHPFPM**, **Percona**, **Nginx** and **Mailhog**.

Features included:

## Motivation

This project aims to offer a quick and easy solution for preparing Magento local environments for developing.

## Features included:
* **one-command** installation
* Supported OS: **Mac**, **Windows WSL**, **Ubuntu** and **Debian**
* Magento 2 version configurable
* Multiproject: docker service names are created dinamically by project
* Multi-project: docker service names are created dynamically by project
* Xdebug ready
* Docker mounted pointds optimization
* Docker mounted points optimization


## Download
Expand All @@ -16,62 +22,76 @@ Clone this repo at your desired folder:

```git clone git@github.com:pablobae/dockerized-magento2-devel-environment.git .```


## Configuration
Credentials for the database server are stored at **conf** > **env** > **db.env**, and **Magento** credentials and others install parameters are stored at **conf** > **magento** > **setup_config**.

In both cases, you can change the values as you wish, but these changes will only be applied before running the installation command.


## Installation

The installation process is automatic and includes the composer Magento 2 project creation of, the generation and installation of SSL certificates, the creation of images for docker and other necessary steps to be able to run the environment.
The installation process is automatic and includes the composer Magento 2 project creation of, the generation and installation of SSL certificates, the creation of images for Docker and other necessary steps to be able to run the environment.


To run a default installation execute the following command:

```bash create-project --project=PROJECT_NAME --domain=LOCAL_URL --version=MAGENTO_2_VERSION```
```bash create-project.sh --project=PROJECT_NAME --domain=LOCAL_URL --version=MAGENTO_2_VERSION```


Example:

```bash create-project --project=myproject --domain=myproject.local --version=2.3.5-p2```
```bash create-project.sh --project=myproject --domain=myproject.local --version=2.3.6-p1```


### Composer Authentication

### Composer Composer Authentication
During the installation process, composer will request you to provide your **Magento public and private keys**: write the username and password values with your Magento public and private keys, respectively.
More info in [Magento official documentation][http://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html].

During the installation process, composer will request you to provide your Magento public and private keys: write the username and password values with your Magento public and private keys, respectively.
More info in http://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html).

### SSL generation and system import

The installation process includes generating a self-signed cert to be used with the domain and its CA cert. To avoid system security warning, the CA cert is imported to your System Keychain and you will be asked for your password to do this.
opytocontainer auth.json.


### Docker mounted points
* src/app : /var/www/html/app
* src/vendor : /var/www/html/vendor
* src/composer.json : /var/www/html/composer.json
* src/comopser.lock : /var/www/html/coposer.lock
```
src/app : /var/www/html/app
src/vendor : /var/www/html/vendor
src/composer.json : /var/www/html/composer.json
src/composer.lock : /var/www/html/composer.lock
```

You can add or remove them editing the **docker-composer.yml** file generated during the create-project.sh execution.
You can add or remove them editing the **docker-composer.yml** file generated during the **create-project.sh** execution.

### Quick commands included
You can find a large list of useful command on **bin** folder, including:
* **bin/bash**: open bash shell container
* **bin/cli**: to execute commands inside the container
* **bin/copyfromcontainer**: copy files from container to host (usefull to copy files/directories not mounted)
* **bin/copytocontainer**: copy files from host to container (usefull to copy files/directories not mounted)
* **bin/copyfromcontainer**: copy files from container to host (useful to copy files/directories not mounted)
* **bin/copytocontainer**: copy files from host to container (useful to copy files/directories not mounted)
* **bin/xdebug**: enable or disable xdebug. By default is disabled.
* **bin/composer**: to run composer commands inside the container
* **bin/magento**: to run magento 2 cli inside the container


## ChangeLog
[CHANGELOG.md](CHANGELOG.md)


### TODO
* Add ElasticSearch
* PHPSTORM integration
* PHP Mess detector & PHPCs
* Add ElasticSearch

## Developers

* [Pablo Baenas](https://github.com/pablobae)

##### INSPIRATION
Project inspired on https://github.com/markshust/docker-magento
Project inspired on https://github.com/markshust/docker-magento

Licence
-------
[GNU General Public License, version 3 (GPLv3)](http://opensource.org/licenses/gpl-3.0)
2 changes: 1 addition & 1 deletion bin/setup-ssl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BASE_URL=${1:-m2.test}

source ./conf/project.conf

# Generate certificate authority if not already setup
# Generate certificate authority if not it's already setup
if ! docker-compose exec -T -u root ${DOCKER_SERVICE_APP} cat /root/.local/share/mkcert/rootCA.pem | grep -q 'BEGIN CERTIFICATE'; then
bin/setup-ssl-ca
fi
Expand Down
25 changes: 23 additions & 2 deletions bin/setup-ssl-ca
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,26 @@ source ./conf/project.conf
docker-compose exec -T -u root ${DOCKER_SERVICE_APP} mkcert -install
docker cp $(docker-compose ps -q ${DOCKER_SERVICE_APP}|awk '{print $1}'):/root/.local/share/mkcert/rootCA.pem .
echo "System password requested to install certificate authority on host..."
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain rootCA.pem
rm rootCA.pem

case $OS in
$OS_WSL)
echo "Installing CA on windows is not supported from WSL"
echo "Run from Windows PowerShell: "
echo "certutil –addstore -enterprise –f \"CA\" WINDOWS_PROJECT_PATH/rootCA.pem"
echo "As alternative, you can import it through: MMC → Certificates (Local Computer) snap-in → Trusted Root Certificates → Import"
read -p "Press any key to continue ..."
;;
$OS_MAC)
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain rootCA.pem
rm rootCA.pem
;;
*)
echo "Installing CA on Linux"
sudo mkdir -p /usr/share/ca-certificates/extra
openssl x509 -in rootCA.pem -inform PEM -out rootCA.crt
sudo cp rootCA.pem /usr/share/ca-certificates/extra/rootCA.crt
sudo update-ca-certificates
read -p "Press any key to continue ..."
;;
esac

50 changes: 44 additions & 6 deletions create-project.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

OS_WSL="wsl"
OS_UBUNTU="ubuntu"
OS_DEBIAN="debian"
OS_MAC="mac"


for i in "$@"
do
case $i in
Expand Down Expand Up @@ -28,9 +34,32 @@ then
exit
fi

echo "Detecting OS..."
echo "OS_WSL=${OS_WSL}" > ./conf/project.conf
echo "OS_UBUNTU=${OS_UBUNTU}" >> ./conf/project.conf
echo "OS_DEBIAN=${OS_DEBIAN}" >> ./conf/project.conf
echo "OS_MAC=${OS_MAC}">> ./conf/project.conf

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DISTRO=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
if [[ ${DISTRO} == *"Ubuntu"* ]]; then
if uname -a | grep -q '^Linux.*icrosoft' ; then
echo "OS=${OS_WSL}" >> ./conf/project.conf
else
echo "OS=${OS_UBUNTU}" >> ./conf/project.conf
fi
elif [[ ${DISTRO} == *"Debian"* ]]; then
echo "OS=${OS_DEBIAN}" >> ./conf/project.conf
else
echo "Error: OS not detected"
read -p "Press any key to continue ..."
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "OS=${OS_MAC}" >> ./conf/project.conf
fi

echo "Saving project configuration..."
echo "PROJECT_NAME=${PROJECT_NAME}" > ./conf/project.conf
echo "PROJECT_NAME=${PROJECT_NAME}" >> ./conf/project.conf
echo "BASE_URL=${BASE_URL}" >> ./conf/project.conf
echo "VERSION=${VERSION}" >> ./conf/project.conf
echo "DOCKER_SERVICE_APP"=app_${PROJECT_NAME}_m2 >> ./conf/project.conf
Expand All @@ -40,14 +69,23 @@ echo "DOCKER_SERVICE_MAILHOG"=mailhog_${PROJECT_NAME}_m2 >> ./conf/project.conf

source ./conf/project.conf

echo "Script customizations by OS..."
case $OS in
$OS_WSL)
SED_FIRST_PARAMETER=
;;
*)
SED_FIRST_PARAMETER="''"
;;
esac

### UPDATE /etc/hosts
## UPDATE /etc/hosts
echo "Write your system password to add ${BASE_URL} entry to /etc/hosts..."
echo "127.0.0.1 ::1 ${BASE_URL}" | sudo tee -a /etc/hosts

echo "Configuring docker-compose project file..."
cp ./conf/base.docker-compose.yml ./docker-compose.yml
sed -i '' "s/PROJECTNAME/${PROJECT_NAME}/g" ./docker-compose.yml
sed -i $SED_FIRST_PARAMETER "s/PROJECTNAME/${PROJECT_NAME}/g" ./docker-compose.yml

echo "Starting docker services..."
docker-compose up -d
Expand Down Expand Up @@ -100,10 +138,10 @@ bin/setup-ssl ${BASE_URL}

echo "Configuring post install docker-compose file..."
docker-compose stop
sed -i '' "s/# - \.\/src/ - \.\/src/g" ./docker-compose.yml
sed -i '' "s/# - \.\/conf/ - \.\/conf/g" ./docker-compose.yml
sed -i $SED_FIRST_PARAMETER "s/# - \.\/src/ - \.\/src/g" ./docker-compose.yml
sed -i $SED_FIRST_PARAMETER "s/# - \.\/conf/ - \.\/conf/g" ./docker-compose.yml

docker-compose up -d

echo "Docker developent environment setup complete."
echo "Docker development environment setup complete."
echo "You may now access your Magento instance at https://${BASE_URL}/"

0 comments on commit 2132a5c

Please sign in to comment.