Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/add support to open search #46

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/Console/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if(empty(getenv('M2_SAMPLE_DATA'))){
$output->writeln("Skip setup, M2_SAMPLE_DATA is not set");
return 0;
}

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);

Expand Down
18 changes: 16 additions & 2 deletions .docker/magento/m2-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ if [ ! -f /var/www/html/.post-install-complete ]; then
disable_modules="--disable-modules=$M2_DISABLE_MODULES"
fi

search_engine_arg_prefix="--elasticsearch-"
if [ "$M2_SEARCH_ENGINE" == 'opensearch' ]; then
search_engine_arg_prefix="--opensearch-"
fi
search_engine="--search-engine=$M2_SEARCH_ENGINE \
${search_engine_arg_prefix}host=$M2_SEARCH_ENGINE_HOST \
${search_engine_arg_prefix}port=$M2_SEARCH_ENGINE_PORT \
${search_engine_arg_prefix}enable-auth=0 \
${search_engine_arg_prefix}index-prefix=$M2_SEARCH_ENGINE_INDEX_PREFIX \
${search_engine_arg_prefix}timeout=$M2_SEARCH_ENGINE_TIMEOUT"

# Install Magento 2
su -s /bin/bash www-data -c "bin/magento setup:install \
--base-url=$M2_URL \
Expand All @@ -75,11 +86,14 @@ if [ ! -f /var/www/html/.post-install-complete ]; then
--elasticsearch-enable-auth=0 \
--elasticsearch-index-prefix=$M2_ELASTICSEARCH_INDEX_PREFIX \
--elasticsearch-timeout=$M2_ELASTICSEARCH_TIMEOUT \
$session_save $disable_modules" \
$session_save $search_engine $disable_modules" \
&& su -s /bin/bash www-data -c "composer config http-basic.repo.magento.com $M2_COMPOSER_REPO_KEY $M2_COMPOSER_REPO_SECRET" \
&& su -s /bin/bash www-data -c "bin/magento deploy:mode:set developer" \
&& su -s /bin/bash www-data -c "bin/magento sampledata:deploy && bin/magento setup:upgrade && bin/magento cache:flush" \
|| handle_failure

if [ -n "$M2_SAMPLE_DATA" ]; then
su -s /bin/bash www-data -c "bin/magento sampledata:deploy && bin/magento setup:upgrade && bin/magento cache:flush" || handle_failure
fi

# Set auto increment to current timestamp for Order Sequence tables
echo "ALTER TABLE sequence_order_0 AUTO_INCREMENT = $(date +%s);ALTER TABLE sequence_order_1 AUTO_INCREMENT = $(date +%s);" \
Expand Down
27 changes: 23 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ REDIS_TAG=7.2 # Compatible with Magento 2.4.7, 2.4.6, 2.4.5, 2.4.4
# The port to expose the Redis service
REDIS_PORT=6380

OPENSEARCH_TAG=2.12.0 # Use this version for Magento 2.4.7, 2.4.6-p5 - 2.4.6-p9
# OPENSEARCH_TAG=2.5.0 # Use this version for Magento 2.4.6 - 2.4.6-p4
# OPENSEARCH_TAG=1.3.20 # Use this version for Magento 2.4.5-p11
# OPENSEARCH_TAG=1.3.0 # Use this version for Magento 2.4.4-p8 - 2.4.4-p11, 2.4.5-p7 - 2.4.5-p10
# OPENSEARCH_TAG=1.2.0 # Use this version for Magento 2.4.3, 2.4.4 - 2.4.4-p7, 2.4.5 - 2.4.5-p6
OPENSEARCH_API_PORT=9201
OPENSEARCH_INTERNODE_PORT=9600

# The version of Elasticsearch to use. See available tags at https://hub.docker.com/_/elasticsearch/tags
# ELASTICSEARCH_TAG=8.11.4 # Use this version for Magento 2.4.7
ELASTICSEARCH_TAG=7.16.3 # Use this version for Magento 2.4.3, 2.4.4, 2.4.5, 2.4.6
Expand Down Expand Up @@ -55,6 +63,8 @@ M2_HTTP_PORT=8018
M2_HTTP_HOST=localhost.sequrapi.com
# The site URL
M2_URL=http://$M2_HTTP_HOST:$M2_HTTP_PORT
# Comment this line to disable sample data installation
M2_SAMPLE_DATA=1

