Skip to content

Commit

Permalink
Merge pull request #2 from asefsoft/dockerizing
Browse files Browse the repository at this point in the history
Dockerizing
  • Loading branch information
asefsoft authored Jun 14, 2024
2 parents 3aaa9c4 + 8ead10a commit 8948e57
Show file tree
Hide file tree
Showing 298 changed files with 1,155 additions and 42 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
src/.env
src/node_modules
src/vendor
src/storage/logs
src/storage/app/livewire-tmp
src/storage/faramwork/cache
src/storage/faramwork/sessions
src/storage/faramwork/testing
src/storage/faramwork/views
src/storage/tv_shows.index
src/tests/test.db
src/tests/tv_shows.index
src/.phpunit.result.cache
23 changes: 23 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
IMAGE_TAG=
COMPOSE_PROJECT_NAME=tv-alert

# Laravel app envs
DB_PASSWORD=2wdr5thu8ilp
APP_URL=http://localhost:3838
# {local, production}
APP_ENV=local
APP_DEBUG=true

MAIL_MAILER=smtp
MAIL_HOST=host.docker.internal
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="series-alert.ir"
# set false for staging, true for main
MAIL_VERIFY_PEER=false

SESSION_DRIVER=database
SESSION_DOMAIN=localhost
5 changes: 5 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
laravel-tests:

runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
Expand All @@ -24,6 +27,8 @@ jobs:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.git-ref }}
- name: make test.db
run: touch tests/test.db
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
Expand Down
22 changes: 1 addition & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
/tests/test.db
/tests/*.index
/tv-alert.rar
/storage/*.index
.git
7 changes: 7 additions & 0 deletions Dockerfile.mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM mysql:8.2

ARG password

COPY ./deployment/config/mysql/create_database.sql /docker-entrypoint-initdb.d/create_database.sql
RUN echo "ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '${password}';" >> /docker-entrypoint-initdb.d/set_native_password.sql
COPY ./deployment/config/mysql/mysql.cnf /etc/mysql/conf.d/mysql.cnf
6 changes: 6 additions & 0 deletions Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:1.25.4-alpine

COPY ./src /usr/src
COPY ./deployment/config/nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You can see live version of this app here: [Series Alert](https://series-alert.i
- **Automate TV Show updates:** Fully automatically scan for new shows and get info of current shows in the background.
- **Data Transfer Objects:** Utilizes the Laravel Data package to efficiently manage data transfer objects.
- **Tested Codebase:** The project is fully tested with PHPUnit and analyzed by PHPInsights, ensuring reliability and stability.
- **Dockerized:** The project is dockerized and can become up and running very fast.

### Timeline
This is an example of your timeline in site:
Expand All @@ -41,6 +42,28 @@ This is an example of your timeline in site:
- PHPUnit: The codebase is rigorously tested with PHPUnit.
- GitHub Actions: Automatic testing and continuous integration are enabled with GitHub Actions.

## Docker run
This project is Dockerized, allowing you to easily run it with the following command:

``docker-compose up``

This will make the project accessible at `localhost:3838`.

### Configuration
Before running the project with Docker, consider customizing the `.env` file located in the project root directory. This file allows you to configure settings based on your needs.

Also, you can have more settings in the `.env.example` file in the `src` directory.

### Deployment
For deployment purposes, refer to the `deployment` directory. This directory contains various configuration files for MySQL, Nginx, and PHP-fpm.

### Docker Services
The `docker-compose.yml` file defines several services that work together to run this application:
* app: The laravel backend app, built on a PHP-FPM Docker image.
* scheduler: This service is essentially a copy of the app service, but its purpose is solely to run the Laravel scheduler. This allows the scheduler to crawl for TV series data without interfering with the main app functionality.
* mysql: Database service that stores the application's data. It utilizes a separate storage volume named `mysql-data` for persistence.
* nginx: Web server that handles incoming web requests and directs them to the app service.

## Deep inside the code
In this article, I explain how I implemented Laravel Scout along with TNTSearch to enhance the project's search capabilities:

Expand Down
11 changes: 0 additions & 11 deletions config/tvshow.php

This file was deleted.

1 change: 1 addition & 0 deletions deployment/config/mysql/create_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE tvalert;
5 changes: 5 additions & 0 deletions deployment/config/mysql/mysql.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mysqld]
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow.log
long_query_time=0.4
sort_buffer_size=3M
34 changes: 34 additions & 0 deletions deployment/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
worker_processes auto;

events {
worker_connections 1024;
}

http {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
include /etc/nginx/mime.types;

gzip on;
gzip_comp_level 4;
gzip_types text/css application/javascript image/jpeg image/png;

server {
listen 80;
server_name series-alert.ir;
root /usr/src/public;
index index.php index.html;

location ~\.php {
try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}

location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
}
17 changes: 17 additions & 0 deletions deployment/config/php-fpm/php-dev.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[opcache]
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.validate_timestamps=0
opcache.revalidate_freq=10

;extension=redis.so

log_errors = On
error_log = /dev/stderr
display_errors = On
display_startup_errors = On
error_reporting = E_ALL

max_execution_time = 30
memory_limit = 128M
17 changes: 17 additions & 0 deletions deployment/config/php-fpm/php-prod.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[opcache]
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.validate_timestamps=0
opcache.revalidate_freq=60

;extension=redis.so

log_errors = On
error_log = /dev/stderr
display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

max_execution_time = 30
memory_limit = 128M
Loading

0 comments on commit 8948e57

Please sign in to comment.