File size: 4,932 Bytes
27afd3f
35ae388
27afd3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560ee81
27afd3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560ee81
 
 
 
 
 
 
 
27afd3f
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
ARG VERSION=8.0.8-fpm-buster-nginx-1.21.1
FROM dwchiang/nginx-php-fpm:8.0.8-fpm-buster-nginx-1.21.1

ARG VERSION_PHP_MINOR
ARG VERSION_OS
ENV VERSION_OS=${VERSION_OS} 

### ----------------------------------------------------------
### PHP
### ----------------------------------------------------------

RUN set -x && \
    # install lib packages
    apt-get update --allow-releaseinfo-change &&\
    apt-get install --no-install-recommends --no-install-suggests -y \
        bc \
        # for bz2
        #   - ref: https://github.com/docker-library/php/issues/47
        libbz2-dev \
        # for gd
        #   - ref: https://stackoverflow.com/questions/61228386/installing-gd-extension-in-docker
        libfreetype6-dev \
        libpng-dev \
        libjpeg62-turbo-dev \
        && \
    # install general usage packages
    apt-get install --no-install-recommends --no-install-suggests -y \
        # for composer
        git \
        && \
    # docker-php
    #   - Removed `mbstring` on alpine: https://stackoverflow.com/questions/59251008/docker-laravel-configure-error-package-requirements-oniguruma-were-not-m/59253249#59253249
    #     Due to this error: `configure: error: Package requirements (oniguruma) were not met: Package 'oniguruma', required by 'virtual:world', not found`
    # for gd
    #   - ref: https://github.com/docker-library/php/pull/910#issuecomment-559383597
    if [ $(echo "${VERSION_PHP_MINOR} >= 7.4" | bc) -eq 1 ]; then \
        docker-php-ext-configure gd --with-freetype --with-jpeg ; \
    else \
        docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr ; \
    fi && \
    docker-php-ext-install -j$(nproc) \
        bcmath \
        mysqli \
        pdo \
        pdo_mysql \
        bz2 \
        gd \
        exif \
        opcache \
        && \
    docker-php-source delete && \
    # php configurations
    mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" && \
    # Memory, Time, Size Limits
    #   You can limit these at your orchestration layer.
    echo "memory_limit=2048M" > $PHP_INI_DIR/conf.d/memory-limit.ini && \
    echo "max_execution_time=900" >> $PHP_INI_DIR/conf.d/memory-limit.ini && \
    echo "post_max_size=20M" >> $PHP_INI_DIR/conf.d/memory-limit.ini && \
    echo "upload_max_filesize=20M" >> $PHP_INI_DIR/conf.d/memory-limit.ini && \
    # Time Zone
    echo "date.timezone=${PHP_TIMEZONE:-UTC}" > $PHP_INI_DIR/conf.d/date_timezone.ini && \
    # Display errors in stderr
    echo "display_errors=stderr" > $PHP_INI_DIR/conf.d/display-errors.ini && \
    # Disable PathInfo
    echo "cgi.fix_pathinfo=0" > $PHP_INI_DIR/conf.d/path-info.ini && \
    # Disable expose PHP
    echo "expose_php=0" > $PHP_INI_DIR/conf.d/path-info.ini && \    
    # composer
    curl -sS https://getcomposer.org/installer | php -- --quiet --install-dir=/usr/local/bin --filename=composer && \
    # clean up
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /usr/share/nginx/html/*

### ----------------------------------------------------------
### Load our app
### ----------------------------------------------------------

COPY public /usr/share/nginx/html
COPY . /var/www/html

RUN mkdir /docker-entrypoint.d
RUN mkdir -p /var/log/supervisor

RUN set -x && \
    # We don't need hirak/prestissimo since composer 2
    # if [ $(echo "${VERSION_PHP_MINOR} <= 7" | bc) -eq 1 ]; then \
    #     composer global require hirak/prestissimo ; \
    # fi && \
    if [ -f "/var/www/html/composer.lock" ]; then \
        if [ "${APP_ENV}" == "development" ] || [ "${APP_ENV}" == "dev" || "${APP_ENV}" == "staging" ] || [ "${APP_ENV}" == "stage" ]; then \
            composer install --working-dir=/var/www/html ; \
        else \
            composer install --no-dev --working-dir=/var/www/html ; \
        fi \
    fi && \
    # resolve: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
    touch /var/www/html/storage/logs/laravel.log && \
    touch /var/log/cron.log && \
    # please remove this APP_KEY generate for your production usage
    #   - ref: https://tighten.co/blog/app-key-and-you/
    php artisan key:generate && \     
    chown -R www-data:www-data /usr/share/nginx/html && \
    chown -R www-data:www-data /var/www/html && \
    find /var/www/html/storage -type f -exec chmod 664 {} \; && \
    find /var/www/html/storage -type d -exec chmod 770 {} \;




COPY scripts/docker-entrypoint.sh /
COPY scripts/10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
COPY scripts/20-envsubst-on-templates.sh /docker-entrypoint.d
COPY scripts/30-tune-worker-processes.sh /docker-entrypoint.d

COPY conf/nginx/nginx-site.conf /etc/nginx/nginx.conf
COPY conf/nginx/nginx-site.conf /etc/nginx/conf.d/default.conf

USER root
RUN mkdir -p -m 0700 /root/.ssh

RUN chmod -R 777 /var/run

EXPOSE 7860

CMD ["/docker-entrypoint.sh"]