-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
101 lines (82 loc) · 3.48 KB
/
Dockerfile
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
FROM php:7.3-apache
# set main params
ARG BUILD_ARGUMENT_DEBUG_ENABLED=false
ENV DEBUG_ENABLED=$BUILD_ARGUMENT_DEBUG_ENABLED
ARG BUILD_ARGUMENT_ENV=dev
ENV ENV=$BUILD_ARGUMENT_ENV
ENV APP_HOME /var/www/html
# check environment
RUN if [ "$BUILD_ARGUMENT_ENV" = "default" ]; then echo "Set BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev" && exit 2; \
elif [ "$BUILD_ARGUMENT_ENV" = "dev" ]; then echo "Building development environment."; \
elif [ "$BUILD_ARGUMENT_ENV" = "test" ]; then echo "Building test environment."; \
elif [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then echo "Building production environment."; \
else echo "Set correct BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev. Available choices are dev,test,prod." && exit 2; \
fi
# install all the dependencies and enable PHP modules
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
procps \
nano \
git \
unzip \
libicu-dev \
zlib1g-dev \
libxml2 \
libxml2-dev \
libreadline-dev \
supervisor \
cron \
libzip-dev \
librabbitmq-dev \
&& pecl install amqp \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install \
pdo_mysql \
sockets \
intl \
zip \
&& docker-php-ext-enable amqp && \
rm -fr /tmp/* && \
rm -rf /var/list/apt/* && \
rm -r /var/lib/apt/lists/* && \
apt-get clean
# disable default site and delete all default files inside APP_HOME
RUN a2dissite 000-default.conf
RUN rm -r $APP_HOME
# create document root
RUN mkdir -p $APP_HOME/public
# change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
RUN chown -R www-data:www-data $APP_HOME
# put apache and php config for Symfony, enable sites
COPY ./docker/hosts/symfony.conf /etc/apache2/sites-available/symfony.conf
COPY ./docker/hosts/symfony-ssl.conf /etc/apache2/sites-available/symfony-ssl.conf
RUN a2ensite symfony.conf && a2ensite symfony-ssl
COPY ./docker/$BUILD_ARGUMENT_ENV/php.ini /usr/local/etc/php/php.ini
# enable apache modules
RUN a2enmod rewrite
RUN a2enmod ssl
# install Xdebug in case development or test environment
COPY ./docker/other/do_we_need_xdebug.sh /tmp/
COPY ./docker/dev/xdebug.ini /tmp/
RUN chmod u+x /tmp/do_we_need_xdebug.sh && /tmp/do_we_need_xdebug.sh
# install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
# add supervisor
RUN mkdir -p /var/log/supervisor
COPY --chown=root:root ./docker/other/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chown=root:root ./docker/other/cron /var/spool/cron/crontabs/root
RUN chmod 0600 /var/spool/cron/crontabs/root
# generate certificates
# TODO: change it and make additional logic for production environment
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem -subj "/C=AT/ST=Vienna/L=Vienna/O=Security/OU=Development/CN=example.com"
# set working directory
WORKDIR $APP_HOME
# create composer folder for user www-data
RUN mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www/.composer
USER www-data
# copy source files
COPY --chown=www-data:www-data . $APP_HOME/
# create cached config file .env.local.php in case prod environment
RUN if [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then composer dump-env $BUILD_ARGUMENT_ENV; \
fi
USER root