-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.sh
executable file
·63 lines (58 loc) · 2.11 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )" # Get the current directory
# Colors for the output
GREEN=$(tput setaf 2)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
WHITE=$(tput setaf 7)
NC=$(tput sgr0) # No color
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) open_cmd=xdg-open;;
Darwin*) open_cmd=open;;
*) open_cmd=start
esac
set -o allexport
# shellcheck source=.env.sample
source .env.sample
if [ -f .env ]; then
source .env
else
echo "⚠️ No .env file found, coping from .env.sample"
cp .env.sample .env
fi
set +o allexport
docker compose up -d --build --remove-orphans || { echo "❌ Failed to start docker compose" ; exit 1; }
echo "🚀 Waiting for installation to complete..."
retry=600
timeout=1
start=$(date +%s)
while [ $(($(date +%s) - $start)) -lt $retry ]; do
# Check if Magento is up and running against exposed http port just in case varnish or anything else is set in front.
response_code="$(curl -s -o /dev/null -w ''%{http_code}'' "http://localhost:${MAGENTO_HTTP_PORT}")"
if [[ $response_code == "000" ]] ; then
echo -ne "⏳ Waiting for Magento to be up and running... $(($(date +%s) - $start)) / $retry "\\r
sleep $timeout
docker compose ps --services | grep -q magento || { echo -ne \\r\\n"❌ Magento container failed"\\r\\n ; exit 1; }
continue
fi
if [[ $response_code == "500" ]] ; then
echo "❌ Something went wrong and Magento returned a 500 error"
exit 1;
fi
echo $GREEN
echo " ✅ Magento installed"
echo " Magento is up and running at http://${MAGENTO_HOST}:${MAGENTO_EXTERNAL_HTTP_PORT_NUMBER}/"
if [[ $MAGENTO_SAMPLEDATA == "true" || $MAGENTO_SAMPLEDATA == "yes" ]] ; then
$DIR/bin/install-sampledata || { echo "❌ Failed to install sample-data" ; exit 1; }
fi
$DIR/bin/magento setup:upgrade || { echo "❌ Failed to run setup:upgrade" ; exit 1; }
echo "🚀 Openning the browser..."
$open_cmd "http://${MAGENTO_HOST}:${MAGENTO_EXTERNAL_HTTP_PORT_NUMBER}/"
echo $NC
exit 0;
done
echo $RED
echo "❌ Timeout after $retry seconds"
echo $NC
exit 1