diff --git a/docker-compose.yml b/docker-compose.yml index 38a573c..9505673 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,15 +4,14 @@ volumes: db-data: services: - # Database Server - database: + ttp-database: container_name: TTP-MySQL image: mysql:8.0 ports: - ${DOCKER_DB_PORT}:3306 environment: MYSQL_ROOT_PASSWORD: ${DOCKER_DB_PASSWORD} - MYSQL_DATABASE: ${DB_DATABASE} + MYSQL_DATABASE: ${DOCKER_DB_DATABASE} MYSQL_USER: ${DOCKER_DB_USERNAME} MYSQL_PASSWORD: ${DOCKER_DB_PASSWORD} volumes: @@ -23,7 +22,7 @@ services: timeout: 10s retries: 10 - phpmyadmin: + ttp-phpmyadmin: container_name: TTP-PhpMyAdmin image: phpmyadmin:latest ports: @@ -32,56 +31,27 @@ services: environment: PMA_HOST: database depends_on: - database: + ttp-database: condition: service_healthy - # NGINX - webone: + + ttp-nginx: container_name: TTP-Nginx build: context: . - dockerfile: ./docker/Dockerfile - target: nginx - volumes: - - ./:/var/www/html - - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf + dockerfile: ./docker/ttp-nginx/Dockerfile + target: php-fpm ports: - "8080:80" - links: - - php - depends_on: - - php + environment: + - APP_ENV=${APP_ENV} - # apache - webtwo: + ttp-apache: container_name: TTP-Apache build: context: . - dockerfile: ./docker/Dockerfile + dockerfile: ./docker/ttp-apache/Dockerfile target: apache - volumes: - - ./:/var/www/html - - ./docker/apache.conf:/etc/apache2/sites-available/000-default.conf ports: - "8000:80" environment: - APP_ENV=${APP_ENV} - depends_on: - - php - - # php - php: - container_name: TTP-Php - build: - context: . - dockerfile: ./docker/Dockerfile - target: php-fpm - working_dir: /var/www/html - volumes: - - ./:/var/www/html - ports: - - "9000:9000" - environment: - - APP_ENV=${APP_ENV} - depends_on: - database: - condition: service_healthy diff --git a/docker/.env.example b/docker/.env.example index b792aaa..a814f07 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -1,6 +1,5 @@ APP_ENV = "docker" -DOCKER_APP_PORT = 8000 DOCKER_DB_PORT = 3306 DOCKER_DB_USERNAME = dbadmin DOCKER_DB_PASSWORD = secret -DB_DATABASE = ttp \ No newline at end of file +DOCKER_DB_DATABASE = ttp \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index c41f548..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM nginx:latest as nginx - -FROM php:8-fpm as php-fpm -RUN apt-get update -y -RUN apt-get install -y libmariadb-dev -RUN docker-php-ext-install mysqli pdo pdo_mysql - -FROM php:8-apache as apache -RUN a2enmod ssl && a2enmod rewrite -RUN docker-php-ext-install mysqli pdo pdo_mysql -WORKDIR /var/www/html \ No newline at end of file diff --git a/docker/apache.conf b/docker/apache.conf deleted file mode 100644 index 5267eab..0000000 --- a/docker/apache.conf +++ /dev/null @@ -1,11 +0,0 @@ -ServerName localhost - - ServerAdmin admin@localhost - DocumentRoot /var/www/html/ - - DirectoryIndex index.php - Options Indexes FollowSymLinks - AllowOverride All - Require all granted - - diff --git a/docker/nginx.conf b/docker/nginx.conf deleted file mode 100644 index b2a1718..0000000 --- a/docker/nginx.conf +++ /dev/null @@ -1,73 +0,0 @@ -server { - listen 80 default_server; - index index.php; - server_name TheTempusProject; - error_log /var/www/html/logs/nginx-error.log; - access_log /var/www/html/logs/nginx-access.log; - root /var/www/html; - charset utf-8; - sendfile off; - client_max_body_size 100m; - - location /js/ { - access_log off; - log_not_found off; - try_files $uri /index.php?error=js404&file=$uri; - } - - location /css/ { - access_log off; - log_not_found off; - try_files $uri /index.php?error=css404&file=$uri; - } - - location /images/ { - try_files $uri /index.php?error=image404&url=$uri; - } - - location /uploads/ { - try_files $uri /index.php?error=upload404&url=$uri; - } - - location /errors/ { - try_files $uri /index.php?error=$uri; - } - - location ~* \.(?:js|css|png|jpg|gif|ico)$ { - access_log off; - log_not_found off; - } - - location = /favicon.ico { - access_log off; - log_not_found off; - rewrite ^(.+)$ /images/favicon.ico break; - } - - location = /robots.txt { - allow all; - access_log off; - log_not_found off; - rewrite ^(.+)$ /bin/robots.txt break; - } - - location ~ \.php$ { - try_files $uri =404; - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass php:9000; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_intercept_errors off; - fastcgi_buffer_size 16k; - fastcgi_buffers 4 16k; - fastcgi_connect_timeout 60s; - fastcgi_read_timeout 60s; - fastcgi_send_timeout 60s; - } - - location / { - rewrite ^/(.+)$ /index.php?url=$1&$args last; - } -} \ No newline at end of file diff --git a/docker/ttp-apache/Dockerfile b/docker/ttp-apache/Dockerfile new file mode 100644 index 0000000..7a79f5c --- /dev/null +++ b/docker/ttp-apache/Dockerfile @@ -0,0 +1,13 @@ +FROM php:8-apache as apache +ENV COMPOSER_ALLOW_SUPERUSER=1 +RUN apt-get update -y +RUN apt-get install git libzip-dev -y +RUN a2enmod ssl && a2enmod rewrite +RUN docker-php-ext-install mysqli pdo pdo_mysql zip +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +# RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +WORKDIR /var/www +RUN rm -rf html/ +RUN composer create-project thetempusproject/thetempusproject html +RUN chmod -R 777 html/ +RUN chown -R www-data:www-data html/ \ No newline at end of file diff --git a/docker/ttp-apache/README.md b/docker/ttp-apache/README.md new file mode 100644 index 0000000..bcb25d5 --- /dev/null +++ b/docker/ttp-apache/README.md @@ -0,0 +1,19 @@ +Build the image +``` +docker build -t thetempusproject/ttp-apache:latest . +docker build --no-cache -t thetempusproject/ttp-apache:latest . +``` + + + +Set the proper tag for dockerhub +``` +docker tag ttp-apache:latest thetempusproject/ttp-apache:latest +``` + + + +Run the image +``` +docker run -d -p 80:80 thetempusproject/ttp-apache +``` \ No newline at end of file diff --git a/docker/ttp-nginx/Dockerfile b/docker/ttp-nginx/Dockerfile new file mode 100644 index 0000000..b5b2e9f --- /dev/null +++ b/docker/ttp-nginx/Dockerfile @@ -0,0 +1,29 @@ +FROM php:8-fpm as php-fpm + +# Env +ENV COMPOSER_ALLOW_SUPERUSER=1 + +# Install Packages +RUN apt-get update -y +RUN apt-get install -y nginx libmariadb-dev git libzip-dev zip unzip supervisor +RUN docker-php-ext-install mysqli pdo pdo_mysql zip + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +#Install TTP +WORKDIR /var/www +RUN rm -rf html/ +RUN composer create-project thetempusproject/thetempusproject html +RUN chmod -R 777 html/ +RUN chown -R www-data:www-data html/ + +# Copy Nginx configuration file +RUN cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old +COPY ./docker/ttp-nginx/nginx.conf /etc/nginx/nginx.conf + +# Copy Supervisor configuration file +COPY ./docker/ttp-nginx/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +# Start Supervisor, which will start both Nginx and PHP-FPM +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] \ No newline at end of file diff --git a/docker/ttp-nginx/README.md b/docker/ttp-nginx/README.md new file mode 100644 index 0000000..76c7657 --- /dev/null +++ b/docker/ttp-nginx/README.md @@ -0,0 +1,19 @@ +Build the image +``` +docker build -t thetempusproject/ttp-nginx:latest . +docker build --no-cache -t thetempusproject/ttp-nginx:latest . +``` + + + +Set the proper tag for dockerhub +``` +docker tag ttp-nginx:latest thetempusproject/ttp-nginx:latest +``` + + + +Run the image +``` +docker run -d -p 8000:80 thetempusproject/ttp-nginx +``` \ No newline at end of file diff --git a/docker/ttp-nginx/nginx.conf b/docker/ttp-nginx/nginx.conf new file mode 100644 index 0000000..07aaa2e --- /dev/null +++ b/docker/ttp-nginx/nginx.conf @@ -0,0 +1,90 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +error_log /var/log/nginx/error.log; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; +} + +http { + tcp_nopush on; + types_hash_max_size 2048; + include /etc/nginx/mime.types; + default_type application/octet-stream; + ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + access_log /var/log/nginx/access.log; + + gzip on; + server { + listen 80 default_server; + index index.php; + server_name TheTempusProject; + root /var/www/html; + charset utf-8; + sendfile on; + client_max_body_size 100m; + + location /js/ { + access_log off; + log_not_found off; + try_files $uri /index.php?error=js404&file=$uri; + } + + location /css/ { + try_files $uri /index.php?error=css404&file=$uri; + } + + location /images/ { + try_files $uri /index.php?error=image404&url=$uri; + } + + location /uploads/ { + try_files $uri /index.php?error=upload404&url=$uri; + } + + location /errors/ { + try_files $uri /index.php?error=$uri; + } + + location = /favicon.ico { + access_log off; + log_not_found off; + rewrite ^(.+)$ /images/favicon.ico break; + } + + location = /robots.txt { + allow all; + access_log off; + log_not_found off; + rewrite ^(.+)$ /bin/robots.txt break; + } + + location ~* \.(?:js|css|png|jpg|gif|ico)$ { + access_log off; + log_not_found off; + } + + location ~ \.php$ { + fastcgi_pass 127.0.0.1:9000; + include snippets/fastcgi-php.conf; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_intercept_errors off; + fastcgi_buffer_size 16k; + fastcgi_buffers 4 16k; + fastcgi_connect_timeout 60s; + fastcgi_read_timeout 60s; + fastcgi_send_timeout 60s; + } + + location / { + rewrite ^/(.+)$ /index.php?url=$1&$args last; + } + } + + include /etc/nginx/conf.d/*.conf; +} \ No newline at end of file diff --git a/docker/ttp-nginx/supervisord.conf b/docker/ttp-nginx/supervisord.conf new file mode 100644 index 0000000..46e1d7d --- /dev/null +++ b/docker/ttp-nginx/supervisord.conf @@ -0,0 +1,8 @@ +[supervisord] +nodaemon=true + +[program:php-fpm] +command=/usr/local/sbin/php-fpm + +[program:nginx] +command=/usr/sbin/nginx -g 'daemon off;' \ No newline at end of file