Skip to content

Commit e41e8f2

Browse files
colinmollenhourSven Reichel
and
Sven Reichel
authored
Add SAMPLE_DATA option to dev/openmage/install.sh (#4602)
* Add SAMPLE_DATA option to dev/openmage/install.sh script and fix warnings. * Improve reliability of waiting for MySQL to be ready * Update docs --------- Co-authored-by: Sven Reichel <[email protected]>
1 parent b1c2dca commit e41e8f2

File tree

7 files changed

+207
-157
lines changed

7 files changed

+207
-157
lines changed

dev/openmage/README.md

+1-145
Original file line numberDiff line numberDiff line change
@@ -1,145 +1 @@
1-
OpenMage Stack
2-
===
3-
4-
With these stack configuration files you can have a fully operational OpenMage LTS development in ONE step!
5-
Upgrade it to production with just a few more easy steps!
6-
7-
**NOTE: Use at your own risk! No warrants or guarantees are provided as to the stability, security or general quality of these environment files.**
8-
9-
For a more robust development environment that supports https, please consider using [ddev](https://ddev.readthedocs.io/en/stable/users/cli-usage/#magento-1-quickstart).
10-
11-
## Prerequisites
12-
13-
- Install [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/)
14-
- Port 80 on your host must be unused. See [Environment Variables](#environment-variables) below if you need to use another port.
15-
- Clone the OpenMage LTS repo to your location of choice (`git clone https://github.com/OpenMage/magento-lts.git`).
16-
17-
## Installation
18-
19-
Run `dev/openmage/install.sh`. That's it!
20-
21-
Visit [http://openmage-7f000001.nip.io/](http://openmage-7f000001.nip.io/) and start coding!
22-
23-
Tips
24-
===
25-
26-
See [colinmollenhour/docker-openmage](https://github.com/colinmollenhour/docker-openmage) for more information
27-
on the containers used in this setup, but here are some quick tips:
28-
29-
- You can start the cron task using `docker-compose up -d cron`.
30-
- The `cli` service contains many useful tools like `composer`, `magerun`, `modman`, `mageconfigsync` and more.
31-
- XDebug is enabled using `remote_connect_back=1` with `idekey=phpstorm`. Customize this in `.env` if needed as described below.
32-
33-
Here are some common commands you may wish to try (from the `dev/openmage` directory):
34-
35-
```
36-
$ docker-compose run --rm -u $(id -u):$(id -g) cli composer show
37-
$ docker-compose run --rm -u $(id -u):$(id -g) cli bash
38-
$ docker-compose run --rm cli magerun sys:check
39-
$ docker-compose run --rm cli magerun cache:clean
40-
$ docker-compose run --rm cli magerun db:console
41-
$ docker-compose exec mysql mysql
42-
```
43-
44-
- *The cli container runs as `www-data` by default so use `-u $(id -u):$(id -g)` with composer so that the container will create/modify files with your user permissions to avoid file permission errors in your IDE.*
45-
- *Always use `run --rm` with the cli container to avoid creating lots of orphan containers.*
46-
47-
Environment Variables
48-
---
49-
50-
You can override some defaults using environment variables defined in a file (that you must create) at `dev/openmage/.env`.
51-
52-
- `ENABLE_SENDMAIL=true` - Enable the sendmail MTA
53-
- `XDEBUG_CONFIG=...` - Override the default XDebug config
54-
- `HOST_NAME=your-preferred-hostname`
55-
- `openmage-7f000001.nip.io` is used by default to resolve to `127.0.0.1`. See [nip.io](https://nip.io) for more info.
56-
- `HOST_PORT=8888`
57-
- `80` is used by default
58-
- `ADMIN_HOST_NAME`
59-
- `openmage-admin-7f000001.nip.io` is used by default to resolve to `127.0.0.1`. See [nip.io](https://nip.io) for more info.
60-
- `ADMIN_HOST_PORT`
61-
- `81` is used by default to avoid conflicts with the frontend port
62-
- `ADMIN_EMAIL`
63-
- `ADMIN_USERNAME`
64-
- `ADMIN_PASSWORD` (must be 14 characters or more)
65-
- `ADMIN_FIRSTNAME`
66-
- `ADMIN_LASTNAME`
67-
- `MAGE_IS_DEVELOPER_MODE`
68-
- `1` is used by default, set to `0` to disable
69-
- `CURRENCY`
70-
- `USD` is used by default
71-
- `LOCALE`
72-
- `en-US` is used by default
73-
- `TIMEZONE`
74-
- `America/New_York` is used by default
75-
- `MYSQL_PORT`
76-
- `3306` is used by default
77-
- `PM_MAX_CHILDREN` - Tune to your environment and needs - see [PHP-FPM configuration](https://www.php.net/manual/en/install.fpm.configuration.php)
78-
- `PM_START_SERVERS`
79-
- `PM_MIN_SPARE_SERVERS`
80-
- `PM_MAX_SPARE_SERVERS`
81-
82-
Wiping
83-
---
84-
85-
If you want to start fresh, wipe out your installation with the following command:
86-
87-
```
88-
$ docker-compose down --volumes && rm -f ../../app/etc/local.xml
89-
```
90-
91-
HTTPS / Production
92-
=====
93-
94-
You can easily have a multi-store SSL-protected environment using Docker with the `docker-compose-production.yml` file.
95-
96-
Features included out of the box:
97-
98-
- Free and automatic SSL provided by [Caddy](https://caddyserver.com/docs/caddyfile)
99-
- Separate domains for frontend and admin sites
100-
- Examples included for redirects, Basic Auth, multi-store routing
101-
- Easily add routes to your other sites
102-
- Root static assets (e.g. robots.txt) in a separate directory for each store view
103-
104-
**Do not try to run a dev environment and a production environment from the same working copy!**
105-
106-
If using OpenMage as a composer dependency, to avoid files being overwritten by composer upon updating OpenMage,
107-
it is recommended to copy the following files into your own project root and modify them as needed:
108-
109-
- `dev/openmage/docker-compose-production.yml` --> `docker-compose.yml`
110-
- `dev/openmage/nginx-admin.conf` --> `nginx-admin.conf`
111-
- `dev/openmage/nginx-frontend.conf` --> `nginx-frontend.conf`
112-
- `dev/openmage/Caddyfile-sample` --> `Caddyfile`
113-
- `pub/admin/` --> `static/admin/`
114-
- `pub/default/{favicon.ico,robots.txt}` --> `static/default/`
115-
116-
Then perform the following steps:
117-
118-
1. `echo "COMPOSE_FILE=docker-compose-production.yml" >> .env` to make the production stack the default
119-
1. Add `BASE_URL` and `ADMIN_URL` to your `.env` file
120-
1. `cp Caddyfile-sample Caddyfile` and edit the `Caddyfile` to reflect your domain names and Magento store codes
121-
1. If you did not hard-code your admin domain name in `Caddyfile` edit `.env` and make sure it includes `ADMIN_HOST_NAME`
122-
1. Run `docker-compose up -d` to launch your new production-ready environment!
123-
1. Load your existing database into the MySQL container volume and copy an existing `local.xml` file into the `app/etc/` subdirectory of your OpenMage root (e.g. `pub/app/etc/local.xml` for composer installations with default `magento-root-dir`).
124-
1. OR copy `dev/openmage/install.sh` into your root directory and run it to create a fresh installation.
125-
126-
Environment variables supported by the `docker-compose-production.yml` file and `install.sh` which may be set in `.env`
127-
when installing a new production environment:
128-
129-
- `SRC_DIR=./pub` - relative path to the OpenMage root - corresponds to the composer `magento-root-dir`
130-
- `STATIC_DIR=./static` - relative path to the directory which contains custom static files to be served from the root - must contain a subdirectory for `admin` and each store view.
131-
- `BASE_URL=https://frontend.example.com/` (overrides `HOST_NAME` and `HOST_PORT`)
132-
- `ADMIN_URL=https://backend.exmaple.com/` (overrides `ADMIN_HOST_NAME` and `ADMIN_HOST_PORT`)
133-
134-
**Backups, intrusion protection and other security features are not provided and are left up to you! This is simply a
135-
web server configuration that adds an easy to configure and maintain SSL termination.**
136-
137-
### Adding more store views
138-
139-
1. Create your new website and/or store codes in OpenMage.
140-
2. Create new root static asset directories in your static asset directory such as `static/store1`, `static/store2`, etc...
141-
3. Edit `Caddyfile` to map your domain name to the appropriate `runcode` and `runtype`.
142-
4. Configure the URLs in the System > Configuration.
143-
5. Set up your DNS and relaunch Caddy (`docker compose restart caddy`).
144-
145-
Mapping paths to different stores can be done using additional `reverse_proxy` declarations. See `@customfrontend` as an example.
1+
Please visit the [official documentation](https://docs.openmage.org/developers/tools/oneline/) for more information.

dev/openmage/docker-compose-production.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.7"
2-
31
services:
42
php-fpm:
53
image: ghcr.io/colinmollenhour/docker-openmage:8.2-fpm

dev/openmage/docker-compose.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
version: "3.7"
2-
31
services:
42
php-fpm:
53
image: ghcr.io/colinmollenhour/docker-openmage:8.2-fpm
64
volumes:
75
- ../..:/var/www/html
86
environment:
9-
- ENABLE_SENDMAIL=${ENABLE_SENDMAIL:-false}
107
- XDEBUG_CONFIG=${XDEBUG_CONFIG:-client_host=host.docker.internal mode=debug force_display_errors=1 start_with_request=yes}
118
- MAGE_IS_DEVELOPER_MODE=${MAGE_IS_DEVELOPER_MODE:-1}
129
- PM_MAX_CHILDREN=${PM_MAX_CHILDREN:-5}

dev/openmage/install.sh

+45-5
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,52 @@ $dc run --rm --no-deps cli chmod -R g+ws media var/cache var/log var/locks var/s
6262

6363
echo "Starting services..."
6464
$dc up -d mysql redis php-fpm
65-
sleep 4
66-
for i in $(seq 1 20); do
65+
66+
echo "Installing Composer dependencies..."
67+
$dc run --rm -u "$(id -u):$(id -g)" cli composer install --no-progress
68+
69+
for i in $(seq 1 30); do
6770
sleep 1
6871
$dc exec mysql mysql -e 'show databases;' 2>/dev/null | grep -qF "$MYSQL_DATABASE" && break
72+
echo "Waiting for MySQL to be ready..."
6973
done
7074

71-
echo "Installing Composer dependencies..."
72-
$dc run --rm -u "$(id -u):$(id -g)" cli composer install --no-progress
75+
if [[ -n "${SAMPLE_DATA:-}" ]]; then
76+
echo "Installing Sample Data..."
77+
78+
SAMPLE_DATA_KEEP_FLAG="${SAMPLE_DATA_KEEP_FLAG:-0}"
79+
SAMPLE_DATA_URL=https://github.com/Vinai/compressed-magento-sample-data/raw/master/compressed-magento-sample-data-1.9.2.4.tgz
80+
SAMPLE_DATA_DIRECTORY="${SRC_DIR}/var/sample_data"
81+
SAMPLE_DATA_FILE=sample_data.tgz
82+
83+
if [[ ! -d "${SAMPLE_DATA_DIRECTORY}" ]]; then
84+
mkdir -p "${SAMPLE_DATA_DIRECTORY}"
85+
fi
86+
87+
if [[ ! -f "${SAMPLE_DATA_DIRECTORY}/${SAMPLE_DATA_FILE}" ]]; then
88+
echo "Downloading Sample Data..."
89+
wget "${SAMPLE_DATA_URL}" -O "${SAMPLE_DATA_DIRECTORY}/${SAMPLE_DATA_FILE}"
90+
fi
91+
92+
echo "Uncompressing Sample Data..."
93+
tar xf "${SAMPLE_DATA_DIRECTORY}/${SAMPLE_DATA_FILE}" -C "${SAMPLE_DATA_DIRECTORY}"
94+
95+
echo "Copying Sample Data into the OpenMage directory..."
96+
cp -r "${SAMPLE_DATA_DIRECTORY}"/magento-sample-data-1.9.2.4/media/* "${SRC_DIR}/media/"
97+
cp -r "${SAMPLE_DATA_DIRECTORY}"/magento-sample-data-1.9.2.4/skin/* "${SRC_DIR}/skin/"
98+
99+
echo "Importing Sample Data into the database..."
100+
$dc exec -T mysql mysql ${MYSQL_DATABASE} < "${SAMPLE_DATA_DIRECTORY}"/magento-sample-data-1.9.2.4/magento_sample_data_for_1.9.2.4.sql
101+
102+
# remove sample data
103+
if [[ ${SAMPLE_DATA_KEEP_FLAG} -eq 1 ]]; then
104+
echo "Removing uncompressed files..."
105+
rm -rf "${SAMPLE_DATA_DIRECTORY}/magento-sample-data-1.9.2.4/"
106+
else
107+
echo "Removing sample data..."
108+
rm -rf "${SAMPLE_DATA_DIRECTORY}"
109+
fi
110+
fi
73111

74112
echo "Installing OpenMage LTS..."
75113
$dc run --rm cli php install.php \
@@ -86,6 +124,7 @@ $dc run --rm cli php install.php \
86124
--use_secure "$([[ $BASE_URL == https* ]] && echo yes || echo no)" \
87125
--secure_base_url "$BASE_URL" \
88126
--use_secure_admin "$([[ $ADMIN_URL == https* ]] && echo yes || echo no)" \
127+
--enable_charts 'yes' \
89128
--skip_url_validation \
90129
--admin_firstname "${ADMIN_FIRSTNAME:-OpenMage}" \
91130
--admin_lastname "${ADMIN_LASTNAME:-User}" \
@@ -95,6 +134,7 @@ $dc run --rm cli php install.php \
95134

96135
# Update URL config to split frontend/admin
97136
$dc exec mysql mysql -e "
137+
DELETE FROM core_config_data WHERE path IN ('admin/url/use_custom', 'web/unsecure/base_url', 'web/secure/base_url');
98138
INSERT INTO core_config_data (scope, scope_id, path, value) VALUES
99139
('default',0,'admin/url/use_custom','1'),
100140
('stores',0,'web/unsecure/base_url','$ADMIN_URL'),
@@ -109,7 +149,7 @@ if command -v curl >/dev/null 2>&1; then
109149
sleep 1
110150
curl --silent --fail ${BASE_URL} >/dev/null && break
111151
done
112-
curl --silent --show-error --fail ${BASE_URL} || true
152+
curl --silent --show-error --fail ${BASE_URL} -o /dev/null || echo "Frontend test failed: ${BASE_URL}"
113153
fi
114154

115155
echo ""

docs/content/developers/tools/ddev.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ tags:
55

66
# DDEV
77

8-
See: https://ddev.com
8+
[DDEV](https://ddev.com) is a powerful tool to set up and manage local PHP development environments.
9+
It is a Docker-based wrapper that provides many useful features for developers out of the box.
10+
11+
!!! info
12+
If you prefer a simpler development environment with no dependencies aside from Docker, see the
13+
[Docker Compose](/developers/tools/oneline) guide instead.
914

1015
!!! info "Test Environment for OpenMage in Windows 10 Based on DDEV"
1116

0 commit comments

Comments
 (0)