Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
Merge ef4f09d into ae210e9
Browse files Browse the repository at this point in the history
  • Loading branch information
shochdoerfer committed Jan 23, 2021
2 parents ae210e9 + ef4f09d commit 88804dc
Show file tree
Hide file tree
Showing 35 changed files with 399 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/bash
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bash
3 changes: 3 additions & 0 deletions bin/cli
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec phpfpm "$@"
3 changes: 3 additions & 0 deletions bin/clinotty
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -T phpfpm "$@"
2 changes: 2 additions & 0 deletions bin/composer
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli composer "$@"
6 changes: 6 additions & 0 deletions bin/dev-urn-catalog-generate
@@ -0,0 +1,6 @@
#!/bin/bash
bin/magento dev:urn-catalog:generate misc.xml
bin/copyfromcontainer misc.xml
mv src/misc.xml src/.idea/misc.xml

echo "URN's have been generated, you may now restart PHPStorm"
2 changes: 2 additions & 0 deletions bin/devconsole
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bin/n98-magerun2.phar dev:console
31 changes: 31 additions & 0 deletions bin/download
@@ -0,0 +1,31 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify the version to download (ex. 2.0.0)" && exit

edition=${2:-community}

if [[ "$edition" == "enterprise" ]]; then
rm -rf src
composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-enterprise-edition=$1 src
exit 0
fi

