summaryrefslogtreecommitdiff
path: root/Dockerfile
blob: 6c92eb8c9b4a764d61238a07851b8f3e7d6836f5 (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
FROM php:8.1-apache as builder

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

# 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 html /var/www/html

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

# Copy configuration files for the container
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 directories
# ------------------------------------------------------------------------------
# RUN chown -R www-data:www-data /var/www
RUN chmod -R 757 /var/www/html/cache


# 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