summaryrefslogtreecommitdiff
path: root/Dockerfile
blob: 16662a1fc82ee5fa8142054441bceed0651eac29 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
FROM php:8.1-apache as builder

# ARG MODE="PRODUCTION"
ARG MODE="debug"


# mailhog (fake mail) configuration
# ------------------------------------------------------------------------------
# RUN apt-get update &&\
#     apt-get install --no-install-recommends --assume-yes --quiet ca-certificates curl git &&\
#     rm -rf /var/lib/apt/lists/*
# RUN curl -Lsf 'https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz' | tar -C '/usr/local' -xvzf -
# ENV PATH /usr/local/go/bin:$PATH
# RUN go get github.com/mailhog/mhsendmail
# RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail
# RUN echo 'sendmail_path = /usr/bin/mhsendmail --smtp-addr mailhog:1025' > /usr/local/etc/php/php.ini


# msmtp (real mail) configuration
# ------------------------------------------------------------------------------
# RUN apt-get update && apt-get install -y msmtp && apt-get clean && rm -r /var/lib/apt/lists/*
# configure sendmail
# RUN { \
#     	echo "php_admin_value[sendmail_path] = $(which msmtp) -ti "; \
#     } >> /usr/local/etc/php-fpm.d/www.conf





# setup apache
# ------------------------------------------------------------------------------

# enable apache mod_rewrite and headers
RUN a2enmod rewrite
RUN a2enmod headers

# install pdo and mysql for php
RUN docker-php-ext-install pdo pdo_mysql mysqli

# copy application code
# ------------------------------------------------------------------------------

# Copy local code to the container image.
COPY public /var/www/public

# Copy core files behind public
COPY core /var/www/core

# Copy storage folder structure behind public
COPY storage /var/www/storage

# Copy configuration files for the container (application based)
COPY .env /var/www/
COPY docker /var/www/docker
COPY tests /var/www/tests
COPY composer.json /var/www/


# Install Composer
# ------------------------------------------------------------------------------

# Install Composer with required libraries
RUN apt-get update --fix-missing
RUN DEBIAN_FRONTEND=noninteractive apt-get install git unzip wget -y
RUN curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN rm composer-setup.php


# Add Greek locales to server
# ------------------------------------------------------------------------------
WORKDIR /
RUN apt-get install -y locales
RUN sed -i 's/^# *\(el_GR\)/\1/' /etc/locale.gen
RUN locale-gen


# Manage permitions in specific (writable) directories
# ------------------------------------------------------------------------------
# (make local storage directories writable)
RUN chown -R www-data:www-data /var/www
RUN chmod -R 757 /var/www/storage
RUN chown -R www-data:www-data /var/www/public/files
RUN chmod -R 757 /var/www/public/files

# change apache's default-root to /var/www/public
RUN sed -ri -e 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/*.conf


# Use the PORT environment variable in Apache configuration files.
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

# Override with custom settings
# TODO: COPY config/php-ini-overrides.ini $PHP_INI_DIR/conf.d/


# Instal Memcached
# ------------------------------------------------------------------------------
# RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev && pecl install memcached-3.2.0 && docker-php-ext-enable memcached
# CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]


# Install and setup cron
# ------------------------------------------------------------------------------
# RUN apt-get update && apt-get install cron -y 
# RUN crontab -l | { cat; echo "10 * * * * /usr/local/bin/php /var/www/core/cli/cache-categories.php"; } | crontab -
# or? RUN crontab -l | { cat; echo "10 * * * * php /var/www/core/cli/cache-categories.php"; } | crontab -
# ... or copy cronjobs file into/as /etc/cron.d/cron ; then RUN crontab /etc/cron.d/cron
# ... do that while on entrypoint
# (+) run once after ex. 4 minutes 



# Install XDebug (only for develop/debud modes)
# ------------------------------------------------------------------------------
RUN apt-get install -y apt-utils \
    && pecl install xdebug \
    && docker-php-ext-enable xdebug

COPY docker/config/php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN touch /usr/local/etc/php/xdebug.log
RUN chown www-data:www-data /usr/local/etc/php/xdebug.log
RUN chmod 664 /usr/local/etc/php/xdebug.log



# Prepare the entrypoint as in the original image
# ------------------------------------------------------------------------------
RUN cp /var/www/docker/bin/docker-entrypoint.sh /usr/local/bin
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT []


# TODO:
## Enable OPcache and JIT on production
# ------------------------------------------------------------------------------
## set environemt variable

# RUN load OPcache and JIT from script
### if [ "${MODE}" = "PRODUCTION" ]; then
### docker-php-ext-install opcache
### docker-php-ext-install opcache
### mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

### chk: https://stackoverflow.com/questions/68308209/docker-compose-failed-to-solve-rpc-error-code-unknown-desc-failed-to-comp

# TODO:
# Enable JIT

### fi



# TODO:
## Enable OPcache and JIT on production
# ------------------------------------------------------------------------------
### optimize.sh
### #!/bin/bash -x
### 
### if test ["$1" == "PRODUCTION"] ; then 
###     docker-php-ext-install opcache
###     docker-php-ext-install opcache
###     install and enable JIT
### else 
###     maybe install some dev-tool
### fi