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

Commit

Permalink
Merge pull request #113 from fmarczew/hacktoberfest/update-version
Browse files Browse the repository at this point in the history
Update versions bin and env from upstream
  • Loading branch information
shochdoerfer committed Oct 15, 2021
2 parents 6d1a19b + bd14c10 commit f8d5ca9
Show file tree
Hide file tree
Showing 27 changed files with 405 additions and 134 deletions.
2 changes: 2 additions & 0 deletions bin/cache-clean
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli /var/www/.composer-global/vendor/bin/cache-clean.js "$@"
3 changes: 3 additions & 0 deletions bin/cliq
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
bin/clinotty "$@" >/dev/null
15 changes: 15 additions & 0 deletions bin/copyfromcontainer
@@ -0,0 +1,15 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a directory or file to copy from container (ex. vendor, --all)" && exit

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/./ "$REAL_SRC/"
echo "Completed copying all files from container to host"
else
if [ -f "$1" ] ; then
docker cp "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$1"
else
docker cp "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$(dirname "$1")"
fi
echo "Completed copying $1 from container to host"
fi
19 changes: 19 additions & 0 deletions bin/copytocontainer
@@ -0,0 +1,19 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a directory or file to copy to container (ex. vendor, --all)" && exit

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp "$REAL_SRC/./" "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/
echo "Completed copying all files from host to container"
bin/fixowns
bin/fixperms
else
if [ -f "$REAL_SRC/$1" ]; then
docker cp "$REAL_SRC/${1}" "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1"
else
docker cp "$REAL_SRC/${1}" "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$(dirname "$1")"
fi
echo "Completed copying $1 from host to container"
bin/fixowns "$1"
bin/fixperms "$1"
fi
7 changes: 7 additions & 0 deletions bin/dev-test-run
@@ -0,0 +1,7 @@
#!/bin/bash

[ -z "$1" ] && echo "Please specify test type (ex. integration)" && exit

TEST_TYPE="$1"
shift
bin/clinotty bash -c "cd dev/tests/${TEST_TYPE} && ../../../vendor/bin/phpunit -c phpunit.xml.dist $*"
7 changes: 7 additions & 0 deletions bin/devtools-cli-check
@@ -0,0 +1,7 @@
#!/bin/bash
if ! bin/clinotty ls /var/www/.composer-global/vendor/bin/cache-clean.js 1> /dev/null 2>&1; then
echo "Installing devtools metapackage, just a moment..."
bin/cliq mkdir -p /var/www/.composer-global
bin/composer require --working-dir=/var/www/.composer-global --quiet markshust/magento2-metapackage-devtools-cli:^1.0
echo "Devtools installed."
fi
34 changes: 8 additions & 26 deletions bin/download
@@ -1,31 +1,13 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify the version to download (ex. 2.0.0)" && exit
set -o errexit

edition=${2:-community}
VERSION=${1:-2.4.2}
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
bin/stop
docker-compose -f docker-compose.yml up -d
[ $? != 0 ] && echo "Failed to start Docker services" && exit

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
bin/setup-composer-auth

# 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
bin/clinotty composer create-project --repository=https://repo.magento.com/ magento/project-"${EDITION}"-edition="${VERSION}" .
6 changes: 3 additions & 3 deletions bin/fixowns
@@ -1,10 +1,10 @@
#!/bin/bash
echo "Correcting filesystem ownerships..."
echo "Fixing 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
bin/rootnotty chown -R app:app /var/www/html/"$1"
fi

echo "Filesystem ownerships corrected."
echo "Filesystem ownerships fixed."
4 changes: 2 additions & 2 deletions bin/fixperms
@@ -1,5 +1,5 @@
#!/bin/bash
echo "Correcting filesystem permissions..."
echo "Fixing 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 {} +;
Expand All @@ -8,4 +8,4 @@ else
bin/clinotty find "$1" \( -type f -or -type d \) -exec chmod u+w {} +;
fi

