Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Docker :)
  • Loading branch information
NaysKutzu committed Nov 23, 2024
1 parent cf26597 commit dd48154
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dockerfiles/mariadb/data
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/storage/packages
43 changes: 43 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM php:8.3-fpm

WORKDIR /var/www/html

# Install system dependencies and PHP extensions
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libxml2-dev \
libzip-dev \
libonig-dev \
libcurl4-openssl-dev \
zip \
unzip \
git \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
gd \
pdo \
pdo_mysql \
mysqli \
bcmath \
xml \
mbstring \
curl \
zip

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Copy composer files first to leverage Docker cache
COPY composer.json composer.lock ./

# Install dependencies
RUN cd /var/www/html && COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader

# Copy rest of the application
COPY . .

# Set permissions
RUN chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html
15 changes: 15 additions & 0 deletions backend/mythicalclient
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use MythicalClient\Cli\App;
define("ENV_PATH", __DIR__ . "/storage/");
define('APP_START', microtime(true));
define('APP_DIR', __DIR__ );

require_once __DIR__ . "/boot/kernel.php";

try {
$args = array_slice($argv, 1); // Exclude the command name and the first argument
new App(isset($argv[1]) ? $argv[1] : '', $args);
} catch (Exception $e) {
echo $e->getMessage();
}
7 changes: 4 additions & 3 deletions backend/storage/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
DATABASE_HOST=127.0.0.1
DATABASE_HOST=mythical_database
DATABASE_PORT=3306
DATABASE_USER=mythical
DATABASE_PASSWORD=efwefwefwe
DATABASE_PASSWORD="Pizza2007!"
DATABASE_DATABASE=mythicalclient
DATABASE_ENCRYPTION=xchacha20
DATABASE_ENCRYPTION_KEY="zKZ7//AocUD2wCuzjW5rdTbb8FvGBgKTZ8iCATslZ/8="
DATABASE_ENCRYPTION_KEY="zKZ7//AocUD2wCuzjW5rdTbb8FvGBgKTZ8iCATslZ/8="
REDIS_PASSWORD="eufefwefwefw"
104 changes: 74 additions & 30 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,90 @@
version: '3.8'

services:
php:
# Frontend Vue service
mythical_frontend:
build:
context: ./dockerfiles/php
restart: unless-stopped
context: ./frontend
dockerfile: Dockerfile
container_name: mythical_frontend
volumes:
- .:/var/www/
expose:
- 9000
depends_on:
database:
condition: service_healthy
env_file: ./backend/storage/.env
extra_hosts:
host.docker.internal: host-gateway
- ./frontend:/app
- /app/node_modules
networks:
- mythical_network

frontend:
build:
context: .
dockerfile: ./dockerfiles/frontend
# PHP Backend service with PHP-FPM
mythical_backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: mythical_backend
volumes:
- ./:/var/www/
restart: unless-stopped
- ./backend:/var/www/html
- ./backend/vendor:/var/www/html/vendor
depends_on:
- mythical_database
networks:
- mythical_network

composer:
image: composer:latest
working_dir: /var/www/
# Main Nginx service
mythical_nginx:
image: nginx:alpine
container_name: mythical_nginx
ports:
- "8080:80"
volumes:
- .:/var/www
entrypoint: ["composer", "--ignore-platform-reqs", "--no-progress", "--no-dev", "--optimize-autoloader"]
command: ["install"]

database:
image: mariadb:10.5
- ./backend:/var/www/html
- ./framework.conf:/etc/nginx/conf.d/default.conf
depends_on:
- mythical_frontend
- mythical_backend
networks:
- mythical_network

mythical_database:
image: mariadb:latest
restart: unless-stopped
container_name: mythical_database
volumes:
- ./dockerfiles/mariadb/data:/var/lib/mysql
- ./dockerfiles/mariadb/data:/var/lib/mysql/
ports:
- 3306:3306
- 33060:33060
env_file:
- ./backend/storage/.env
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "true"
MARIADB_ROOT_PASSWORD: "superlongquiery!!password"
MARIADB_DATABASE: ${DATABASE_DATABASE}
MARIADB_USER: ${DATABASE_USER}
MARIADB_PASSWORD: ${DATABASE_PASSWORD}
MARIADB_PASSWORD: ${DATABASE_PASSWORD}
healthcheck:
test: mysqladmin ping -u$$MARIADB_USER -p$$MARIADB_PASSWORD
interval: 5s
timeout: 5s
retries: 20
networks:
- mythical_network

mythical_redis:
image: redis:7.0-alpine
container_name: mythical_redis
restart: unless-stopped
command: redis-server --save 60 1 --loglevel notice --requirepass '${REDIS_PASSWORD}'
env_file:
- ./backend/storage/.env
ports:
- 6379:6379
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD}
healthcheck:
test: redis-cli -a $$REDIS_PASSWORD ping | grep PONG
interval: 5s
timeout: 5s
retries: 20
networks:
- mythical_network

networks:
mythical_network:
driver: bridge
9 changes: 0 additions & 9 deletions dockerfiles/frontend/Dockerfile

This file was deleted.

Empty file removed dockerfiles/mariadb/.gitignore
Empty file.
7 changes: 0 additions & 7 deletions dockerfiles/php/Dockerfile

This file was deleted.

35 changes: 35 additions & 0 deletions framework.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
server {
listen 80;
server_name framework.mythical.systems;

# Root directory for PHP backend
root /var/www/html/public;
index index.php index.html index.htm;

# Location for the PHP backend (handles all /api requests and PHP files)
location /api {
try_files $uri $uri/ /index.php;
}

# General PHP script handling (via PHP-FPM)
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass mythical_backend:9000; # PHP-FPM is running here
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

# Location for the frontend
location / {
proxy_pass http://mythical_frontend:80; # Replace 'frontend:80' with your frontend service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# Deny access to sensitive files
location ~ /\.(ht|git|svn) {
deny all;
}
}
1 change: 1 addition & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
13 changes: 13 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Build stage
FROM node:20 as build-stage
WORKDIR /app
COPY package*.json ./
RUN yarn install
COPY . .
RUN yarn run build

# Production stage
FROM nginx:alpine
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
17 changes: 8 additions & 9 deletions frontend/src/mythicalclient/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Swal from 'sweetalert2';

class Settings {
static settings = {};

Expand Down Expand Up @@ -28,13 +26,14 @@ class Settings {
}
} catch (error) {
console.error('Failed to initialize settings:', error);
Swal.fire({
icon: 'error',
title: 'Failed to initialize session!',
text: 'It looks like something went really wrong. Please try again later or contact the webmaster.',
}).then(() => {
document.body.innerHTML = '<h1>We are so sorry but our backend is down at this moment :(</h1>';
});
document.body.innerHTML = `
<div style="display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f8d7da; color: #721c24; font-family: Arial, sans-serif;">
<div style="text-align: center;">
<h1 style="font-size: 3em; margin-bottom: 0.5em;">We are so sorry</h1>
<p style="font-size: 1.5em;">Our backend is down at this moment :(</p>
</div>
</div>
`;
}
}

Expand Down
18 changes: 9 additions & 9 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
server: {
proxy: {
'/api': {
target: 'http://localhost:9000',
changeOrigin: true,
rewrite: (path) => path
}
}
}
// server: {
// proxy: {
// '/api': {
// target: 'http://localhost:9000',
// changeOrigin: true,
// rewrite: (path) => path
// }
// }
// }
})

0 comments on commit dd48154

Please sign in to comment.