This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
140 lines (108 loc) · 3.55 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
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
FROM debian:buster-slim
#### DEFINING VARS
ARG php_version=7.3
ARG php_fpm_path="/etc/php/${php_version}/fpm/"
ARG php_fpm_pool_path="/etc/php/${php_version}/fpm/pool.d/"
#### LARAVEL OPERATIONS
RUN apt-get update
# Installing system packages
RUN apt-get install -y -qq --force-yes \
nano \
lsb-base \
php${php_version}-fpm \
--no-install-recommends > /dev/null
# Installing packages for Laravel
RUN apt-get install -y -qq --force-yes \
php${php_version}-bcmath \
php${php_version}-json \
php${php_version}-mbstring \
php${php_version}-tokenizer \
php${php_version}-xml \
php${php_version}-mysql \
php-redis \
--no-install-recommends > /dev/null
# Installing packages for our application
RUN apt-get install -y -qq --force-yes \
php-curl \
zbar-tools \
qrencode \
cron \
--no-install-recommends > /dev/null
# Installing temporary packages
RUN apt-get install -y -qq --force-yes \
composer \
git \
zip \
unzip \
php${php_version}-zip \
--no-install-recommends > /dev/null
#### CONFIGURING PHP-FPM
# CONFIGURING POOL
COPY .build/www.conf ${php_fpm_pool_path}/www.conf
RUN chown root:root ${php_fpm_pool_path}/www.conf
RUN chmod 644 ${php_fpm_pool_path}/www.conf
# CONFIGURING BASE
COPY .build/php.ini ${php_fpm_path}/php.ini
RUN chown root:root ${php_fpm_path}/php.ini
RUN chmod 644 ${php_fpm_path}/php.ini
####
# Creating a temporary folder for our app
RUN mkdir -p /tmp/laravel
# Download the entire project
COPY . /tmp/laravel/
# Create needed folders for composer autoloader optimization
RUN mkdir -p /app/database
RUN mkdir -p /app/database/seeds
RUN mkdir -p /app/database/factories
# Defining which packages Composer will install
RUN cp /tmp/laravel/composer.lock /app/composer.lock
RUN cp /tmp/laravel/composer.json /app/composer.json
# Please, Composer, install them
RUN composer install -d /app --no-dev --no-scripts
# Moving Laravel to the right place
RUN cp -r /tmp/laravel/* /app
RUN rm -rf /tmp/laravel
RUN touch /app/.env
# Setting the configurations values for Laravel
RUN cd /app && composer dump-autoload
# Deleting system temporary packages
RUN apt-get purge -y -qq --force-yes \
composer \
git \
zip \
unzip \
php${php_version}-zip \
> /dev/null
# Cleaning the system
RUN apt-get -y -qq --force-yes autoremove > /dev/null
# Changing permissions of the entire Laravel
RUN chown www-data:www-data -R /app
RUN find /app -type f -exec chmod 644 {} \;
RUN find /app -type d -exec chmod 755 {} \;
# Crafting the entrypoint script
RUN rm -rf /entrypoint.sh && touch /entrypoint.sh
RUN echo "#!/bin/bash" >> /entrypoint.sh
RUN echo "service cron start" >> /entrypoint.sh
RUN echo "service php${php_version}-fpm start" >> /entrypoint.sh
RUN echo "shopt -s dotglob" >> /entrypoint.sh
RUN echo "mkdir -p /var/www/" >> /entrypoint.sh
RUN echo "mv /app/* /var/www/" >> /entrypoint.sh
RUN echo "(crontab -l; echo '* * * * * cd /var/www && php artisan schedule:run >> /dev/null 2>&1';) | crontab -" >> /entrypoint.sh
RUN echo "touch /etc/crontab /etc/cron.*/*" >> /entrypoint.sh
RUN echo 'exec "$@"' >> /entrypoint.sh
RUN echo "php /var/www/artisan config:cache" >> /entrypoint.sh
RUN echo "php /var/www/artisan browscap:cache" >> /entrypoint.sh
RUN chown root:root /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Crafting the cmd script
RUN rm -rf /init.sh && touch /init.sh
RUN echo "#!/bin/bash" >> /init.sh
RUN echo "/bin/bash" >> /init.sh
RUN chown root:root /init.sh
RUN chmod +x /init.sh
# Gaining a bit of comfort
WORKDIR "/var/www"
EXPOSE 9000
# Executing the scripts
ENTRYPOINT ["/entrypoint.sh"]
CMD /init.sh