Skip to content

Commit f350566

Browse files
Merge pull request #340 from ByteInternet/update-obj-storage-for-magento2-docs
Update Object Storage Documentation
2 parents 16b1296 + 07c05d5 commit f350566

File tree

2 files changed

+105
-106
lines changed

2 files changed

+105
-106
lines changed

docs/ecommerce-applications/magento-2/how-to-configure-remote-storage-for-magento-2-x.md

Lines changed: 55 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -22,157 +22,106 @@ This can be useful for many reasons, such as:
2222

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

25-
**AWS S3**
25+
**Hypernode Object Storage and other S3 compatible providers**
26+
27+
If you're using Hypernode Object Storage or a different provider than AWS S3, you need to specify the `--remote-storage-endpoint` option.
2628

2729
```bash
2830
bin/magento setup:config:set \
2931
--remote-storage-driver="aws-s3" \
3032
--remote-storage-bucket="my_bucket_name" \
31-
--remote-storage-region="my-aws-region" \
33+
--remote-storage-region="provider-region" \
3234
--remote-storage-key="abcd1234" \
33-
--remote-storage-secret="abcd1234"
35+
--remote-storage-secret="abcd1234" \
36+
--remote-storage-endpoint="https://my-s3-compatible.endpoint.com"
3437
```
3538

36-
**Other S3 compatible providers**
39+
In the case of Hypernode Object Storage you can get the relevant information by running `hypernode-object-storage info` with the `--with-credentials` flag:
40+
41+
```console
42+
app@testapp ~ # hypernode-object-storage info --with-credentials
43+
+--------------------------------------+----------------+---------+-------------+-------------------------------------+---------------+---------------+
44+
| UUID | Name | Plan | Hypernodes | Management URL | Access Key | Secret Key |
45+
+--------------------------------------+----------------+---------+-------------+-------------------------------------+---------------+---------------+
46+
| 12345678-9012-3456-b7e3-19ab43df4a23 | testappbucket1 | OS200GB | testapp | https://example.ams.objectstore.eu | abcd1234 | abcd1234 |
47+
+--------------------------------------+----------------+---------+-------------+-------------------------------------+---------------+---------------+
48+
```
3749

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

4052
```bash
4153
bin/magento setup:config:set \
4254
--remote-storage-driver="aws-s3" \
4355
--remote-storage-bucket="my_bucket_name" \
44-
--remote-storage-region="provider-region" \
56+
--remote-storage-region="my-aws-region" \
4557
--remote-storage-key="abcd1234" \
46-
--remote-storage-secret="abcd1234" \
47-
--remote-storage-endpoint="https://my-s3-compatible.endpoint.com"
58+
--remote-storage-secret="abcd1234"
4859
```
4960

50-
## Syncing the files
61+
## Syncing the files (efficiently)
5162

52-
Instead of running (which is Magento's official way to do this):
63+
Magento provides an official method for syncing files using the following command (not recommended):
5364

5465
```bash
5566
bin/magento remote-storage:sync
5667
```
5768

58-
One can run the following instead to really speed up the process:
69+
However, for better performance, you can use the following alternative:
70+
71+
```bash
72+
hypernode-object-storage objects sync pub/media/ s3://my_bucket_name/media/
73+
hypernode-object-storage objects sync var/import_export s3://my_bucket_name/import_export
74+
```
75+
76+
The `hypernode-object-storage objects sync` command runs the sync process in the background
77+
and provides the Process ID (PID). You can monitor the sync progress using:
78+
79+
```bash
80+
hypernode-object-storage objects show PID
81+
```
82+
83+
Alternatively, you can use the AWS CLI directly:
5984

6085
```bash
6186
aws s3 sync pub/media/ s3://my_bucket_name/media/
6287
aws s3 sync var/import_export s3://my_bucket_name/import_export
6388
```
6489

65-
This is much faster than Magento's built-in sync, because `aws s3 sync` uploads files concurrently.
90+
Both methods are significantly faster than Magentos built-in sync, as aws s3 sync handles uploads concurrently.
6691

6792
## The storage flag file in the bucket
6893

6994
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)).
7095

