Skip to content

Commit a2368b3

Browse files
committed
feat:terraform module added
1 parent 53022fa commit a2368b3

22 files changed

+5277
-66
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,6 @@ coverage/
9191

9292
composer.phar
9393

94-
.phpunit.result.cache
94+
.phpunit.result.cache
95+
96+
.terraform

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ services:
5151
environment:
5252
MYSQL_DATABASE: ${DB_DATABASE}
5353
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
54-
MYSQL_PASSWORD: ${DB_PASSWORD}
55-
MYSQL_USER: ${DB_USERNAME}
5654
SERVICE_TAGS: dev
5755
SERVICE_NAME: mysql
5856
volumes:

docker/nginx/nginx.ecs.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
server {
2+
listen 80;
3+
index index.php;
4+
root /var/www/public;
5+
6+
client_max_body_size 51g;
7+
client_body_buffer_size 512k;
8+
client_body_in_file_only clean;
9+
10+
location ~ \.php$ {
11+
try_files $uri =404;
12+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
13+
fastcgi_pass localhost:9000;
14+
fastcgi_index index.php;
15+
include fastcgi_params;
16+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
17+
fastcgi_param PATH_INFO $fastcgi_path_info;
18+
}
19+
20+
location / {
21+
try_files $uri $uri/ /index.php?$query_string;
22+
gzip_static on;
23+
}
24+
25+
error_log /var/log/nginx/error.log;
26+
access_log /var/log/nginx/access.log;
27+
}

