Skip to content

Commit

Permalink
Merge branch 'playground/game-app'
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltrolezi committed Sep 20, 2024
2 parents 2e91b9b + d553f5c commit 29ae990
Show file tree
Hide file tree
Showing 150 changed files with 8,373 additions and 537 deletions.
24 changes: 20 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
APP_NAME="Laravel App"
APP_VERSION=1.0
APP_URL=http://laravel-app.local
RUN_MODE=octane

APP_NAME="GameWatch"
APP_VERSION=1.0.0
APP_URL=http://gamewatch.local

APP_ENV=local
APP_KEY=
Expand All @@ -14,4 +16,18 @@ DB_USERNAME=root
DB_PASSWORD=secret

REDIS_HOST=redis
REDIS_PASSWORD=redis
REDIS_PASSWORD=redis

RAWG_API_KEY=
RAWG_API_HOST=https://api.rawg.io

JWT_EXPIRES=false

DISCORD_APP_ID=
DISCORD_PUBLIC_KEY=
DISCORD_BOT_TOKEN=
DISCORD_API_HOST=https://discord.com

ROOT_DISCORD_USER_ID=
ROOT_DISCORD_USERNAME=
ROOT_DISCORD_CHANNEL_ID=
25 changes: 0 additions & 25 deletions .github/workflows/application-ci.yml

This file was deleted.

10 changes: 5 additions & 5 deletions github/workflows/ci-cd.yml → .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Build Docker image (PHP-fpm)
run: docker build . --file Dockerfile.app --tag ${{ vars.DOCKER_IMAGE_TAG }}/php-fpm
- name: Build Docker image (Octane)
run: docker build . --file Dockerfile.app --tag ${{ vars.DOCKER_IMAGE_TAG }}/octane

- name: Build Docker image (Nginx)
run: docker build . --file Dockerfile.nginx --tag ${{ vars.DOCKER_IMAGE_TAG }}/nginx
Expand All @@ -36,12 +36,12 @@ jobs:
- name: Tag Docker images
run: |
docker tag ${{ vars.DOCKER_IMAGE_TAG }}/php-fpm:latest ${{ secrets.ECR_REPOSITORY_URI }}:latest-php-fpm
docker tag ${{ vars.DOCKER_IMAGE_TAG }}/octane:latest ${{ secrets.ECR_REPOSITORY_URI }}:latest-octane
docker tag ${{ vars.DOCKER_IMAGE_TAG }}/nginx:latest ${{ secrets.ECR_REPOSITORY_URI }}:latest-nginx
- name: Push Docker images to ECR
run: |
docker push ${{ secrets.ECR_REPOSITORY_URI }}:latest-php-fpm
docker push ${{ secrets.ECR_REPOSITORY_URI }}:latest-octane
docker push ${{ secrets.ECR_REPOSITORY_URI }}:latest-nginx
ecs-service-deploy:
Expand All @@ -64,7 +64,7 @@ jobs:
sed -i 's|<ECS_TASK_EXEC_ROLE>|${{ secrets.ECS_TASK_EXEC_ROLE }}|' ./ecs/deployment-task.json
sed -i 's|<ECS_SERVICE_NAME>|${{ vars.ECS_SERVICE_NAME }}|' ./ecs/deployment-task.json
sed -i 's|<SSM_NAMESPACE>|${{ secrets.SSM_NAMESPACE }}|' ./ecs/deployment-task.json
sed -i 's|<IMAGE_PHP_FPM>|${{ secrets.ECR_REPOSITORY_URI }}:latest-php-fpm|' ./ecs/deployment-task.json
sed -i 's|<IMAGE_OCTANE>|${{ secrets.ECR_REPOSITORY_URI }}:latest-octane|' ./ecs/deployment-task.json
sed -i 's|<IMAGE_NGINX>|${{ secrets.ECR_REPOSITORY_URI }}:latest-nginx|' ./ecs/deployment-task.json
- name: Register updated task definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Build Docker image (PHP-fpm)
run: docker build . --file Dockerfile.app --tag ${{ vars.DOCKER_IMAGE_TAG }}/php-fpm
- name: Build Docker image (Octane)
run: docker build . --file Dockerfile.app --tag ${{ vars.DOCKER_IMAGE_TAG }}/octane

- name: Build Docker image (Nginx)
run: docker build . --file Dockerfile.nginx --tag ${{ vars.DOCKER_IMAGE_TAG }}/nginx
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ vendor
.env
.vscode
.phpunit.result.cache
*info.php
*info.php
29 changes: 12 additions & 17 deletions Dockerfile.app
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
FROM php:8.3-fpm
FROM php:8.3-cli

WORKDIR /var/www/laravel-app
WORKDIR /srv/gamewatch

RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libbrotli-dev \
libc-ares-dev \
libssl-dev \
apt-utils \
curl \
wget \
zip \
git \
nano \
supervisor
npm

RUN docker-php-ext-configure pcntl --enable-pcntl
RUN docker-php-ext-install pdo pdo_mysql pcntl opcache

RUN pecl install xdebug \
redis \
&& docker-php-ext-enable xdebug \
redis

RUN mkdir -p /var/run/php && \
chown -R www-data:www-data /var/run/php && \
chmod 755 /var/run/php
RUN printf "\n" | pecl install swoole