7196
## Serving assets from your S3 bucket
7297

73-
To start serving media assets from your S3 bucket, you need to make some adjustments to your nginx configuration. Create the following file at `/data/web/nginx/example.com/server.assets.conf` for each relevant vhost:
74-
75-
```nginx
76-
set $backend "haproxy";
77-
78-
location @object_storage_fallback {
79-
# Proxy to object storage
80-
set $bucket "my_bucket_name";
81-
proxy_cache_key "$bucket$uri";
82-
proxy_cache_valid 200 302 7d;
83-
proxy_cache_methods GET HEAD;
84-
proxy_cache_background_update on;
85-
proxy_cache_use_stale updating;
86-
proxy_cache asset_cache;
87-
resolver 8.8.8.8;
88-
proxy_pass https://$bucket.s3.amazonaws.com$uri;
89-
proxy_pass_request_body off;
90-
proxy_pass_request_headers off;
91-
proxy_intercept_errors on;
92-
proxy_hide_header "x-amz-id-2";
93-
proxy_hide_header "x-amz-request-id";
94-
proxy_hide_header "x-amz-storage-class";
95-
proxy_hide_header "x-amz-server-side-encryption";
96-
proxy_hide_header "Set-Cookie";
97-
proxy_ignore_headers "Set-Cookie";
98-
add_header Cache-Control "public";
99-
add_header X-Frame-Options "SAMEORIGIN";
100-
add_header X-Cache-Status $upstream_cache_status;
101-
expires +1y;
102-
103-
# If object storage fails, fallback to PHP handler
104-
error_page 404 = @asset_fallback;
105-
error_page 403 = @asset_fallback;
106-
}
107-
108-
location @php_asset_fallback {
109-
# Handle with phpfpm
110-
rewrite ^/media /get.php?$args last;
111-
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
112-
echo_exec @phpfpm;
113-
}
98+
To serve media assets directly from your S3 bucket, you need to adjust your Nginx configuration.
99+
Fortunately, `hypernode-manage-vhosts` simplifies this process for you.
100+
If you're using Hypernode's object storage solution, simply run the following command for the relevant vhosts:
114101

115-
location @haproxy {
116-
# Handle with haproxy
117-
include /etc/nginx/proxy_to_haproxy.conf;
118-
proxy_pass http://127.0.0.1:8080;
119-
}
120-
121-
location @asset_fallback {
122-
try_files "" $asset_fallback_handler;
123-
}
124-
125-
location ~ ^/static/ {
126-
expires max;
127-
128-
# Remove signature of the static files that is used to overcome the browser cache
129-
location ~ ^/static/version\d*/ {
130-
rewrite ^/static/version\d*/(.*)$ /static/$1 last;
131-
}
102+
```bash
103+
hmv example.com --object-storage
104+
```
132105

133-
location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2|html|json|webmanifest)$ {
134-
add_header Cache-Control "public";
135-
add_header X-Frame-Options "SAMEORIGIN";
136-
expires +1y;
106+
### Using a custom object storage solution
137107

138-
try_files $uri $uri/ @asset_fallback;
139-
}
140-
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
141-
add_header Cache-Control "no-store";
142-
add_header X-Frame-Options "SAMEORIGIN";
143-
expires off;
108+
If you're using a custom storage provider, such as Amazon S3, you'll need to specify the bucket name and URL manually:
144109

145-
try_files $uri $uri/ @asset_fallback;
146-
}
147-
try_files $uri $uri/ @asset_fallback;
148-
add_header X-Frame-Options "SAMEORIGIN";
149-
}
110+
```bash
111+
hmv example.com --object-storage --object-storage-bucket mybucket --object-storage-url https://example_url.com
112+
```
150113

151-
location /media/ {
152-
try_files $uri $uri/ @asset_fallback;
114+
### Switching back to Hypernode defaults
153115

154-
location ~ ^/media/theme_customization/.*\.xml {
155-
deny all;
156-
}
116+
If you previously set a custom bucket and URL but want to revert to Hypernode's default object storage, use the `--object-storage-defaults` flag:
157117

158-
location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|swf|eot|ttf|otf|woff|woff2)$ {
159-
add_header Cache-Control "public";
160-
add_header X-Frame-Options "SAMEORIGIN";
161-
expires +1y;
162-
try_files $uri $uri/ @object_storage_fallback;
163-
}
164-
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
165-
add_header Cache-Control "no-store";
166-
add_header X-Frame-Options "SAMEORIGIN";
167-
expires off;
168-
try_files $uri $uri/ @object_storage_fallback;
169-
}
170-
add_header X-Frame-Options "SAMEORIGIN";
171-
}
118+
```bash
119+
hmv example.com --object-storage-defaults
172120
```
173121

174-
Make sure to change the string `my_bucket_name` to the name of your bucket and keep in mind that your bucket URL might be different depending on your AWS region. For example, you might need to change it from `https://$bucket.s3.amazonaws.com$uri` to `https://s3.amazonaws.com/$bucket$uri` instead.
175-
Furthermore, ensure that your S3 bucket policies are configured correctly, so that only `/media` is publicly readable. For example:
122+
### Configuring Amazon S3 bucket policies
123+
124+
If you’re using Amazon S3, ensure that your S3 bucket policies are properly configured so that only the `/media` directory is publicly accessible. For example:
176125

