forked from Joweb1/Antigravity-Ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (62 loc) · 3.12 KB
/
Dockerfile
File metadata and controls
83 lines (62 loc) · 3.12 KB
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
# Dockerfile
FROM php:8.4-apache
# 1. Install system dependencies and unzip (crucial for unpacking the artifact)
RUN apt-get update && apt-get install -y \
unzip \
libzip-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# 2. Install PHP extensions
# Using the standard mlocati installer script
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions
RUN install-php-extensions gd mbstring xml zip pdo_mysql opcache intl
# 3. Configure Apache to allow .htaccess rewrites
RUN a2enmod rewrite
# 4. Setup Working Directory
# We will use /var/www as the base.
# Apache looks at /var/www/html by default.
WORKDIR /var/www
# 5. Copy the Zipped Project from the build context
# The CI/CD pipeline will place 'release.zip' here
COPY release.zip .
# 6. Unzip and Setup "Shared Hosting" Structure
# We unzip into 'laravel-app' folder, parallel to 'html'
RUN unzip release.zip -d laravel-app && \
rm release.zip
# 7. Move Public files to Main Directory (Apache Root)
# Clean default html folder
RUN rm -rf html/*
# Move contents of public to html
RUN cp -r laravel-app/public/* html/
# Ensure .htaccess is moved (cp -r usually catches it, but explicit checks are safer)
RUN cp laravel-app/public/.htaccess html/
# 8. Modify index.php to point to the new paths
# We use sed to replace the relative paths to point up one level into 'laravel-app'
WORKDIR /var/www/html
RUN sed -i "s|require __DIR__.'/../vendor/autoload.php';|require __DIR__.'/../laravel-app/vendor/autoload.php';|g" index.php && \
sed -i "s|\$app = require_once __DIR__.'/../bootstrap/app.php';|\$app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';|g" index.php
# 9. Create Production .env
# NOTE: It is better security practice to use Environment Variables injected by Render.
# However, this creates the file as requested.
RUN echo "APP_ENV=production" > ../laravel-app/.env && \
echo "APP_DEBUG=false" >> ../laravel-app/.env && \
echo "APP_URL=https://antigravity-ecommerce-ql94.onrender.com" >> ../laravel-app/.env && \
echo "LOG_CHANNEL=stderr" >> ../laravel-app/.env
# 10. Permissions and Storage Linking
# Fix permissions for the app code
RUN chown -R www-data:www-data /var/www/laravel-app \
&& chown -R www-data:www-data /var/www/html
# Set directory permissions to 755 and files to 644
RUN find /var/www/laravel-app -type d -exec chmod 755 {} + \
&& find /var/www/laravel-app -type f -exec chmod 644 {} +
# Link the storage folder (Simulating 'php artisan storage:link' but manually for this structure)
# We link html/storage -> ../laravel-app/storage/app/public
RUN rm -rf /var/www/html/storage && \
ln -s /var/www/laravel-app/storage/app/public /var/www/html/storage
# 11. Final Apache Permissions
RUN chown -h www-data:www-data /var/www/html/storage
# Final permissions fix for Laravel Storage and Cache
RUN chown -R www-data:www-data /var/www/laravel-app/storage /var/www/laravel-app/bootstrap/cache \
&& chmod -R 777 /var/www/laravel-app/storage /var/www/laravel-app/bootstrap/cache
EXPOSE 80
CMD ["apache2-foreground"]