Replace debian-based image with alpine-based.

Remove supervisor usage. Cron now runs as separate service.
CI for backend now performs without Docker.
This commit is contained in:
ErickSkrauch
2018-07-10 20:02:19 +03:00
parent a0d88e8a8f
commit 49d612daa1
12 changed files with 201 additions and 185 deletions

View File

@@ -1,41 +0,0 @@
#!/usr/bin/env bash
mkdir -p api/runtime api/web/assets console/runtime
chown www-data:www-data api/runtime api/web/assets console/runtime
if [ "$YII_ENV" = "test" ]
then
YII_EXEC="/var/www/html/tests/codeception/bin/yii"
else
YII_EXEC="/var/www/html/yii"
fi
if ! cmp -s ./../vendor/autoload.php ./vendor/autoload.php
then
echo "Vendor have diffs"
echo "Removing not bundled vendor..."
rm -rf ./vendor
echo "Copying new one..."
cp -r ./../vendor ./vendor
fi
# Переносим dist, если его нету или он изменился (или затёрся силами volume)
if ! cmp -s ./../dist/index.html ./frontend/dist/index.html
then
echo "Frontend dist have diffs"
echo "Removing not bundled dist..."
rm -rf ./frontend/dist
echo "Copying new one..."
cp -r ./../dist ./frontend/dist
fi
# Генерируем правила RBAC
echo "Generating RBAC rules"
php $YII_EXEC rbac/generate
if [ "$YII_ENV" != "test" ]
then
wait-for-it "${DB_HOST:-db}:3306" -s -t 0 -- "php $YII_EXEC migrate/up --interactive=0"
else
wait-for-it "${DB_HOST:-testdb}:3306" -s -t 0 -- "php $YII_EXEC migrate/up --interactive=0"
fi

62
docker/php/docker-entrypoint.sh Executable file
View File

@@ -0,0 +1,62 @@
#!/usr/bin/env bash
set -e
XDEBUG_EXTENSION_FILE="/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
PHP_PROD_INI="/usr/local/etc/php/conf.d/php.prod.ini"
PHP_DEV_INI="/usr/local/etc/php/conf.d/php.dev.ini"
if [ "$YII_DEBUG" = "true" ] || [ "$YII_DEBUG" = "1" ] ; then
echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > $XDEBUG_EXTENSION_FILE
mv ${PHP_PROD_INI}{,.disabled} 2> /dev/null || true
mv ${PHP_DEV_INI}{.disabled,} 2> /dev/null || true
else
rm -f $XDEBUG_EXTENSION_FILE
mv ${PHP_DEV_INI}{,.disabled} 2> /dev/null || true
mv ${PHP_PROD_INI}{.disabled,} 2> /dev/null || true
fi
cd /var/www/html
# Create all necessary folders
mkdir -p api/runtime api/web/assets console/runtime
chown -R www-data:www-data api/runtime api/web/assets console/runtime
if [ "$YII_ENV" = "test" ]
then
YII_EXEC="/var/www/html/tests/codeception/bin/yii"
else
YII_EXEC="/var/www/html/yii"
fi
# Fix permissions for cron tasks
chmod 644 /etc/cron.d/*
if [ "$1" = "crond" ] ; then
# see: https://github.com/dubiousjim/dcron/issues/13
# ignore using `exec` for `dcron` to get another pid instead of `1`
# exec "$@"
"$@"
fi
if [ "$1" = "yii" ] ; then
shift
php $YII_EXEC "$@"
exit 0
fi
if [ "$1" = "sh" ] || [ "$1" = "bash" ] || [ "$1" = "composer" ] || [ "$1" = "php" ] ; then
exec "$@"
exit 0
fi
echo "Generating RBAC rules"
php $YII_EXEC rbac/generate
if [ "$YII_ENV" != "test" ]
then
wait-for-it "${DB_HOST:-db}:3306" -s -t 0 -- "php $YII_EXEC migrate/up --interactive=0"
else
wait-for-it "${DB_HOST:-testdb}:3306" -s -t 0 -- "php $YII_EXEC migrate/up --interactive=0"
fi
exec "$@"

5
docker/php/php.dev.ini Normal file
View File

@@ -0,0 +1,5 @@
error_reporting = E_ALL;
display_errors = On;
# Disable Opcache caching
opcache.validate_timestamps = 1;

14
docker/php/php.prod.ini Normal file
View File

@@ -0,0 +1,14 @@
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
html_errors = Off
expose_php = Off
# Opcache tuning
opcache.revalidate_freq = 0
opcache.validate_timestamps = 0
opcache.max_accelerated_files = 7963
opcache.memory_consumption = 192
opcache.interned_strings_buffer = 16
opcache.fast_shutdown = 1

157
docker/php/wait-for-it.sh Executable file
View File

@@ -0,0 +1,157 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
# https://github.com/jlordiales/wait-for-it (fork of original source)
cmdname=$(basename $0)
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage() {
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}
wait_for() {
local wait_host=$1
local wait_port=$2
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $wait_host:$wait_port"
else
echoerr "$cmdname: waiting for $wait_host:$wait_port without a timeout"
fi
local start_ts=$(date +%s)
while :
do
(echo > /dev/tcp/$wait_host/$wait_port) >/dev/null 2>&1
local result=$?
if [[ $result -eq 0 ]]; then
local end_ts=$(date +%s)
echoerr "$cmdname: $wait_host:$wait_port is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}
wait_for_wrapper() {
local wait_host=$1
local wait_port=$2
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $TIMEOUT $0 $wait_host:$wait_port --quiet --child --timeout=$TIMEOUT &
else
timeout $TIMEOUT $0 $wait_host:$wait_port --child --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $wait_host:$wait_port"
fi
return $RESULT
}
parse_arguments() {
local index=0
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST[$index]=${hostport[0]}
PORT[$index]=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI="$@"
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
let index+=1
done
if [[ ${#HOST[@]} -eq 0 || ${#PORT[@]} -eq 0 ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi
}
iterate_hosts() {
local result=0
local index=0
local wait_function=$1
while [[ $result -eq 0 && $index -lt ${#HOST[@]} ]]; do
($wait_function ${HOST[$index]} ${PORT[$index]})
result=$?
let index+=1
done
echo $result
}
wait_for_services() {
TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}
if [[ $CHILD -gt 0 ]]; then
exit $(iterate_hosts wait_for)
else
if [[ $TIMEOUT -gt 0 ]]; then
RESULT=$(iterate_hosts wait_for_wrapper)
else
RESULT=$(iterate_hosts wait_for)
fi
fi
}
parse_arguments "$@"
wait_for_services
if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec $CLI
else
exit $RESULT
fi