177126
```json
178127
{

docs/hypernode-platform/object-storage/getting-started-with-object-storage.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,56 @@ app@testhypernode ~ # hypernode-object-storage info
6363

6464
You can use the credentials and the URL now to configure remote storage for your application with the help of [this document](../../ecommerce-applications/magento-2/how-to-configure-remote-storage-for-magento-2-x.md).
6565

66+
### Managing objects in object storage
67+
68+
You can manage your objects using the `hypernode-object-storage objects` subcommand.
69+
It supports all common operations--listing, copying, moving, and deleting files--while also allowing you to sync files in the background and monitor the progress of an ongoing sync.
70+
71+
```console
72+
app@testhypernode ~ # hypernode-object-storage objects --help
73+
usage: hypernode-object-storage objects [-h] {sync,cp,ls,mv,rm,show} ...
74+
75+
Manage objects in object storage
76+
77+
positional arguments:
78+
{sync,cp,ls,mv,rm,show}
79+
sync Synchronize files between a local directory and an object storage location
80+
cp Copy a file or object from one location to another
81+
ls List objects in an S3 bucket or folder
82+
mv Move or rename a file or object
83+
rm Delete an object from S3
84+
show Display the current status of an ongoing sync process
85+
86+
options:
87+
-h, --help show this help message and exit
88+
```
89+
90+
It is important to note that `hypernode-object-storage objects` supports all optional flags available in `aws s3`, allowing you to customize its behavior for advanced configurations.
91+
92+
#### Syncing files and monitoring progress
93+
94+
Syncing files between your local directory and object storage is simple. Run the following command:
95+
96+
```console
97+
app@testhypernode ~ # hypernode-object-storage objects sync /example/local/path/ s3://example/bucket/uri/
98+
Syncing objects from /example/local/path/ to s3://example/bucket/uri/...
99+
Sync process started with PID 1234 in the background.
100+
```
101+
102+
The `sync` operation runs in the background, and you can monitor its progress by using the `show` command, for example:
103+
104+
```console
105+
app@testhypernode ~ # hypernode-object-storage objects show 1234
106+
Completed 9.7 GiB/~30.0 GiB (118.2 MiB/s) with ~5 file(s) remaining (calculating...)
107+
```
108+
109+
If you run the `show` command after the sync operation has finished, you’ll see output like this:
110+
111+
```console
112+
app@testhypernode ~ # hypernode-object-storage objects show 1234
113+
Process 1234 does not exist anymore
114+
```
115+
66116
## UI option - Control Panel
67117

68118
Coming soon

0 commit comments

Comments
 (0)