Docker
This commit is contained in:
parent
866eee5b16
commit
d2ea5ab548
74
Dockerfile
Normal file
74
Dockerfile
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# Use PHP with Apache as the base image
|
||||||
|
FROM php:8.3-apache
|
||||||
|
|
||||||
|
# Timezone
|
||||||
|
ENV TZ="Europe/Prague"
|
||||||
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
RUN printf '[Date]\ndate.timezone="%s"\n', $TZ > /usr/local/etc/php/conf.d/tzone.ini
|
||||||
|
|
||||||
|
# PHP
|
||||||
|
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
||||||
|
RUN sed -i "s|memory_limit = 128M|memory_limit = 256M |g" /etc/sysctl.conf
|
||||||
|
RUN sed -i "s|upload_max_filesize = 2M|upload_max_filesize = 100M |g" /etc/sysctl.conf
|
||||||
|
RUN sed -i "s|post_max_size = 8M|post_max_size = 100M |g" /etc/sysctl.conf
|
||||||
|
|
||||||
|
# Install Additional System Dependencies
|
||||||
|
RUN apt-get update && apt-get upgrade -y
|
||||||
|
RUN apt-get install -y \
|
||||||
|
libzip-dev \
|
||||||
|
zip \
|
||||||
|
nodejs \
|
||||||
|
npm \
|
||||||
|
cron \
|
||||||
|
nano \
|
||||||
|
default-mysql-client
|
||||||
|
|
||||||
|
# Clear cache
|
||||||
|
RUN apt-get autoremove
|
||||||
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Enable Apache mod_rewrite for URL rewriting
|
||||||
|
RUN a2enmod rewrite
|
||||||
|
|
||||||
|
# Install PHP extensions
|
||||||
|
RUN docker-php-ext-install pdo_mysql zip
|
||||||
|
|
||||||
|
# Configure Apache DocumentRoot to point to Laravel's public directory
|
||||||
|
# and update Apache configuration files
|
||||||
|
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
|
||||||
|
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
|
||||||
|
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
|
||||||
|
|
||||||
|
# Copy the application code
|
||||||
|
COPY . /var/www/html
|
||||||
|
|
||||||
|
# Install composer
|
||||||
|
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||||
|
|
||||||
|
# Install project dependencies
|
||||||
|
RUN composer install --quiet --prefer-dist --no-dev -o
|
||||||
|
RUN npm install && npm run build
|
||||||
|
|
||||||
|
# Setup Crone
|
||||||
|
RUN mkdir -p /var/log/cron
|
||||||
|
RUN echo "* * * * * www-data cd /var/www/html && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1" >> /etc/crontab
|
||||||
|
RUN echo "* * * * * www-data cd /var/www/html && /usr/local/bin/php artisan queue:work --queue=default --stop-when-empty >> /dev/null 2>&1" >> /etc/crontab
|
||||||
|
RUN echo "#" >> /etc/crontab
|
||||||
|
|
||||||
|
# Add a command to base-image entrypont scritp
|
||||||
|
RUN sed -i 's/^exec /printenv > \/etc\/environment\n\nexec /' /usr/local/bin/apache2-foreground
|
||||||
|
RUN sed -i 's/^exec /service cron start\n\nexec /' /usr/local/bin/apache2-foreground
|
||||||
|
|
||||||
|
#Start Container
|
||||||
|
RUN chmod +x /var/www/html/start.sh
|
||||||
|
CMD ["/var/www/html/start.sh"]
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
VOLUME /var/www/html/storage/app/app
|
||||||
|
|
||||||
|
RUN mkdir -p /config
|
||||||
|
VOLUME /config
|
||||||
|
|
||||||
|
# Start Apache
|
||||||
|
WORKDIR /var/www/html/
|
||||||
|
|
1
public/version.txt
Normal file
1
public/version.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.0.1
|
50
start.sh
Normal file
50
start.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# Install project dependencies
|
||||||
|
composer install --quiet --prefer-dist --no-dev -o
|
||||||
|
npm install
|
||||||
|
|
||||||
|
init=false
|
||||||
|
if ! test -f /config/.env; then
|
||||||
|
# Create Env File
|
||||||
|
cp .env.example .env
|
||||||
|
php artisan key:generate
|
||||||
|
|
||||||
|
cp .env /config/.env
|
||||||
|
|
||||||
|
init=true
|
||||||
|
echo "Initialization"
|
||||||
|
else
|
||||||
|
cp /config/.env .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $(grep -ic "DB_CONNECTION=sqlite" /var/www/html/.env) -gt 0 ] || [ "${DEPLOY_ENV}" == "sqlite"]; then
|
||||||
|
if ! test -f "/var/www/html/database/database.sqlite" ; then
|
||||||
|
echo " DB Initialization"
|
||||||
|
init=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Migrate Database
|
||||||
|
php artisan migrate --force --no-interaction
|
||||||
|
|
||||||
|
# Link storage and create default user
|
||||||
|
if [ "$init" = true ]; then
|
||||||
|
echo "Initialization of Laravel"
|
||||||
|
php artisan db:seed --force --class=DatabaseSeeder
|
||||||
|
php artisan storage:link
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clear Cashes
|
||||||
|
php artisan cache:clear
|
||||||
|
php artisan config:clear
|
||||||
|
php artisan route:clear
|
||||||
|
php artisan view:clear
|
||||||
|
|
||||||
|
# fix permissions
|
||||||
|
chown -R www-data:www-data /var/www/html
|
||||||
|
find /var/www/html -type f -not -name "*.sh" -exec chmod 664 {} +
|
||||||
|
find /var/www/html -type d -exec chmod 775 {} +
|
||||||
|
|
||||||
|
# Start Apache
|
||||||
|
apache2-foreground
|
||||||
|
|
Loading…
Reference in New Issue
Block a user