-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathDockerfile
More file actions
219 lines (195 loc) · 8.6 KB
/
Copy pathDockerfile
File metadata and controls
219 lines (195 loc) · 8.6 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Base Image
FROM ubuntu:24.04
# Metadata
LABEL org.label-schema.name="Apache Docker" \
org.label-schema.description="Docker container running Apache on Ubuntu with Composer, Laravel, TDD via Shippable & CircleCI" \
org.label-schema.url="https://htmlgraphic.com" \
org.label-schema.vcs-url="https://github.com/htmlgraphic/Apache" \
org.label-schema.vendor="HTMLgraphic, LLC" \
org.label-schema.schema-version="1.0"
# Environment Variables
ENV DEBIAN_FRONTEND=noninteractive \
TERM=xterm \
OS_LOCALE="en_US.UTF-8" \
APACHE_RUN_USER=www-data \
APACHE_RUN_GROUP=www-data \
APACHE_LOG_DIR=/var/log/apache2 \
APACHE_PID_FILE=/var/run/apache2.pid \
APACHE_RUN_DIR=/var/run/apache2 \
APACHE_LOCK_DIR=/var/lock/apache2 \
CONTAINER_NAME=apache
ARG INSTALL_DEV_TOOLS=true
# Install prerequisites with minimal disk usage
RUN apt-get update && \
apt-get install -y --no-install-recommends gnupg ca-certificates ubuntu-keyring && \
apt-get clean && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
# Install libssl1.1 for ARM64 and initial dependencies
RUN APT_CACHE_DIR=/tmp/apt-cache && \
apt-get update && apt-get install -y \
curl \
wget && \
wget -qO /tmp/libssl1.1.deb https://ports.ubuntu.com/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_arm64.deb && \
dpkg -i /tmp/libssl1.1.deb && \
rm -f /tmp/libssl1.1.deb && \
apt-get install -y \
locales \
software-properties-common \
libmcrypt-dev && \
locale-gen ${OS_LOCALE} && \
apt-get clean && rm -rf /var/lib/apt/lists/*
ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
LC_ALL="en_US.UTF-8"
# Add PHP PPA and install additional dependencies
RUN add-apt-repository -y ppa:ondrej/php && \
apt-get update && apt-get install -y \
curl \
unzip \
p7zip-full \
apache2 \
libsasl2-modules \
libapache2-mod-php8.3 \
php-pear \
php8.3 \
php8.3-cli \
php8.3-bz2 \
php8.3-curl \
php8.3-mbstring \
php8.3-intl \
php8.3-fpm \
php8.3-dev \
php8.3-xml \
php8.3-common \
php8.3-redis \
php8.3-mysql \
php8.3-gd \
php8.3-zip \
php8.3-xsl \
php8.3-bcmath \
php8.3-mysql \
php8.3-phar \
php8.3-simplexml \
libxml2-dev \
libssl-dev \
zlib1g-dev \
cron \
ghostscript \
mailutils \
mysql-client \
libgs-dev \
imagemagick \
php8.3-imagick \
libmagickwand-dev \
language-pack-en \
supervisor \
rsyslog \
postfix \
netcat-openbsd \
python3 \
gyp \
wkhtmltopdf \
fontconfig \
libjpeg-turbo8 \
xfonts-75dpi \
xfonts-base && \
if [ "$INSTALL_DEV_TOOLS" = "true" ]; then \
apt-get install -y --no-install-recommends git iputils-ping vim dnsutils; \
fi && \
apt-get autoremove -y && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Install Mcrypt Extension
RUN pecl install mcrypt && \
echo "extension=mcrypt.so" > /etc/php/8.3/mods-available/mcrypt.ini && \
ln -s /etc/php/8.3/mods-available/mcrypt.ini /etc/php/8.3/apache2/conf.d/20-mcrypt.ini && \
ln -s /etc/php/8.3/mods-available/mcrypt.ini /etc/php/8.3/cli/conf.d/20-mcrypt.ini
# Configure Redis Extension
RUN echo "extension=redis.so" > /etc/php/8.3/mods-available/redis.ini && \
ln -sf /etc/php/8.3/mods-available/redis.ini /etc/php/8.3/apache2/conf.d/20-redis.ini && \
ln -sf /etc/php/8.3/mods-available/redis.ini /etc/php/8.3/cli/conf.d/20-redis.ini && \
find /etc/php/8.3/ -name "*redis*.ini" -not -path "/etc/php/8.3/mods-available/*" -not -name "20-redis.ini" -delete
# Enable Apache Modules
RUN a2enmod headers userdir rewrite ssl
# Create Apache directories
RUN mkdir -p /data/apache2/logs /data/apache2/ssl /data/apache2/sites-enabled && \
chown www-data:www-data /data/apache2/logs /data/apache2/ssl /data/apache2/sites-enabled
# Apache Configuration
RUN a2dissite default-ssl && \
echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf && \
a2enconf servername && \
sed -i 's|IncludeOptional sites-enabled/\*.conf|IncludeOptional /data/apache2/sites-enabled/*.conf|' /etc/apache2/apache2.conf && \
echo "<IfModule mpm_event_module>\nStartServers 2\nMinSpareThreads 25\nMaxSpareThreads 75\nThreadLimit 64\nThreadsPerChild 25\nMaxRequestWorkers 150\nMaxConnectionsPerChild 0\n</IfModule>" >> /etc/apache2/apache2.conf && \
echo "Header set X-Frame-Options DENY\nHeader set X-Content-Type-Options nosniff" > /etc/apache2/conf-available/security-headers.conf && \
a2enconf security-headers
# Postfix Configuration
RUN postconf -e "compatibility_level=2" \
"myhostname=localhost.localdomain" \
"mail_spool_directory=/var/spool/mail/" \
"mydestination=localhost.localdomain localhost" \
"smtp_sasl_auth_enable=yes" \
"smtp_sasl_security_options=noanonymous" \
"smtp_sasl_tls_security_options=noanonymous" \
"smtp_tls_security_level=may" \
"header_size_limit=4096000" \
"inet_protocols=ipv4" \
"relayhost=[sandbox.smtp.mailtrap.io]:587" \
"smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd" && \
cp /etc/hostname /etc/mailname
# Install wkhtmltox
RUN if wget -qO /tmp/wkhtmltox.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.noble_arm64.deb && [ -s /tmp/wkhtmltox.deb ]; then \
dpkg -i /tmp/wkhtmltox.deb || (apt-get update && apt-get install -f -y); \
rm -f /tmp/wkhtmltox.deb; \
else \
echo "wkhtmltox package not available for ARM64, using distro wkhtmltopdf package"; \
rm -f /tmp/wkhtmltox.deb; \
fi
# Create supervisord configuration directory
RUN mkdir -p /etc/supervisor/conf.d
# Copy Application Files
COPY ./app /opt/app
COPY ./tests /opt/tests
COPY ./tests/php_modules /opt/tests/php_modules
COPY ./tests/cli_php_modules /opt/tests/cli_php_modules
RUN chmod -R 755 /opt/* && \
chmod +x /opt/app/entrypoint.sh && \
chmod 644 /opt/tests/php_modules /opt/tests/cli_php_modules
# PHP Configuration
RUN cp /etc/php/8.3/apache2/php.ini /etc/php/8.3/apache2/php.ini.bak && \
sed -i 's|;include_path = ".:/usr/share/php"|include_path = ".:/usr/share/php:/data/pear"|' /etc/php/8.3/apache2/php.ini && \
sed -i 's|short_open_tag = On|short_open_tag = Off|' /etc/php/8.3/apache2/php.ini && \
sed -i 's|max_execution_time = 30|max_execution_time = 300|' /etc/php/8.3/apache2/php.ini && \
sed -i 's|memory_limit = 128M|memory_limit = 512M|' /etc/php/8.3/apache2/php.ini && \
sed -i 's|upload_max_filesize = 2M|upload_max_filesize = 100M|' /etc/php/8.3/apache2/php.ini && \
sed -i 's|post_max_size = 8M|post_max_size = 100M|' /etc/php/8.3/apache2/php.ini && \
sed -i 's|max_input_time = 60|max_input_time = 300|' /etc/php/8.3/apache2/php.ini && \
cp /etc/php/8.3/apache2/php.ini /etc/php/8.3/cli/php.ini && \
sed -i 's|max_execution_time = .*|max_execution_time = 300|' /etc/php/8.3/cli/php.ini && \
sed -i 's|max_input_time = .*|max_input_time = 300|' /etc/php/8.3/cli/php.ini
# Composer Installation
COPY --from=composer:2.8 /usr/bin/composer /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer && \
composer global require "laravel/installer" "vlucas/phpdotenv"
# Install WP-CLI
RUN wget -qO /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
chmod +x /usr/local/bin/wp
# Unit Tests
RUN tar xf /opt/tests/shunit2-2.1.7.tar.gz -C /opt/tests/ && \
chmod +x /opt/tests/build_tests.sh
# Permissions
RUN mkdir -p /data/www/public_html /data/pear /root/project/container-build && \
chown -R www-data:www-data /var/www/html /data/www/public_html /root/project/container-build && \
find /var/www/html -type f -exec chmod 644 {} \; && \
find /var/www/html -type d -exec chmod 755 {} \; && \
find /data/www/public_html -maxdepth 1 -type f -exec chmod 644 {} \; && \
find /data/www/public_html -maxdepth 1 -type d -exec chmod 755 {} \;
# Create test files
RUN echo "<?php phpinfo(); ?>" > /data/www/public_html/php_extensions.php && \
echo "<?php echo 'Hello World'; ?>" > /data/www/public_html/index.php && \
chown www-data:www-data /data/www/public_html/*.php && \
chmod 644 /data/www/public_html/*.php
# Volumes, Ports, Healthcheck
VOLUME ["/backup", "/data", "/etc/letsencrypt"]
EXPOSE 80 443
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/ || exit 1
# Entrypoint
ENTRYPOINT ["/opt/app/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]