Skip to content

Automated usage of Docker Stack

cmtickle edited this page Apr 24, 2023 · 3 revisions

(All examples on this page assume that you are using Linux/Mac OS and have cloned Docker-Stack to your user home directory. The commands should be executed in a Terminal window as your own user, not root or sudo.)

Creating an automated installer for https://mage-mirror.loc

This scenario demonstrates:

  • The stacks support of .loc domains.
  • Creating an automated installer script for Magento 2.
    • Changing variables in the project script to suit the projects needs.
    • Changing the functions called by a project.
    • Changing the CTI Digital Configurator configuration files for a project.
    • Editing the env.php according to projects setup.
  • The function of the ./project/resources folder.
  • The ability to store and use multiple database backups.
  • The functionality/variable which starts only the containers needed for a specific project.
  • The various docker:... functions supported by project scripts.
  • The setup:... functions.

# Copy the Magento Opensource sample script (even if you're going to be using Adobe Commerce for your own project).
# This is the most Vanilla install script.
cp ./project/m2_opensource ./project/mage_mirror

# Copy the resources which are used by this script during automated setup.
cp -r ./project/resources/eg-m2-opensource.loc ./project/resources/mage-mirror.loc

For this example, we will install the Magento Opensource 2.4-develop branch from a mirror.

Copying an existing project to make a new one.

  • Edit the "# Project Variables" section of file ./project/mage_mirror
    • Change cvs_organisation to 'cmtickle'
    • Change cvs_branch to '2.4-develop'
    • Change db_name to mage_mirror
    • Change vmhost_name to 'mage_mirror.loc'
    • Change required_containers so that elasticsearch7 becomes elasticsearch716
    • Remove the lines of the script between # Sample data needs adding ... and # End of sample data addition.
    • NOTE: For a real project you would most likely delete the github_args line. For this exercise, we won't delete the line as this makes it faster.
  • Edit the file ./project/resources/mage-mirror.loc/configurator/global.yaml
    • Change both base_url lines to reflect the new host https://mage-mirror.loc/
    • Change the "value" for "path" catalog/search/elasticsearch7_server_hostname to be http://elasticsearch716/
  • Edit the file ./project/resources/mage-mirror.loc/env.php
    • Change db > connection > default > dbname to mage_mirror (per the value defined in the above project script.)
    • Change cache > frontend > default > id_prefix and cache > frontend > page_cache > id_prefix to mm_ (or any random string to avoid cache collisions.)
    • Change downloadable_domains to mage-mirror.loc
  • NOTE: For a real project you would replace db.sql.gz with your own database backup, created with MySQL and compressed with gzip -9 db.sql.
    • If multiple database backups exist, you will be prompted to choose one during project setup.
  • Put your own credentials in ./project/resources/mage-mirror.loc/auth.json
  • Edit the file ./docker/nginx/m-hosts.conf so the $PHP_HOSTM2 map contains mage-mirror.loc php81; above the section marked "DEFAULT".

Starting the correct containers and running project setup.

  • Stop all running containers: ./project/mage_mirror docker:stop
  • Update the images and start only the containers needed by this project: ./project/mage_mirror docker:refresh (as defined in the project script as required_containers)
  • Check that the containers are running: ./project/mage_mirror docker:status
  • Install the project: ./project/mage_mirror setup:all (the variations and features of the setup:... parameters can be understood by running the project script with no parameters.)
  • wait until the script finishes and returns to a command prompt.
  • Add the host entry as described by the script output.
  • Access Magento's frontend: https://mage-mirror.loc/
  • Access Magento admin: https://mage-mirror.loc/admin using the credentials displayed by the setup script.

Sharing This New Project With Your Colleagues.

Clearly, you should not share details (e.g. client names and the auth.json) with the general public. For this reason, you should create a private fork of this repo and work in a branch which you never push/merge to this repository.

Once you are working against your private fork of the repository, you are free to commit files to ./project/resources.

BUT!! It is not recommended that you push large files (e.g. database backups) to Git. For this reason, the stack supports centralised storage of files in S3.

To change the above project from using "local" resources to resources stored in S3.

Setup and permission administration of S3 (and the s3cmd command line tool) is outside the scope of this wiki. We will assume that you have created, and have write permissions to, an S3 bucket called docker-stack.

# Upload the resources to S3
s3cmd put --recursive ./project/resources/mage-mirror.loc s3://docker-stack/
  • Edit the "# Project Variables" section of the project script ./project/mage_mirror
    • Change resources_storage to 's3'
    • (Optionally): If your S3 bucket has another name you can specify it in this section like s3_bucket='my-bucket';
  • Run the script setup again: ./project/mage_mirror setup:all (All resources should now download from S3).
  • (Optionally:) You can now delete the directory ./project/resources/mage-mirror.loc