Skip to content

Instantly share code, notes, and snippets.

@JeroenBoersma
Last active November 4, 2020 16:36
Show Gist options
  • Save JeroenBoersma/9ec255324b7aa12f2ab2766703d7eb8d to your computer and use it in GitHub Desktop.
Save JeroenBoersma/9ec255324b7aa12f2ab2766703d7eb8d to your computer and use it in GitHub Desktop.
Docker php development aditional scripts

Docker php development aditional scripts

For docker I've some local scripts which I occasionaly use for day-to-day jobs. The reason I don't commit them in the repository is because they're so project specific.

Setup

Magento

Next up, some Magento 2 scripts which I use to get back on track.

m2-db

  • todo: import database from aws

m2-clean

Clear all Magento 2 generated context and do a install composer packages

m2-init

Run setup scripts, deploy static content(this is a speed improvement for local development) Create a local user with a defined password.

m2-install

Do a clean install of Magento 2, set base url's, locales, generated xsd mapping and set in dev mode.

m2-sample

Link global auth.json and deploy sampledata.

m2-cron

Run the Magento cron every 60 seconds.

host machine scripts

watch -d -n 5 'du -hs generated/* var/*cache pub/static/*'

Watch files for changes over time, helped me a lot :)

cache-clean.js

Awesome Mage2tv cachecleaner. Put this one in your ~/bin/cache-clean.js

dev php /data/.applications/magento-cache-clean/bin/generate-cache-clean-config.php
dev node /data/.applications/magento-cache-clean/bin/cache-clean.js "$@"
#!/bin/bash
echo "---CLEANUP---"
rm -rf generated var/cache var/page_cache vendor pub/static/*;
mkdir pub/static generated;
echo "---COMPOSER----"
composer install --prefer-dist -o
#/bin/bash
echo "---MAGENTO----"
bin/magento set:up
bin/magento set:di:comp
bin/magento set:sta:dep -fa adminhtml en_US
bin/magento set:sta:dep -fa frontend en_US nl_NL -s compact
echo '---USER---';
magerun2 admin:user:create --admin-user=jeroen --admin-password='Test1234!' --admin-email=jeroen@elgentos.nl --admin-firstname=Jeroen --admin-lastname=Boersma
magerun2 admin:user:change-password jeroen 'Test1234!'
echo "---COMMANDS---"
echo "\$ watch -d -n 5 'du -hs generated/* var/*cache pub/static/*'"
echo "\$ cache-clean.js -w -v"
echo "\$ dev m2-cron"
#!/bin/bash
if [ ! -e "vendor/." ]; then
echo 'Make sure to run "'$0' m2-clean" first';
exit 2;
fi
if [ $# -lt 1 ]; then
echo $0 db-name [install-options];
exit 1;
fi
m2_user='jeroen'
m2_pass='Test1234!'
m2_first='Jeroen'
m2_last='Boersma'
m2_email='jeroen@elgentos.nl'
db=$1;
shift;
host=`echo ${PWD} | sed -e 's/\//./g' -e 's/.data./https:\/\//' -e 's/\.*$/.magento2.localhost\//' -e 's/\.magento2\.magento2/.magento2/'`;
echo "---MAGENTO----"
php bin/magento set:install --backend-frontname=admin \
--db-host=db --db-user=jeroen --db-password='' --db-name=${db} \
--admin-user="${m2_user}" --admin-password="${m2_pass}" \
--admin-firstname="${m2_first}" --admin-lastname="${m2_last}" \
--admin-email="${m2_email}" \
$@;
# default settings
php bin/magento conf:set -le web/unsecure/base_url $host;
php bin/magento conf:set -le web/secure/base_url $host;
php bin/magento conf:set -le web/secure/use_in_frontend 1;
php bin/magento conf:set -le general/locale/code en_US;
php bin/magento conf:set -le web/seo/use_rewrites 1;
php bin/magento conf:set -le web/url/use_store 1;
php bin/magento set:sta:dep -fa adminhtml en_US;
php bin/magento dev:urn-ca:gen .idea/misc.xml;
php bin/magento dep:mode:set developer;
#!/bin/bash
if [ ! -e "var/composer_home/." ]; then
mkdir -p var/composer_home;
ln -s /data/.composer/auth.json var/composer_home;
fi
php bin/magento sample:dep;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment