Table of Contents
π§ About The Project
This tool will help you set up your development environement to kickstart the creation of a PrestaShop SaaS App.
You will find an exemple of a simple SaaS App Module within the rbm_example
folder.
Once you launch the services through docker-compose, you will get access to a PrestaShop instance configured with all the needed modules.
π‘ Getting Started
This is an example of how you may setup your project locally.
Prerequisites
Installation
Quick install
- Clone the repo
git clone https://github.com/PrestaShopCorp/rbm-devtools.prestashop.com.git
- Create your dot env file
cp .env.example .env
- Customize your .env
MODULE_NAME=CHANGEME123
PORT=8080
PMA_PORT=8081
DB_PORT=3307
π‘ more info in Environment variables section
- Copy your module You need to copy you module into modules directory
|-- modules
| |-- CHANGEME123
| |-- rbm_example
| `-- rbm_example_stairstep
π‘ "CHANGEME123" have been change beforehand in .env file
- Run the project
./install.sh
Configuration
Environment variables
PS_NAME
- Define the subdomain for the http tunnel (default value: CHANGEME123)
π‘ PS_NAME
is automatically generated by localtunnel client
MODULE_NAME
- Define the subdomain for the http tunnel (default value: CHANGEME123)
π‘ MODULE_NAME
needs to be setup before installing
TUNNEL_DOMAIN
- Define tunnel domain (default value: localtunnel.distribution.prestashop.net)
π‘ TUNNEL_DOMAIN
can be changed if you host your own localtunnel server
PS_LANGUAGE
- Change the default language installed on PrestaShop (default value: en)PS_COUNTRY
- Change the default country installed on PrestaShop (default value: GB)PS_ALL_LANGUAGES
- Install all the existing languages for the current version. (default value: 0)ADMIN_MAIL
- Override default admin mail (default value: admin@prestashop.com)ADMIN_PASSWD
- Override default admin password (default value: prestashop)PORT
- Define port of the PrestaShop and the http proxy client (default value: 8080)PMA_PORT
- Define port of PhpMyAdmin (default value: 8081)DB_PORT
- Define port of the MySQL (default value: 3307)
Custom install
Let's break the install.sh down:
First we create a network layer for our container. If the network already exists, we skip this part:
# Create a network for containers to communicate
NETWORK_NAME=prestashop_net
if [ -z $(docker network ls --filter name=^${NETWORK_NAME}$ --format="{{ .Name }}") ] ; then
echo -e "Create ${NETWORK_NAME} network for containers to communicate"
docker network create ${NETWORK_NAME} ;
else
echo -e "Network ${NETWORK_NAME} already exists, skipping"
fi
π‘ If you want to use another network you will need to edit docker-compose.yml
We create an http tunnel container, which will generate your shop url
# Create http tunnel container
echo -e "Create HTTP tunnel service"
if [[ `uname -m` == 'arm64' ]]; then
DOCKER_SCAN_SUGGEST=false docker-compose -f docker-compose.yml -f docker-compose.arm64.yml up -d --no-deps --force-recreate --build prestashop_tunnel
else
DOCKER_SCAN_SUGGEST=false docker-compose up -d --no-deps --force-recreate --build prestashop_tunnel
fi
echo -e "Checking if HTTP tunnel is available..."
LOCAL_TUNNEL_READY=`docker inspect -f {{.State.Running}} ps-tunnel.local`
until (("$LOCAL_TUNNEL_READY"=="true"))
do
echo -e "Waiting for confirmation of HTTP tunnel service startup"
sleep 5
done;
echo -e "HTTP tunnel is available, let's continue !"
We setup the .env file with your subdomain, if .env already exist we skip this part and we replace PS_NAME
# Setting up env file
echo -e "Setting up env file"
ENV_FILE=.env
SUBDOMAIN_NAME=`docker logs ps-tunnel.local 2>/dev/null | awk -F '/' '{print $3}' | awk -F"." '{print $1}' | awk 'END{print}' | tr -d "[:space:]"`
if [ ! -s "$ENV_FILE" ]; then
echo -e "Create env file"
cp .env.example $ENV_FILE
fi
sed -i $SED_OPTIONS -E "s|(PS_NAME=).*|PS_NAME=${SUBDOMAIN_NAME}|g" $ENV_FILE
if [[ "$OSTYPE" == "darwin"* ]]; then
rm -f "${ENV_FILE}${SED_OPTIONS}"
fi
PS_NAME=$(readEnv PS_NAME $ENV_FILE)
π‘ Note: you can customize the .env file, see below in Environment variables
We do a small trick to always get the same URL
# Handle restart to avoid new subdomain
TUNNEL_FILE=tunnel/.config
if [ ! -s "$TUNNEL_FILE" ]; then
echo -e "Handle restart to avoid new subdomain"
echo $SUBDOMAIN_NAME > $TUNNEL_FILE
fi
docker cp $TUNNEL_FILE ps-tunnel.local:/tmp/.config
We create the MySQL and PrestaShop container
# Create MySQL and PrestaShop service
echo -e "Create MySQL & PrestaShop service"
if [[ `uname -m` == 'arm64' ]]; then
DOCKER_SCAN_SUGGEST=false docker-compose -f docker-compose.yml -f docker-compose.arm64.yml up -d --no-deps --force-recreate --build prestashop_rbm_shop prestashop_rbm_db
else
DOCKER_SCAN_SUGGEST=false docker-compose up -d --no-deps --force-recreate --build prestashop_rbm_db prestashop_rbm_shop
fi
We wait until PrestaShop is ready to use
echo -e "Checking if PrestaShop is available..."
LOCAL_PORT=$(readEnv PORT $ENV_FILE)
if [ -z $LOCAL_PORT ] ; then
LOCAL_PORT=`docker port ps-rbm.local 80 | awk -F ':' '{print $2}' | tr -d "[:space:]"`
fi
PRESTASHOP_READY=`curl -s -o /dev/null -w "%{http_code}" localhost:$LOCAL_PORT`
until (("$PRESTASHOP_READY"=="302"))
do
# avoid infinite loop...
PRESTASHOP_READY=`curl -s -o /dev/null -w "%{http_code}" localhost:$LOCAL_PORT`
echo "Waiting for confirmation of PrestaShop is available (${PRESTASHOP_READY})"
sleep 5
done;
Finaly, we display your URL
BO Url: http://CHANGEME123.localtunnel.distribution.prestashop.net/admin-dev
FO Url: http://CHANGEME123.localtunnel.distribution.prestashop.net
Utils
Get your shop URL
./get-url.sh
BO Url: http://CHANGEME123.localtunnel.distribution.prestashop.net/admin-dev
FO Url: http://CHANGEME123.localtunnel.distribution.prestashop.net
Update the shop URL
./update-domain.sh
Updating PrestaShop domains ...
BO Url: http://CHANGEME123.localtunnel.distribution.prestashop.net/admin-dev
FO Url: http://CHANGEME123.localtunnel.distribution.prestashop.net
π Troubleshooting
Mac OS
Mac network_mode: "host" not working as expected
Error on database port
ERROR: for prestashop_rbm_db Cannot start service prestashop_rbm_db: Ports are not available: listen tcp 0.0.0.0:3307:
You should override the port DB_PORT
in the environement file
Database doesn't start
If the database doesn't start because of this error :
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
You should delete the ./mysql/
folder and relaunch everything.
Error within ps-tunnel.local
Bind for 0.0.0.0:8080 failed: port is already allocated
You should override the port PORT
in the environement file
Error within phpmyadmin.local
Bind for 0.0.0.0:8081 failed: port is already allocated
You should override the port PMA_PORT
in the environement file
Error docker env not changed
You can use Debug mode to force docker to rebuild images
export TUNNEL_DEBUG=true && ./install.sh
Error: operand expected
((: ==true : syntax error: operand expected (error token is "==true ")
You need to update your docker-compose version (>= 1.27.0)
π What next ?
SaaS App documentation
Documentation about developping a SaaS App is available here.
Install SaaS App example
-
Follow the instruction in README.md
-
Search RBM Example module within the Module Catalog
-
Click on "Install" button