-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathDockerfile
84 lines (72 loc) · 2.99 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
FROM --platform=linux/amd64 php:8.2-apache
# Add labels for better maintainability
LABEL maintainer="Your Name <[email protected]>"
LABEL description="Your application description"
# Set working directory
WORKDIR /var/www/html
# Install system dependencies and PHP extensions in a single layer
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
mariadb-client \
libzip-dev \
libicu-dev \
zlib1g-dev \
libc-client-dev \
libkrb5-dev \
gnupg2 \
libaio1 && \
docker-php-ext-configure intl && \
docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
docker-php-ext-install \
imap \
exif \
mysqli \
pdo \
pdo_mysql \
zip \
intl && \
# PHP configurations
echo "short_open_tag=off" >> /usr/local/etc/php/conf.d/syntax.ini && \
echo "memory_limit=-1" >> /usr/local/etc/php/conf.d/memory_limit.ini && \
echo "display_errors=0" >> /usr/local/etc/php/conf.d/errors.ini && \
# Update Apache configuration
sed -e 's!DocumentRoot /var/www/html!DocumentRoot /var/www/html/public!' -ri /etc/apache2/sites-available/000-default.conf && \
# Clean up
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
docker-php-ext-install opcache && \
echo "opcache.enable=1" >> /usr/local/etc/php/conf.d/opcache.ini && \
echo "opcache.memory_consumption=256" >> /usr/local/etc/php/conf.d/opcache.ini && \
echo "opcache.interned_strings_buffer=16" >> /usr/local/etc/php/conf.d/opcache.ini && \
echo "opcache.max_accelerated_files=20000" >> /usr/local/etc/php/conf.d/opcache.ini && \
echo "opcache.validate_timestamps=0" >> /usr/local/etc/php/conf.d/opcache.ini && \
echo "realpath_cache_size=4096K" >> /usr/local/etc/php/conf.d/php.ini && \
echo "realpath_cache_ttl=600" >> /usr/local/etc/php/conf.d/php.ini
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install Node.js (using specific version)
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get update && \
apt-get install -y nodejs build-essential && \
npm install -g npm yarn && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy composer files first to leverage layer caching
COPY composer.json composer.lock ./
RUN composer install --no-scripts --no-autoloader
# Copy application files
COPY --chown=www-data:www-data . .
# Final composer and yarn steps
RUN composer dump-autoload --optimize && \
yarn install && \
yarn run build
# Copy scripts and set permissions
COPY ./docker/script/myddleware-foreground.sh /usr/local/bin/
COPY ./docker/script/myddleware-cron.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/myddleware-*.sh
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
CMD curl -f http://localhost/ || exit 1
# Switch to non-root user
USER www-data
CMD ["myddleware-foreground.sh"]