docker/nginx/nginx.prod.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ server {
3434
location ~ \.php$ {
3535
try_files $uri =404;
3636
fastcgi_split_path_info ^(.+\.php)(/.+)$;
37-
fastcgi_pass app:9000;
37+
fastcgi_pass localhost:9000;
3838
fastcgi_index index.php;
3939
include fastcgi_params;
4040
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

docker/php/Dockerfile.prod

Lines changed: 156 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,167 @@
1-
FROM php:8.2-fpm-alpine
1+
FROM php:8.1-fpm-alpine as php-base
22

3-
# Set working directory
4-
WORKDIR /var/www
5-
6-
# Install system dependencies and dev packages
7-
RUN apk add --no-cache \
8-
git \
9-
curl \
10-
libpng-dev \
11-
libxml2-dev \
12-
zip \
13-
unzip \
14-
mysql-client \
15-
supervisor \
16-
nginx \
17-
freetype-dev \
18-
libjpeg-turbo-dev \
19-
libwebp-dev \
20-
zlib-dev \
21-
libxpm-dev \
22-
oniguruma-dev
23-
24-
# Configure GD extension
25-
RUN docker-php-ext-configure gd \
26-
--with-freetype \
27-
--with-jpeg \
28-
--with-webp
29-
30-
# Install PHP extensions
31-
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd xml
32-
33-
# Clear cache
34-
RUN rm -rf /var/cache/apk/*
35-
36-
# Install Redis extension
37-
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
38-
&& pecl install redis \
39-
&& docker-php-ext-enable redis \
40-
&& apk del .build-deps
41-
42-
# Install Composer
43-
COPY --from=composer:2.7 /usr/bin/composer /usr/bin/composer
3+
LABEL Description="Production PHP image with Nginx and PHP-FPM"
4+
LABEL Vendor="PHP"
5+
LABEL Version=1.0
6+
7+
# Install system dependencies
8+
RUN apk add --update --no-cache \
9+
bash \
10+
curl \
11+
shadow \
12+
icu-libs \
13+
libintl \
14+
libzip \
15+
aria2 \
16+
gettext \
17+
patch \
18+
nginx \
19+
supervisor
20+
21+
# Install runtime libraries for GD extension
22+
RUN apk add --update --no-cache \
23+
freetype \
24+
libjpeg-turbo \
25+
libpng \
26+
libwebp
27+
28+
# Install build dependencies
29+
RUN apk add --update --no-cache --virtual .docker-php-global-dependancies \
30+
freetype-dev \
31+
libjpeg-turbo-dev \
32+
libpng-dev \
33+
libwebp-dev \
34+
gettext-dev \
35+
gmp-dev \
36+
icu-dev \
37+
oniguruma-dev \
38+
libxml2-dev \
39+
ldb-dev \
40+
libzip-dev \
41+
autoconf \
42+
g++ \
43+
make \
44+
pcre-dev \
45+
wget
46+
47+
# Install php extensions
48+
RUN php -m && \
49+
docker-php-ext-configure bcmath --enable-bcmath && \
50+
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp && \
51+
docker-php-ext-configure gettext && \
52+
docker-php-ext-configure gmp && \
53+
docker-php-ext-configure intl --enable-intl && \
54+
docker-php-ext-configure mbstring --enable-mbstring && \
55+
docker-php-ext-configure opcache --enable-opcache && \
56+
docker-php-ext-configure pcntl --enable-pcntl && \
57+
docker-php-ext-configure soap && \
58+
docker-php-ext-configure zip && \
59+
docker-php-ext-install bcmath \
60+
gd \
61+
gettext \
62+
gmp \
63+
intl \
64+
mbstring \
65+
opcache \
66+
pcntl \
67+
soap \
68+
dom \
69+
xml \
70+
zip && \
71+
php -m
72+
73+
# Enable CURL
74+
RUN apk add --update --no-cache curl && \
75+
apk add --update --no-cache --virtual .curl-build-deps curl-dev && \
76+
docker-php-ext-install curl && \
77+
apk del .curl-build-deps && \
78+
php -m
79+
80+
# Enable MCRYPT
81+
RUN apk add --update --no-cache libmcrypt && \
82+
apk add --update --no-cache --virtual .mcrypt-build-deps libmcrypt-dev && \
83+
pecl install mcrypt && \
84+
docker-php-ext-enable mcrypt && \
85+
apk del .mcrypt-build-deps && \
86+
php -m
87+
88+
# Enable MySQL
89+
RUN apk add --update --no-cache --virtual .docker-php-mysql-dependancies \
90+
mysql-client && \
91+
docker-php-ext-configure mysqli && \
92+
docker-php-ext-configure pdo_mysql && \
93+
docker-php-ext-install mysqli \
94+
pdo_mysql && \
95+
apk del .docker-php-mysql-dependancies && \
96+
php -m
97+
98+
# Enable Redis
99+
RUN pecl install redis && \
100+
docker-php-ext-enable redis && \
101+
php -m
102+
103+
# Enable composer
104+
RUN php -r "readfile('https://getcomposer.org/installer');" | \
105+
php -- --install-dir=/usr/bin/ --filename=composer
106+
107+
# Clean up build dependencies
108+
RUN apk del .docker-php-global-dependancies && \
109+
rm -rf /var/cache/apk/* && \
110+
docker-php-source delete
111+
112+
# Production build
113+
FROM php-base as php-production
114+
115+
ARG LARAVEL_WORK_DIR='/var/www'
44116

45117
# Copy application files
46-
COPY . /var/www
47-
COPY docker/nginx/nginx.prod.conf /etc/nginx/nginx.conf
48-
COPY docker/php/php.prod.ini /usr/local/etc/php/conf.d/local.ini
49-
COPY docker/supervisor/supervisord.conf /etc/supervisord.conf
118+
COPY ./ /var/www/
119+
COPY ./docker/php/custom.ini /usr/local/etc/php/conf.d/custom.ini
120+
COPY ./docker/php/startup.sh /usr/local/bin/startup.sh
121+
122+
# Copy Nginx configuration
123+
COPY ./docker/nginx/nginx.prod.conf /etc/nginx/http.d/default.conf
124+
125+
# Copy supervisor configuration
126+
COPY ./docker/supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
127+
128+
# Set working directory
129+
WORKDIR $LARAVEL_WORK_DIR
130+
131+
# Install composer dependencies
132+
RUN composer install --no-dev --optimize-autoloader
133+
134+
# Publish vendor assets
135+
RUN php artisan vendor:publish --tag=public
50136

51137
# Set permissions
52-
RUN chown -R www-data:www-data /var/www \
53-
&& chmod -R 755 /var/www/storage \
54-
&& chmod -R 755 /var/www/bootstrap/cache
138+
RUN chown -R root:root $LARAVEL_WORK_DIR
139+
RUN rm -Rf /var/www/docker /root/.composer/
55140

56-
# Install dependencies
57-
RUN composer install --optimize-autoloader --no-dev --no-interaction --prefer-dist
141+
# Setup user and permissions
142+
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data \
143+
&& mkdir -p /home/www-data/.composer/cache \
144+
&& mkdir -p /var/log/php \
145+
&& touch /var/log/php/php_error.log \
146+
&& touch /var/log/php/php-fpm-access.log \
147+
&& touch /var/log/php/php-fpm-error.log \
148+
&& touch /var/log/php/php-cli-error.log \
149+
&& find /var/log/php -type f -exec chmod 755 {} \; \
150+
&& chown -R www-data:www-data /home/www-data /var/www
58151

59-
# Install Node.js and build assets
60-
RUN apk add --no-cache nodejs npm
61-
RUN npm install && npm run build && rm -rf node_modules
152+
# Create Laravel storage directories
153+
RUN mkdir -p ${LARAVEL_WORK_DIR}/storage/framework/sessions && \
154+
mkdir -p ${LARAVEL_WORK_DIR}/storage/framework/views && \
155+
mkdir -p ${LARAVEL_WORK_DIR}/storage/framework/cache && \
156+
mkdir -p ${LARAVEL_WORK_DIR}/storage/key && \
157+
mkdir -p ${LARAVEL_WORK_DIR}/storage/logs && \
158+
chmod -R 777 ${LARAVEL_WORK_DIR}/storage && \
159+
chmod -R 777 ${LARAVEL_WORK_DIR}/bootstrap
62160

63-
# Generate application key and optimize
64-
RUN php artisan config:cache \
65-
&& php artisan route:cache \
66-
&& php artisan view:cache
161+
# Create nginx directories
162+
RUN mkdir -p /var/log/nginx && \
163+
chown -R www-data:www-data /var/log/nginx
67164

68-
# Expose port
69165
EXPOSE 80
70166

71-
# Start supervisor
72-
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
167+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

docker/supervisor/supervisord.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[supervisord]
22
nodaemon=true
33
user=root
4-
logfile=/var/log/supervisor/supervisord.log
4+
logfile=/dev/stdout
5+
logfile_maxbytes=0
56
pidfile=/var/run/supervisord.pid
67

78
[program:nginx]

0 commit comments

Comments
 (0)