Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01242bf

Browse files
committed
Added Docker entrypoint
1 parent 7ef17b9 commit 01242bf

6 files changed

Lines changed: 249 additions & 17 deletions

File tree

.docker/Dockerfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
FROM php:7.3-apache
2-
RUN apt-get update && apt-get install -y libicu-dev git zip unzip && docker-php-ext-install intl && docker-php-ext-install pdo_mysql
3-
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
4-
# RUN git clone git://github.com/vvaswani/jade.git . && git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
5-
# RUN git clone git://github.com/vvaswani/jade.git . && git checkout docker
6-
COPY .docker/php/application.ini "$PHP_INI_DIR/conf.d/application.ini"
7-
COPY . /var/www/html/
8-
COPY config/autoload/local.php.dist /var/www/html/config/autoload/local.php
9-
WORKDIR /var/www/html
10-
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
11-
RUN php composer-setup.php
12-
RUN php composer.phar install --prefer-dist --no-scripts --no-dev --no-autoloader && rm -rf /root/.composer
13-
RUN php composer.phar dump-autoload --no-scripts --no-dev --optimize
14-
RUN rm -rf composer-setup.php composer.phar .docker/
15-
RUN chown -R www-data:www-data /var/www/html && a2enmod rewrite
16-
RUN service apache2 restart
1+
FROM php:7.3-apache
2+
RUN apt-get update && apt-get install -y libicu-dev git zip unzip && docker-php-ext-install intl && docker-php-ext-install pdo_mysql
3+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
4+
# RUN git clone git://github.com/vvaswani/jade.git . && git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
5+
# RUN git clone git://github.com/vvaswani/jade.git . && git checkout docker
6+
COPY .docker/config/php.ini "$PHP_INI_DIR/conf.d/app.ini"
7+
COPY . /var/www/html/
8+
#COPY config/autoload/local.php.dist /var/www/html/config/autoload/local.php
9+
WORKDIR /var/www/html
10+
#RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
11+
#RUN php composer-setup.php
12+
#RUN php composer.phar install --prefer-dist --no-scripts --no-dev --no-autoloader && rm -rf /root/.composer
13+
#RUN php composer.phar dump-autoload --no-scripts --no-dev --optimize
14+
#RUN rm -rf composer-setup.php composer.phar
15+
RUN apt-get remove libicu-dev git zip unzip && apt-get autoremove
16+
RUN chown -R www-data:www-data /var/www/html && a2enmod rewrite
1717
EXPOSE 80
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ date.timezone = UTC
22
post_max_size = 50M
33
upload_max_filesize = 50M
44
file_uploads = On
5+
intl.default_locale = en_GB

.docker/docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ services:
2121
- db
2222
ports:
2323
- "8080:80"
24+
environment:
25+
MYSQL_DATABASE: example
26+
MYSQL_USER: example-user
27+
MYSQL_PASSWORD: example-password
28+
entrypoint: ["/var/www/html/.docker/scripts/entrypoint.sh"]
29+
command: ["apache2-foreground"]
2430
networks:
2531
default:
2632
name: default-network

.docker/scripts/entrypoint.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# check for local configuration file
6+
# create if not already present
7+
echo "Checking for database credentials..."
8+
if [ ! -f /var/www/html/config/autoload/local.php ]; then
9+
echo "No database credentials found."
10+
echo "Creating configuration file with database credentials..."
11+
cp /var/www/html/config/autoload/local.php.dist /var/www/html/config/autoload/local.php
12+
sed -i "s/localhost/db/g" /var/www/html/config/autoload/local.php
13+
echo "Configuration file created."
14+
else
15+
echo "Configuration file found, skipping."
16+
fi
17+
18+
echo $aa
19+
20+
# wait for database server to become active
21+
/var/www/html/.docker/scripts/wait-for-it.sh db:3306
22+
23+
# check for database
24+
# create if not already present
25+
if [ $? -eq 0 ]; then
26+
echo "Database server active."
27+
echo "Checking for database..."
28+
if ! /var/www/html/vendor/bin/doctrine-module dbal:run-sql "SELECT COUNT(*) FROM job" ; then
29+
echo "No database found."
30+
echo "Creating database schema..."
31+
/var/www/html/vendor/bin/doctrine-module -n orm:schema-tool:create
32+
echo "Loading database fixtures..."
33+
/var/www/html/vendor/bin/doctrine-module -n orm:fixtures:load
34+
else
35+
echo "Database found, skipping database creation."
36+
fi
37+
else
38+
echo "Database server inactive, skipping database checks."
39+
fi
40+
41+
# run default entrypoint commands for parent image
42+
# first arg is `-f` or `--some-option`
43+
if [ "${1#-}" != "$1" ]; then
44+
set -- apache2-foreground "$@"
45+
fi
46+
47+
exec "$@"
48+