COPY . /var/www/laravel-app
RUN docker-php-ext-enable xdebug \
redis \
swoole

COPY . .
COPY ./docker/php "${PHP_INI_DIR}/conf.d/"
COPY ./docker/php-fpm/www.conf /usr/local/etc/php-fpm.d/www.conf
COPY ./docker/supervisor /etc/supervisor/

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN find /var/www/laravel-app -not -path "/var/www/laravel-app/vendor/*" -type f -exec chmod 644 {} \;
RUN find /var/www/laravel-app -type d -exec chmod 755 {} \;
RUN chown -R www-data:www-data /var/www/laravel-app
RUN chgrp -R www-data storage bootstrap/cache
RUN chmod -R ug+rwx storage bootstrap/cache

COPY ./docker/entrypoint.app.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
2 changes: 1 addition & 1 deletion Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM nginx:alpine

COPY . /var/www/laravel-app
COPY . /var/www/gamewatch
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf.template

COPY ./docker/entrypoint.nginx.sh /usr/local/bin/entrypoint.sh
Expand Down
51 changes: 5 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,12 @@
![version](https://img.shields.io/badge/version-0.9.0-blue?style=flat)
[![build](https://github.com/danieltrolezi/laravel-app/actions/workflows/application-ci.yml/badge.svg)](https://github.com/danieltrolezi/laravel-app/actions/workflows/application-ci.yml)
[![build](https://github.com/danieltrolezi/gamewatch/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/danieltrolezi/gamewatch/actions/workflows/ci-cd.yml.yml)

## :package: Base Laravel Application
## GameWatch

This setup serves as the foundation for my personal Laravel projects and a playground for my coding experiments.
GameWatch makes it easy to track upcoming game releases.

If you prefer a streamlined development experience, consider checking out tools like [phpctl](https://github.com/opencodeco/phpctl), [docker-php](https://github.com/serversideup/docker-php), or [devpod](https://github.com/loft-sh/devpod).

However, if you enjoy diving deep into the workings of everything, feel free to take a look.

#### Documentation

:sparkle: [Full documentation available on the Wiki](https://github.com/danieltrolezi/laravel-app/wiki).

Explore examples on how to use:

* [Swagger](https://github.com/danieltrolezi/laravel-app/wiki/07.-Swagger)
* [PHP's Yaml](https://github.com/danieltrolezi/laravel-app/wiki/98.-Appendix#yaml)
* [Laravel Octane](https://github.com/danieltrolezi/laravel-app/wiki/08.-Laravel-Octane)
* [Authentication & Authorization](https://github.com/danieltrolezi/laravel-app/wiki/09.-Authentication-&-Authorization)

#### Key Technologies

* Backend: PHP 8.3 + Laravel 11 Framework
* Databases: MySQL 8 + Redis
* Containerization: Docker
* Web Server: Nginx
* PHP Processor: PHP-fpm
* Process Supervisor: Supervisord

#### Development Experience

* Code Sniffer (PSR-12): Enforces consistent and clean coding practices
* Git Hooks: Automates tasks to enhance your workflow
* Unit Testing: Ensures your code works as intended
* Xdebug Integration: Elevates your debugging capabilities
* Swagger: For comprehensive OpenAPI documentation
* Rector: Simplifies PHP/Laravel version upgrades

#### CI/CD Ready

This repository includes GitHub Actions templates for:

* Running Tests
* Code Sniffer
* Building Docker Images
* Uploading Docker Images to AWS ECR
* Updating Task Definitions on AWS ECS
* Updating Services on AWS ECS
Customize your notifications by selecting your preferred platforms and genres,
set your frequency, and never miss a game launch again!

## License

Expand Down
41 changes: 41 additions & 0 deletions app/Console/Commands/CreateRoot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Console\Commands;

use App\Repositories\UserRepository;
use App\Services\AuthService;
use Illuminate\Console\Command;

class CreateRoot extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:create-root';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates the Root User for the application';

/**
* Execute the console command.
*/
public function handle()
{
$created = resolve(UserRepository::class)->createRoot();

if ($created && app()->environment(['local', 'testing'])) {
$jwt = resolve(AuthService::class)->generateJWT([
'email' => config('auth.root.email'),
'password' => config('auth.root.password')
]);

$this->info('JWT: ' . $jwt['token']);
}
}
}
33 changes: 33 additions & 0 deletions app/Console/Commands/DispatchNotifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Console\Commands;

use App\Repositories\UserRepository;
use App\Services\Discord\Commands\ReleasesCommand;
use App\Services\Discord\DiscordAppService;
use Illuminate\Console\Command;

class DispatchNotifications extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:dispatch-notifications';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Dispatch notifications for all users';

/**
* Execute the console command.
*/
public function handle()
{
resolve(DiscordAppService::class)->dispatchNotifications();
}
}
35 changes: 35 additions & 0 deletions app/Console/Commands/RegisterCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Console\Commands;

use App\Services\Discord\DiscordAppService;
use Illuminate\Console\Command;

class RegisterCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:register-command {name}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Register Discord Command';

/**
* Execute the console command.
*/
public function handle()
{
$this->info(
resolve(DiscordAppService::class)->registerCommand(
$this->argument('name')
)
);
}
}
Loading

0 comments on commit 29ae990

Please sign in to comment.