echo "Filesystem permissions corrected."
echo "Filesystem permissions fixed."
6 changes: 4 additions & 2 deletions bin/mysql
@@ -1,9 +1,11 @@
#!/bin/bash

# shellcheck source=../env/db.env
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} "$@"
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} "$@"
bin/clinotty mysql -h"${MYSQL_HOST}" -u"${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" "$@"
fi
7 changes: 7 additions & 0 deletions bin/n98-magerun2
@@ -0,0 +1,7 @@
#!/bin/bash
if ! bin/clinotty ls bin/n98-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/n98-magerun2.phar
bin/clinotty chmod +x bin/n98-magerun2.phar
fi
bin/cli bin/n98-magerun2.phar "$@"
2 changes: 2 additions & 0 deletions bin/pwa-studio
@@ -1,4 +1,6 @@
#!/bin/bash
set -o errexit

if [ ! -d pwa-studio ]; then
echo "PWA studio must first be installed by running bin/setup-pwa-studio"
exit
Expand Down
2 changes: 1 addition & 1 deletion bin/remove
@@ -1,2 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml rm --stop
docker-compose -f docker-compose.yml -f docker-compose.dev.yml rm
12 changes: 6 additions & 6 deletions bin/removevolumes
@@ -1,8 +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
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
115 changes: 65 additions & 50 deletions bin/setup
@@ -1,75 +1,90 @@
#!/bin/bash
BASE_URL=${1:-m2.localhost}
MAGE_VERSION=${2:-2.4.1}
set -o errexit

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

bin/restart
sleep 1 #Ensure containers are started...
BASE_URL=${1:-magento2.test}
ES_HOST=elasticsearch
ES_PORT=9200

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
bin/stop

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
docker-compose -f docker-compose.yml up -d
[ $? != 0 ] && echo "Failed to start Docker services" && exit

echo "Forcing reinstall of composer deps to ensure perms & reqs..."
bin/clinotty composer global require hirak/prestissimo
bin/clinotty composer update
bin/clinotty chmod u+x bin/magento
mv .vscode src

echo "Waiting for connection to Elasticsearch..."
bin/clinotty timeout 100 bash -c "
until curl --silent --output /dev/null http://$ES_HOST:$ES_PORT/_cat/health?h=st; do
printf '.'
sleep 2
done"
[ $? != 0 ] && echo "Failed to connect to Elasticsearch" && exit

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 \
--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="$MAGENTO_ADMIN_FRONTNAME" \
--admin-firstname="$MAGENTO_ADMIN_FIRST_NAME" \
--admin-lastname="$MAGENTO_ADMIN_LAST_NAME" \
--admin-email="$MAGENTO_ADMIN_EMAIL" \
--admin-user="$MAGENTO_ADMIN_USER" \
--admin-password="$MAGENTO_ADMIN_PASSWORD" \
--language="$MAGENTO_LOCALE" \
--currency="$MAGENTO_CURRENCY" \
--timezone="$MAGENTO_TIMEZONE" \
--amqp-host=rabbitmq \
--amqp-port=5672 \
--amqp-user=guest \
--amqp-password=guest \
--amqp-virtualhost=/ \
--cache-backend=redis \
--cache-backend-redis-server=redis \
--cache-backend-redis-db=0 \
--page-cache=redis \
--page-cache-redis-server=redis \
--page-cache-redis-db=1 \
--session-save=redis \
--session-save-redis-host=redis \
--session-save-redis-log-level=4 \
--session-save-redis-db=2 \
--search-engine=elasticsearch7 \
--elasticsearch-host=elasticsearch \
--elasticsearch-host=$ES_HOST \
--elasticsearch-port=$ES_PORT \
--use-rewrites=1

echo "Turning on developer mode.."
bin/clinotty bin/magento deploy:mode:set developer
bin/clinotty bin/magento indexer:reindex
echo "Copying files from container to host after install..."
bin/copyfromcontainer --all

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..."
echo "Clearing the cache to apply updates..."
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
bin/setup-ssl "$BASE_URL"