.docker/scripts/wait-for-it.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env bash
2+
# Use this script to test if a given TCP host/port are available
3+
4+
WAITFORIT_cmdname=${0##*/}
5+
6+
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
7+
8+
usage()
9+
{
10+
cat << USAGE >&2
11+
Usage:
12+
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
13+
-h HOST | --host=HOST Host or IP under test
14+
-p PORT | --port=PORT TCP port under test
15+
Alternatively, you specify the host and port as host:port
16+
-s | --strict Only execute subcommand if the test succeeds
17+
-q | --quiet Don't output any status messages
18+
-t TIMEOUT | --timeout=TIMEOUT
19+
Timeout in seconds, zero for no timeout
20+
-- COMMAND ARGS Execute command with args after the test finishes
21+
USAGE
22+
exit 1
23+
}
24+
25+
wait_for()
26+
{
27+
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
28+
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
29+
else
30+
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
31+
fi
32+
WAITFORIT_start_ts=$(date +%s)
33+
while :
34+
do
35+
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
36+
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
37+
WAITFORIT_result=$?
38+
else
39+
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
40+
WAITFORIT_result=$?
41+
fi
42+
if [[ $WAITFORIT_result -eq 0 ]]; then
43+
WAITFORIT_end_ts=$(date +%s)
44+
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
45+
break
46+
fi
47+
sleep 1
48+
done
49+
return $WAITFORIT_result
50+
}
51+
52+
wait_for_wrapper()
53+
{
54+
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
55+
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
56+
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
57+
else
58+
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
59+
fi
60+
WAITFORIT_PID=$!
61+
trap "kill -INT -$WAITFORIT_PID" INT
62+
wait $WAITFORIT_PID
63+
WAITFORIT_RESULT=$?
64+
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
65+
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
66+
fi
67+
return $WAITFORIT_RESULT
68+
}
69+
70+
# process arguments
71+
while [[ $# -gt 0 ]]
72+
do
73+
case "$1" in
74+
*:* )
75+
WAITFORIT_hostport=(${1//:/ })
76+
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
77+
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
78+
shift 1
79+
;;
80+
--child)
81+
WAITFORIT_CHILD=1
82+
shift 1
83+
;;
84+
-q | --quiet)
85+
WAITFORIT_QUIET=1
86+
shift 1
87+
;;
88+
-s | --strict)
89+
WAITFORIT_STRICT=1
90+
shift 1
91+
;;
92+
-h)
93+
WAITFORIT_HOST="$2"
94+
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
95+
shift 2
96+
;;
97+
--host=*)
98+
WAITFORIT_HOST="${1#*=}"
99+
shift 1
100+
;;
101+
-p)
102+
WAITFORIT_PORT="$2"
103+
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
104+
shift 2
105+
;;
106+
--port=*)
107+
WAITFORIT_PORT="${1#*=}"
108+
shift 1
109+
;;
110+
-t)
111+
WAITFORIT_TIMEOUT="$2"
112+
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
113+
shift 2
114+
;;
115+
--timeout=*)
116+
WAITFORIT_TIMEOUT="${1#*=}"
117+
shift 1
118+
;;
119+
--)
120+
shift
121+
WAITFORIT_CLI=("$@")
122+
break
123+
;;
124+
--help)
125+
usage
126+
;;
127+
*)
128+
echoerr "Unknown argument: $1"
129+
usage
130+
;;
131+
esac
132+
done
133+
134+
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
135+
echoerr "Error: you need to provide a host and port to test."
136+
usage
137+
fi
138+
139+
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
140+
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
141+
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
142+
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
143+
144+
# check to see if timeout is from busybox?
145+
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
146+
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
147+
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
148+
WAITFORIT_ISBUSY=1
149+
WAITFORIT_BUSYTIMEFLAG="-t"
150+
151+
else
152+
WAITFORIT_ISBUSY=0
153+
WAITFORIT_BUSYTIMEFLAG=""
154+
fi
155+
156+
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
157+
wait_for
158+
WAITFORIT_RESULT=$?
159+
exit $WAITFORIT_RESULT
160+
else
161+
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
162+
wait_for_wrapper
163+
WAITFORIT_RESULT=$?
164+
else
165+
wait_for
166+
WAITFORIT_RESULT=$?
167+
fi
168+
fi
169+
170+
if [[ $WAITFORIT_CLI != "" ]]; then
171+
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
172+
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
173+
exit $WAITFORIT_RESULT
174+
fi
175+
exec "${WAITFORIT_CLI[@]}"
176+
else
177+
exit $WAITFORIT_RESULT
178+
fi

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ nbproject
88
.settings
99
composer.phar
1010
*.*~
11-
vendor
1211
data/cache/*
1312
data/tmp/*
1413
data/upload/*

0 commit comments

Comments
 (0)