if [ ! -f ~/.docker-magento/magento2-$1.tar.gz ]; then
mkdir -p ~/.docker-magento
(cd ~/.docker-magento && curl -fOL http://pubfiles.nexcess.net/magento/ce-packages/magento2-$1.tar.gz)
fi

# Fallback download to hypernode if archive doesn't exist on Nexcess (smaller than 1MB)
if [ $(find ~/.docker-magento/magento2-$1.tar.gz -size -1M) ]; then
(cd ~/.docker-magento && curl -o magento2-$1.tar.gz -fOL https://www.magento.mirror.hypernode.com/releases/magento-$1.tar.gz)
fi

# Final fallback. If no archive exists, let's use Composer!
if [ ! -f ~/.docker-magento/magento2-$1.tar.gz ]; then
echo "Archive not found, or not yet available due to new version release."
echo "Attempting install with Composer..."
rm -rf src
composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-community-edition=$1 src
else
echo "Extracting magento2-$1.tar.gz to ./src"
mkdir -p src && tar xzf ~/.docker-magento/magento2-$1.tar.gz -o -C src
fi
10 changes: 10 additions & 0 deletions bin/fixowns
@@ -0,0 +1,10 @@
#!/bin/bash
echo "Correcting filesystem ownerships..."

if [ -z "$1" ]; then
bin/rootnotty chown -R app:app /var/www/
else
bin/rootnotty chown -R app:app /var/www/html/$1
fi

echo "Filesystem ownerships corrected."
11 changes: 11 additions & 0 deletions bin/fixperms
@@ -0,0 +1,11 @@
#!/bin/bash
echo "Correcting filesystem permissions..."

if [ -z "$1" ]; then
bin/clinotty find var vendor pub/static pub/media app/etc \( -type f -or -type d \) -exec chmod u+w {} +;
bin/clinotty chmod u+x bin/magento
else
bin/clinotty find "$1" \( -type f -or -type d \) -exec chmod u+w {} +;
fi

echo "Filesystem permissions corrected."
2 changes: 2 additions & 0 deletions bin/grunt
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli grunt "$@"
2 changes: 2 additions & 0 deletions bin/magento
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bin/magento "$@"
7 changes: 7 additions & 0 deletions bin/magerun2
@@ -0,0 +1,7 @@
#!/bin/bash
if ! bin/clinotty ls bin/magerun2.phar 1> /dev/null 2>&1; then
bin/clinotty mkdir -p bin
bin/clinotty curl https://files.magerun.net/n98-magerun2.phar -o bin/magerun2.phar
bin/clinotty chmod +x bin/magerun2.phar
fi
bin/cli bin/magerun2.phar "$@"
9 changes: 9 additions & 0 deletions bin/mysql
@@ -0,0 +1,9 @@
#!/bin/bash
source env/db.env
if [ -t 0 ]; then
# Need tty to run mysql shell
bin/cli mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
else
# Read from stdin, ex: bin/mysql < dbdump.sql
bin/clinotty mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
fi
2 changes: 2 additions & 0 deletions bin/mysqldump
@@ -0,0 +1,2 @@
#!/bin/bash
bin/n98-magerun2 db:dump --stdout "$@"
2 changes: 2 additions & 0 deletions bin/node
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli node "$@"
2 changes: 2 additions & 0 deletions bin/npm
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli npm "$@"
8 changes: 8 additions & 0 deletions bin/pwa-studio
@@ -0,0 +1,8 @@
#!/bin/bash
if [ ! -d pwa-studio ]; then
echo "PWA studio must first be installed by running bin/setup-pwa-studio"
exit
fi

cd pwa-studio
NODE_TLS_REJECT_UNAUTHORIZED=0 yarn run watch:all
2 changes: 2 additions & 0 deletions bin/redis
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose exec redis "$@"
2 changes: 2 additions & 0 deletions bin/remove
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml rm --stop
3 changes: 3 additions & 0 deletions bin/removeall
@@ -0,0 +1,3 @@
#!/bin/bash
bin/remove
bin/removevolumes
8 changes: 8 additions & 0 deletions bin/removevolumes
@@ -0,0 +1,8 @@
#!/bin/bash
current_folder=${PWD##*/}
volume_prefix=`echo $current_folder | awk '{print tolower($0)}' | sed 's/\.//g'`
docker volume rm ${volume_prefix}_appdata
docker volume rm ${volume_prefix}_dbdata
docker volume rm ${volume_prefix}_rabbitmqdata
docker volume rm ${volume_prefix}_sockdata
docker volume rm ${volume_prefix}_ssldata
3 changes: 3 additions & 0 deletions bin/restart
@@ -0,0 +1,3 @@
#!/bin/bash
bin/stop "$@"
bin/start "$@"
3 changes: 3 additions & 0 deletions bin/root
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -u root phpfpm "$@"
3 changes: 3 additions & 0 deletions bin/rootnotty
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -u root -T phpfpm "$@"
75 changes: 75 additions & 0 deletions bin/setup
@@ -0,0 +1,75 @@
#!/bin/bash
BASE_URL=${1:-m2.localhost}
MAGE_VERSION=${2:-2.4.1}

# load the DB env information
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
source "$DIR/../env/db.env"

bin/restart
sleep 1 #Ensure containers are started...

echo "Downloading Magento ${MAGE_VERSION} with Sample data..."
bin/root curl -o /var/www/html/magento.tar.gz https://pubfiles.nexcess.net/magento/ce-packages/magento2-with-samples-${MAGE_VERSION}.tar.gz
bin/rootnotty tar xvfz /var/www/html/magento.tar.gz
bin/rootnotty rm /var/www/html/magento.tar.gz
bin/rootnotty cp /var/www/html/nginx.conf.sample /var/www/html/nginx.conf
bin/rootnotty chown -R app.app /var/www/html
bin/rootnotty chmod +x bin/magento

echo "Downloading magerun..."
bin/root curl -o /var/www/html/bin/magerun2.phar https://files.magerun.net/n98-magerun2-latest.phar
bin/rootnotty chmod +x /var/www/html/bin/magerun2.phar

echo "Forcing reinstall of composer deps to ensure perms & reqs..."
bin/clinotty composer global require hirak/prestissimo
bin/clinotty composer update

bin/clinotty bin/magento setup:install \
--db-host=$MYSQL_HOST \
--db-name=$MYSQL_DATABASE \
--db-user=$MYSQL_USER \
--db-password=$MYSQL_PASSWORD \
--base-url=https://$BASE_URL/ \
--base-url-secure=https://$BASE_URL/ \
--backend-frontname=admin \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@test.loc \
--admin-user=magento \
--admin-password=magento2\
--language=en_US \
--currency=EUR \
--timezone=Europe/Berlin \
--search-engine=elasticsearch7 \
--elasticsearch-host=elasticsearch \
--use-rewrites=1

echo "Turning on developer mode.."
bin/clinotty bin/magento deploy:mode:set developer
bin/clinotty bin/magento indexer:reindex

echo "Forcing deploy of static content to speed up initial requests..."
bin/clinotty bin/magento setup:static-content:deploy -f

echo "Re-indexing with Elasticsearch..."
bin/clinotty bin/magento indexer:reindex

echo "Disable Magento 2FAuth module..."
bin/clinotty bin/magento module:disable Magento_TwoFactorAuth

echo "Clearing the cache for good measure..."
bin/clinotty bin/magento cache:flush

echo "Installing Sample data..."
bin/clinotty bin/magento sampledata:deploy

echo "Generating SSL certificate..."
bin/setup-ssl $BASE_URL

echo "Restarting containers with host bind mounts for dev..."
bin/restart

echo "Docker development environment setup complete."
echo "You may now access your Magento instance at https://${BASE_URL}/"
17 changes: 17 additions & 0 deletions bin/setup-ssl
@@ -0,0 +1,17 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a domain (ex. mydomain.test)" && exit

# Generate certificate authority if not already setup
if ! docker-compose exec -T -u root app cat /root/.local/share/mkcert/rootCA.pem | grep -q 'BEGIN CERTIFICATE'; then
bin/setup-ssl-ca
fi

# Generate the certificate for the specified domain
docker-compose exec -T -u root app mkcert -key-file nginx.key -cert-file nginx.crt "$@"
echo "Moving key and cert to /etc/nginx/certs/..."
docker-compose exec -T -u root app chown app:app nginx.key nginx.crt
docker-compose exec -T -u root app mv nginx.key nginx.crt /etc/nginx/certs/

# Restart nginx to apply the updates
echo "Restarting containers to apply updates..."
bin/restart
15 changes: 15 additions & 0 deletions bin/setup-ssl-ca
@@ -0,0 +1,15 @@
#!/bin/bash

# Generate a new local CA "/root/.local/share/mkcert"
docker-compose exec -T -u root app mkcert -install

docker cp $(docker-compose ps -q app|awk '{print $1}'):/root/.local/share/mkcert/rootCA.pem .
echo "System password requested to install certificate authority on host..."

if [ "$(uname)" == "Darwin" ]; then
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain rootCA.pem
rm rootCA.pem
else
sudo mv rootCA.pem /usr/local/share/ca-certificates/rootCA.pem
sudo update-ca-certificates
fi
57 changes: 57 additions & 0 deletions bin/start
@@ -0,0 +1,57 @@
#!/bin/bash

## The following lines are commented oout per https://github.com/markshust/docker-magento/issues/351

<< 'COMMENTING-OUT'
function parseYaml {
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|,$s\]$s\$|]|" \
-e ":1;s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s,$s\(.*\)$s\]|\1\2: [\3]\n\1 - \4|;t1" \
-e "s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s\]|\1\2:\n\1 - \3|;p" $1 | \
sed -ne "s|,$s}$s\$|}|" \
-e ":1;s|^\($s\)-$s{$s\(.*\)$s,$s\($w\)$s:$s\(.*\)$s}|\1- {\2}\n\1 \3: \4|;t1" \
-e "s|^\($s\)-$s{$s\(.*\)$s}|\1-\n\1 \2|;p" | \
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)-$s[\"']\(.*\)[\"']$s\$|\1$fs$fs\2|p" \
-e "s|^\($s\)-$s\(.*\)$s\$|\1$fs$fs\2|p" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" | \
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]; idx[i]=0}}
if (length($2) == 0) {vname[indent] = ++idx[indent] };
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn = (vn)(vname[i])("_")}
if ("'$2'_" == vn) {
print substr($3 ,1 , match($3,":")-1)
}
}
}'
}
# Check if volume files exist to avoid creating an empty folder
VOLUME_LIST=`parseYaml docker-compose.dev.yml services_app_volumes`
IGNORE_LIST="./src/app/code ./src/m2-hotfixes ./src/patches ./src/var/log ./src/var/report ./src"
IS_VALID=true
# Loop through all files missing from the docker-compose.dev.yml file
for file in $VOLUME_LIST; do
if [ ! -e $file ] && [[ ! " $IGNORE_LIST " =~ " $file " ]]; then
echo "$file: No such file or directory"
IS_VALID=false
fi
done
# Wait to exit until all missing files have been outputted to the user
[ $IS_VALID = false ] && echo "Failed to start docker for missing volume files" && exit
COMMENTING-OUT

docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --remove-orphans "$@"

## Blackfire support
# ------------------
## First register the blackfire agent with:
#bin/root blackfire-agent --register --server-id={YOUR_SERVER_ID} --server-token={YOUR_SERVER_TOKEN}
## Then uncomment the below line (and leave uncommented) to start the agent automatically with bin/start:
#bin/root /etc/init.d/blackfire-agent start
2 changes: 2 additions & 0 deletions bin/status
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml ps
2 changes: 2 additions & 0 deletions bin/stop
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml stop "$@"
8 changes: 8 additions & 0 deletions bin/update
@@ -0,0 +1,8 @@
#!/bin/bash
mkdir -p tmpupdate && cd $_
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
rm -rf .git
rsync -av ./ ../
cd ..
rm -rf tmpupdate
echo "docker-magento has been updated, run bin/restart to apply the updates"
14 changes: 14 additions & 0 deletions bin/xdebug
@@ -0,0 +1,14 @@
#!/bin/bash
if [ "$1" == "disable" ]; then
bin/cli sed -i -e 's/^zend_extension/\;zend_extension/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sleep 1
bin/restart phpfpm
echo "Xdebug has been disabled."
elif [ "$1" == "enable" ]; then
bin/cli sed -i -e 's/^\;zend_extension/zend_extension/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sleep 1
bin/restart phpfpm
echo "Xdebug has been enabled."
else
echo "Please specify either 'enable' or 'disable' as an argument"
fi
22 changes: 22 additions & 0 deletions docker-compose.dev.yml
@@ -0,0 +1,22 @@
# Mark Shust's Docker Configuration for Magento
# (https://github.com/markshust/docker-magento)
#
# Version 34.2.0

version: "3"

services:
app:
volumes: &appvolumes
- ~/.composer:/var/www/.composer
- ~/.composer/auth.json:/var/www/html/auth.json
- ./:/var/www/.n98-magerun2/modules/magerun2-password-normalizer/:cached

phpfpm:
volumes: *appvolumes

mailhog:
image: mailhog/mailhog
ports:
- "1025"
- "8025:8025"

0 comments on commit 88804dc

Please sign in to comment.