Dockerfile 5.41 KB
Newer Older
1
2
3
4
# syntax = docker/dockerfile:experimental
FROM debian:10 AS dependencies

EXPOSE 8080
Dominik Hebeler's avatar
Dominik Hebeler committed
5

Dominik Hebeler's avatar
Dominik Hebeler committed
6
7
8
# Install System Components
RUN apt update \
    && apt install -y \
Dominik Hebeler's avatar
Dominik Hebeler committed
9
10
    nginx \
    tzdata \
Dominik Hebeler's avatar
Dominik Hebeler committed
11
12
13
14
15
16
    cron \
    lsb-release \
    apt-transport-https \
    curl \
    zip

17
# Install PHP Components
Dominik Hebeler's avatar
Dominik Hebeler committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
RUN curl -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
    && echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list

RUN apt update \
    && apt install -y \
    php7.4 \
    php7.4-xml \
    php7.4-fpm \
    php7.4-common \
    php7.4-curl \
    php7.4-mbstring \
    php7.4-sqlite3 \
    php7.4-mysql \
    php7.4-sqlite \
    php7.4-zip \
    php7.4-redis \
    php7.4-gd \
    php7.4-json \
Dominik Hebeler's avatar
Dominik Hebeler committed
36
37
    php7.4-opcache \
    php7.4-xdebug
Dominik Hebeler's avatar
Dominik Hebeler committed
38

39
40
41
42
43
# Install Composer
COPY ./helpers/installComposer.sh /usr/bin/installComposer
RUN chmod +x /usr/bin/installComposer && \
    /usr/bin/installComposer && \
    rm /usr/bin/installComposer
Dominik Hebeler's avatar
Dominik Hebeler committed
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Install Nodejs
COPY ./helpers/installNodejs.sh /usr/bin/installNodejs
RUN chmod +x /usr/bin/installNodejs && \
    /usr/bin/installNodejs && \
    rm /usr/bin/installNodejs
ENV PATH /usr/local/lib/nodejs/bin:$PATH

# Install Minio Client
RUN curl -o /usr/bin/mc "https://dl.min.io/client/mc/release/linux-amd64/mc" &&\
    chmod +x /usr/bin/mc

FROM dependencies AS development

RUN sed -i 's/pid = \/run\/php\/php7.4-fpm.pid/;pid = \/run\/php\/php7.4-fpm.pid/g' /etc/php/7.4/fpm/php-fpm.conf && \
Dominik Hebeler's avatar
Dominik Hebeler committed
59
60
61
    sed -i 's/error_log = \/var\/log\/php7.4-fpm.log/error_log = \/dev\/stderr/g' /etc/php/7.4/fpm/php-fpm.conf && \
    sed -i 's/;daemonize = yes/daemonize = no/g' /etc/php/7.4/fpm/php-fpm.conf && \
    sed -i 's/listen = \/run\/php\/php7.4-fpm.sock/listen = 9000/g' /etc/php/7.4/fpm/pool.d/www.conf && \
62
    sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 0/g' /etc/php/7.4/fpm/pool.d/www.conf && \
Dominik Hebeler's avatar
Dominik Hebeler committed
63
64
65
66
67
68
69
70
    sed -i 's/;request_terminate_timeout_track_finished = no/request_terminate_timeout_track_finished = yes/g' /etc/php/7.4/fpm/pool.d/www.conf && \
    sed -i 's/;decorate_workers_output = no/decorate_workers_output = no/g' /etc/php/7.4/fpm/pool.d/www.conf && \
    sed -i 's/;catch_workers_output = yes/catch_workers_output = yes/g' /etc/php/7.4/fpm/pool.d/www.conf && \
    sed -i 's/pm.max_children = 5/pm.max_children = 1024/g' /etc/php/7.4/fpm/pool.d/www.conf && \
    sed -i 's/pm.start_servers = 2/pm.start_servers = 50/g' /etc/php/7.4/fpm/pool.d/www.conf && \
    sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' /etc/php/7.4/fpm/pool.d/www.conf && \
    sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 50/g' /etc/php/7.4/fpm/pool.d/www.conf && \
    sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.4/fpm/php.ini && \
