Skip to content
86 changes: 45 additions & 41 deletions bin/watch
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
import datetime
import os
import subprocess

from inotify.adapters import InotifyTree
import time
from pathlib import Path
from time import sleep


def build_docs():
Expand All @@ -15,54 +16,57 @@ def refresh_assets():
)


def watch_for_changes(debug=False):
i = InotifyTree("docs")
def watch_for_changes():
"""Watch for changes using watchdog."""
from watchdog.events import FileSystemEvent, FileSystemEventHandler
from watchdog.observers import Observer

class MyHandler(FileSystemEventHandler):
def __init__(self):
super().__init__()
self.last_build = time.time()

IGNORED_EVENTS = ["IN_CLOSE_WRITE", "IN_CLOSE_NOWRITE", "IN_ACCESS", "IN_OPEN"]
IGNORED_PATHS = ["docs/_build"]
def on_modified(self, event: FileSystemEvent):
cwd = os.getcwd()
file_path = Path(event.src_path)

last_build = None
IGNORED_PATHS = ["docs/_build"]

for event in i.event_gen(yield_nones=False):
(_, type_names, path, filename) = event
if event.is_directory:
return

ignore = False
for ignored_event_type in IGNORED_EVENTS:
if ignored_event_type in type_names:
ignore = True
break
if file_path.name.isdigit():
return

for ignored_path in IGNORED_PATHS:
if path.startswith(ignored_path):
ignore = True
break
if (
file_path.name.endswith(".swx")
or file_path.name.endswith(".swp")
or file_path.name.endswith("~")
):
return

if (
filename.endswith(".swx")
or filename.endswith(".swp")
or filename.endswith("~")
):
ignore = True
for ignored_path in IGNORED_PATHS:
ignored_path = os.path.join(cwd, ignored_path)
if str(file_path).startswith(ignored_path):
return

if ignore:
continue
if self.last_build and time.time() - self.last_build < 0.5:
return

if last_build:
# If build has been triggered in the last 50 ms, skip
delta = (datetime.datetime.now() - last_build).microseconds / 1000
if delta < 50:
continue
build_docs()
refresh_assets()
self.last_build = time.time()

build_docs()
refresh_assets()
last_build = datetime.datetime.now()
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path="docs", recursive=True)
observer.start()

if debug:
print(
"PATH=[{}] FILENAME=[{}] EVENT_TYPES={}".format(
path, filename, type_names
)
)
try:
while True:
sleep(1)
except KeyboardInterrupt:
observer.stop()


if __name__ == "__main__":
Expand Down
41 changes: 24 additions & 17 deletions docs/best-practices/database/how-to-run-rabbitmq-on-hypernode.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ You can run this command to restart RabbitMQ:
hypernode-servicectl restart rabbitmq-server
```

## Accessing RabbitMQ
## Accessing the RabbitMQ admin interface

- RabbitMQ only binds on localhost
- The default admin account is username `guest` and password `guest`. You can change and add users via the admin interface.
Expand All @@ -67,22 +67,29 @@ Use your browser to go to `localhost:55672` and logon using guest/guest.

Another way to access the admin interface is via [hypernode-vpn](https://changelog.hypernode.com/changelog/release-6064-rabbitmq-can-be-accessed-via-the-hypernode-vpn/)

## RabbitMQ and Magento

You need to make some changes in Magento in order to use RabbitMQ. For example in `/data/web/magento2/app/etc/env.php`:

```php
'queue' =>
array (
'amqp' =>
array (
'host' => 'rabbitmqmaster',
'port' => '5672',
'user' => 'guest',
'password' => 'guest',
'virtualhost' => '/',
),
),
## Creating RabbitMQ users

You can also create your own RabbitMQ users. This can be done by in the RabbitMQ admin interface, as follows:

1. Go to the RabbitMQ admin interface
1. Click on the `Admin` tab
1. Click on `Add a user`
1. Fill in the username and password
1. Click on `Add user`
1. Click on the user you just created
1. Click on `Set permission`

## RabbitMQ and Magento 2

To configure RabbitMQ in Magento 2, you can run the following command:

```bash
bin/magento setup:config:set \
--amqp-host="rabbitmqmaster" \
--amqp-port="5672" \
--amqp-user="guest" \
--amqp-password="guest" \
--amqp-virtualhost="/"
```

Note: Hypernode provisions a non-default user called `hypernode-admin` but you are free to create new users.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
myst:
html_meta:
description: Configure remote storage for Magento 2.x. Learn how to configure
Magento 2 to start storing files in your bucket using a single command.
title: How to Configure Remote Storage for Magento 2.x | Hypernode
---

# How to Configure Remote Storage for Magento 2.x

Magento 2.x supports remote storage for media files, import/export files, and other files.
This feature allows you to store files in a remote storage location, such as an Amazon S3 bucket, instead of storing them on the server itself.

This can be useful for many reasons, such as:

- Offloading storage from your server, reducing the load on your server, and improving performance.
- Allows you to make use of [horizontal scaling](../../hypernode-platform/autoscaling/how-does-horizontal-autoscaling-work), as you can easily add more servers without having to worry about syncing files between them.
- Allows for effortless storage capacity scaling, as you can easily increase the storage capacity of your remote storage location.
- Serving assets from a CDN, which can improve the performance of your website.

## Configuring the application

Configuring Magento 2 to start storing files in your bucket is done using a single command.

**AWS S3**

```bash
bin/magento setup:config:set \
--remote-storage-driver="aws-s3" \
--remote-storage-bucket="my_bucket_name" \
--remote-storage-region="my-aws-region" \
--remote-storage-key="abcd1234" \
--remote-storage-secret="abcd1234"
```

**Other S3 compatible providers**

If you're using a different provider than AWS S3, you need to specify the `--remote-storage-endpoint` option.

```bash
bin/magento setup:config:set \
--remote-storage-driver="aws-s3" \
--remote-storage-bucket="my_bucket_name" \
--remote-storage-region="provider-region" \
--remote-storage-key="abcd1234" \
--remote-storage-secret="abcd1234" \
--remote-storage-endpoint="https://my-s3-compatible.endpoint.com"
```

## Syncing the files

Instead of running (which is Magento's official way to do this):

```bash
bin/magento remote-storage:sync
```

One can run the following instead to really speed up the process:

```bash
aws s3 sync pub/media/ s3://my_bucket_name/media/
aws s3 sync var/import_export s3://my_bucket_name/import_export
```

This is much faster than Magento's built-in sync, because `aws s3 sync` uploads files concurrently.

## The storage flag file in the bucket

Magento's S3 implementation creates a test file called `storage.flag`, which is basically created to test if the connection works. So this is not a magic file to mark anything ([source](https://github.com/magento/magento2/blob/6f4805f82bb7511f72935daa493d48ebda3d9039/app/code/Magento/AwsS3/Driver/AwsS3.php#L104)).

## Serving assets from your S3 bucket

To start serving media assets from your S3 bucket, you need to make some adjustments to your nginx configuration.

```nginx
location /media {
# ...
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
resolver 8.8.8.8;
set $bucket "<my_bucket_name>";
proxy_pass https://s3.amazonaws.com/$bucket$uri;
proxy_pass_request_body off;
proxy_pass_request_headers off;
proxy_intercept_errors on;
proxy_hide_header "x-amz-id-2";
proxy_hide_header "x-amz-request-id";
proxy_hide_header "x-amz-storage-class";
proxy_hide_header "Set-Cookie";
proxy_ignore_headers "Set-Cookie";
}
# ...
}
```

Also make sure your S3 bucket policies are configured correctly, so that only `/media` is publicly readable. For example:

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPublicReadOnlyForMedia",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<your-bucket-name>/media/*"
}
]
}
```

## Magento remote storage documentation

- [Configure Remote Storage](https://experienceleague.adobe.com/en/docs/commerce-operations/configuration-guide/storage/remote-storage/remote-storage)
- [Configure AWS S3 bucket for remote storage](https://experienceleague.adobe.com/en/docs/commerce-operations/configuration-guide/storage/remote-storage/remote-storage-aws-s3)
Loading
Loading