M2_BACKEND_FRONTNAME="admin"
M2_ADMIN_USER="admin"
Expand All @@ -66,10 +76,19 @@ M2_LANGUAGE="es_ES"
M2_CURRENCY="EUR"
M2_TIMEZONE="Europe/Madrid"

M2_ELASTICSEARCH_HOST=elasticsearch
M2_ELASTICSEARCH_PORT=9200
M2_ELASTICSEARCH_INDEX_PREFIX=m2
M2_ELASTICSEARCH_TIMEOUT=60
# Uncomment the following lines to enable Elasticsearch
# M2_SEARCH_ENGINE=elasticsearch7
# M2_SEARCH_ENGINE_HOST=elasticsearch

# Uncomment the following lines to enable OpenSearch
M2_SEARCH_ENGINE=opensearch
M2_SEARCH_ENGINE_HOST=opensearch

COMPOSE_PROFILES=$M2_SEARCH_ENGINE_HOST

M2_SEARCH_ENGINE_PORT=9200
M2_SEARCH_ENGINE_INDEX_PREFIX=m2
M2_SEARCH_ENGINE_TIMEOUT=60

M2_DISABLE_MODULES="Magento_TwoFactorAuth"
# M2_DISABLE_MODULES="Magento_TwoFactorAuth,Magento_AdminAdobeIms,Magento_AdminAnalytics,Magento_AdobeIms,Magento_AdobeImsApi,Magento_AdobeStockAdminUi,Magento_AdobeStockClient,Magento_AdobeStockClientApi,Magento_AdobeStockImage,Magento_AdobeStockImageApi,Magento_AdobeStockImageAdminUi,Magento_Analytics,Magento_ApplicationPerformanceMonitor,Magento_ApplicationPerformanceMonitorNewRelic,Magento_Backup,Magento_CardinalCommerce,Magento_Captcha,Magento_Dhl,Magento_Fedex,Magento_GoogleAdwords,Magento_GoogleAnalytics,Magento_GoogleGtag,Magento_GoogleOptimizer,Magento_Paypal,Magento_PaypalCaptcha,Magento_PaypalGraphQl,Magento_PaymentServicesPaypal,Magento_PaymentServicesPaypalGraphQl,PayPal_Braintree,PayPal_BraintreeCustomerBalance,PayPal_BraintreeGiftCardAccount,PayPal_BraintreeGiftWrapping,PayPal_BraintreeGraphQl"
Expand Down
34 changes: 23 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ services:
depends_on:
mariadb:
condition: service_healthy
elasticsearch:
condition: service_healthy
redis:
condition: service_healthy
ports:
Expand All @@ -31,7 +29,7 @@ services:
volumes:
- m2_db:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
interval: 1s
timeout: 3s
retries: 10
Expand All @@ -43,7 +41,7 @@ services:
volumes:
- m2_redis:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
test: [ "CMD", "redis-cli", "ping" ]
interval: 1s
timeout: 3s
retries: 10
Expand All @@ -64,16 +62,30 @@ services:
memlock:
soft: -1
hard: -1
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:$ELASTICSEARCH_API_PORT"]
interval: 3s
timeout: 3s
retries: 15
volumes:
- m2_elasticsearch:/usr/share/elasticsearch/data

profiles:
- elasticsearch
opensearch:
image: opensearchproject/opensearch:$OPENSEARCH_TAG
ports:
- $OPENSEARCH_API_PORT:9200
- $OPENSEARCH_INTERNODE_PORT:9600
environment:
- discovery.type=single-node
- DISABLE_SECURITY_PLUGIN=true
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- m2_opensearch:/usr/share/opensearch/data
profiles:
- opensearch

volumes:
m2_db:
m2_redis:
m2_elasticsearch:
m2_html:
m2_opensearch:
m2_html:
5 changes: 5 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ if [ $ngrok -eq 1 ]; then
echo "✅ Ngrok started. Public URL: $M2_URL"
fi

# search_engine_profile="elasticsearch"
# if [ "$M2_SEARCH_ENGINE_HOST" == 'opensearch' ]; then
# search_engine_profile="opensearch"
# fi

docker compose up -d || exit 1

echo "🚀 Waiting for installation to complete..."
Expand Down
5 changes: 5 additions & 0 deletions teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ set -o allexport
source .env
set +o allexport

# search_engine_profile="elasticsearch"
# if [ "$M2_SEARCH_ENGINE_HOST" == 'opensearch' ]; then
# search_engine_profile="opensearch"
# fi

docker compose down --volumes --remove-orphans
docker rm -f $NGROK_CONTAINER_NAME || true
Loading