71
72
73
74
75
76
77
78
79
80
81
    echo "xdebug.mode = debug" >> /etc/php/7.4/fpm/conf.d/20-xdebug.ini && \
    echo "xdebug.start_with_request = yes" >> /etc/php/7.4/fpm/conf.d/20-xdebug.ini && \
    echo "xdebug.discover_client_host = true" >> /etc/php/7.4/fpm/conf.d/20-xdebug.ini && \
    echo "xdebug.idekey=VSCODE" >> /etc/php/7.4/fpm/conf.d/20-xdebug.ini && \
    sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 30M/g' /etc/php/7.4/fpm/php.ini && \
    sed -i 's/post_max_size = 8M/post_max_size = 30M/g' /etc/php/7.4/fpm/php.ini && \
    cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \
    echo "Europe/Berlin" > /etc/timezone
# (crontab -l ; echo "* * * * * php /html/artisan schedule:run >> /dev/null 2>&1") | crontab - # TODO: Fix crontab

# Using image as non-root
82
83
RUN groupadd -g 1000 metager && \
    useradd -b /home/metager -g 1000 -u 1000 -M -s /bin/bash metager
84
RUN chown -R 1000:1000 /var/lib/nginx /var/log/nginx
85
86
RUN mkdir -p /home/metager &&\
    chown 1000:1000 /home/metager
87
88
89
RUN touch /run/nginx.pid && \
    chown 1000:1000 /run/nginx.pid
USER 1000:1000
90
WORKDIR /html
91

Dominik Hebeler's avatar
Dominik Hebeler committed
92
CMD /html/helpers/entrypointDev.sh
93
94
95
96
97
98
99
100

FROM development AS production

USER 0:0

# Opcache configuration
RUN apt purge -y php7.4-xdebug
RUN sed -i 's/expose_php = On/expose_php = Off/g' /etc/php/7.4/fpm/php.ini && \
Dominik Hebeler's avatar
Dominik Hebeler committed
101
    sed -i 's/;opcache.enable=1/opcache.enable=1/g' /etc/php/7.4/fpm/php.ini && \
102
    sed -i 's/request_terminate_timeout = 0/request_terminate_timeout = 30/g' /etc/php/7.4/fpm/pool.d/www.conf && \
Dominik Hebeler's avatar
Dominik Hebeler committed
103
104
105
106
107
    sed -i 's/;opcache.memory_consumption=128/opcache.memory_consumption=128/g' /etc/php/7.4/fpm/php.ini && \
    sed -i 's/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g' /etc/php/7.4/fpm/php.ini && \
    sed -i 's/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=10000/g' /etc/php/7.4/fpm/php.ini && \
    sed -i 's/;opcache.max_wasted_percentage=5/opcache.max_wasted_percentage=5/g' /etc/php/7.4/fpm/php.ini && \
    sed -i 's/;opcache.validate_timestamps=1/opcache.validate_timestamps=1/g' /etc/php/7.4/fpm/php.ini && \
108
    sed -i 's/;opcache.revalidate_freq=2/opcache.revalidate_freq=300/g' /etc/php/7.4/fpm/php.ini
Dominik Hebeler's avatar
Dominik Hebeler committed
109
110

COPY config/nginx.conf /etc/nginx/nginx.conf
Dominik Hebeler's avatar
Dominik Hebeler committed
111
112
COPY config/nginx-default.conf /etc/nginx/sites-available/default
RUN sed -i 's/fastcgi_pass phpfpm:9000;/fastcgi_pass localhost:9000;/g' /etc/nginx/sites-available/default 
Dominik Hebeler's avatar
Dominik Hebeler committed
113

114
115
COPY --chown=1000:1000 . /html

Dominik Hebeler's avatar
Dominik Hebeler committed
116
117
RUN chmod +x /html/helpers/*.sh

118
119
120
121
122
# Install packages
RUN --mount=type=secret,id=auto-devops-build-secrets . /run/secrets/auto-devops-build-secrets && \
    chmod +x ./helpers/installPackages.sh && \
    /bin/sh -c ./helpers/installPackages.sh

123
124
USER 1000:1000

125
126
CMD /html/helpers/entrypointProduction.sh

127
128
#CMD cp /root/.env .env && \
#    cron -L /dev/stdout && \