echo "Ensuring Composer auth.json is setup..."
bin/setup-composer-auth

echo "Installing cron (see docker-compose.yml to enable)..."
bin/magento cron:install

echo "Restarting containers with host bind mounts for dev..."
bin/restart
echo "Turning on developer mode.."
bin/clinotty bin/magento deploy:mode:set developer

echo "Docker development environment setup complete."
echo "You may now access your Magento instance at https://${BASE_URL}/"
31 changes: 31 additions & 0 deletions bin/setup-composer-auth
@@ -0,0 +1,31 @@
#!/bin/bash
MAGENTO_USERNAME_PROP="http-basic.repo.magento.com.username"
MAGENTO_PASSWORD_PROP="http-basic.repo.magento.com.password"
hash composer 2>/dev/null && IS_COMPOSER_ON_HOST=true

if [ $IS_COMPOSER_ON_HOST ]; then
PUBLIC_KEY="$(composer config --global $MAGENTO_USERNAME_PROP 2>/dev/null)"
PRIVATE_KEY="$(composer config --global $MAGENTO_PASSWORD_PROP 2>/dev/null)"
fi

if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
exec < /dev/tty
echo
echo "Composer authentication required (repo.magento.com public and private keys):"
read -r -p " Username: " PUBLIC_KEY
read -r -p " Password: " PRIVATE_KEY
echo
exec <&-
fi

if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
echo "Please setup Composer auth for repo.magento.com to continue." && exit 1
fi

# Output must be piped otherwise file descriptor errors occur. Carriage returns?
echo "composer config --global http-basic.repo.magento.com ${PUBLIC_KEY} ${PRIVATE_KEY}" | bin/clinotty bash -

# Also make sure alternate auth.json is setup (Magento uses this internally)
bin/clinotty cp /var/www/.composer/auth.json ./var/composer_home/auth.json

echo "Composer auth has been setup."
43 changes: 43 additions & 0 deletions bin/setup-grunt
@@ -0,0 +1,43 @@
#!/bin/bash
DEFAULT_THEME_ID="select value from core_config_data where path = 'design/theme/theme_id'"
THEME_PATH="select theme_path from theme where theme_id in ($DEFAULT_THEME_ID);"
VENDOR_THEME=$(bin/n98-magerun2 db:query "$THEME_PATH" | sed -n 2p | cut -d$'\r' -f1)
THEME=$(echo "$VENDOR_THEME" | cut -d'/' -f2)

# Generate local-theme.js for custom theme
read -r -d '' GEN_THEME_JS << EOM
var fs = require('fs');
var util = require('util');
var theme = require('./dev/tools/grunt/configs/themes');
theme['$THEME'] = {
area: 'frontend',
name: '$VENDOR_THEME',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l'
],
dsl: 'less'
};
fs.writeFileSync('./dev/tools/grunt/configs/local-themes.js', '"use strict"; module.exports = ' + util.inspect(theme), 'utf-8');
EOM

if [ -z "$VENDOR_THEME" ] || [ -z "$THEME" ]; then
echo "Using Magento/luma theme for grunt config"
THEME=luma
bin/clinotty cp ./dev/tools/grunt/configs/themes.js ./dev/tools/grunt/configs/local-themes.js
else
echo "Using $VENDOR_THEME theme for grunt config"
bin/node -e "$GEN_THEME_JS"
fi

bin/clinotty cp package.json.sample package.json
bin/clinotty cp Gruntfile.js.sample Gruntfile.js
bin/clinotty cp grunt-config.json.sample grunt-config.json
bin/npm install ajv@^5.0.0 --save
bin/npm install
bin/magento cache:clean
bin/grunt clean
bin/grunt exec:$THEME
bin/grunt less:$THEME

0 comments on commit f8d5ca9

Please sign in to comment.