项目作者: RinMinase

项目描述 :
💬🐳 Rin Minase's Anime Database API Service utilizing Lumen 7 by Laravel and Mongo DB Atlas and is deployed to Heroku
高级语言: PHP
项目地址: git://github.com/RinMinase/anidb-be.git
创建时间: 2019-06-23T11:43:33Z
项目社区:https://github.com/RinMinase/anidb-be

开源协议:MIT License

下载


Rin Minase’s Anime Database
(Back-end API Service)



Laravel


PHP

Introduction

Add info here

Table Of Contents

Getting Started

Environment variables setup

Return to the table of contents

  1. Database

    Definition of terms:

    • DB_HOST - docker container name of the database
    • DB_PORT - port used by the database
    • DB_DATABASE - database name
    • DB_USERNAME - database username
    • DB_PASSWORD - database password

      Notes : DB_HOST should use docker container name of db, by default this is ‘anidb-pgsql’, but yours could be different. You can check this by running docker ps then check the container name of the postgres container.

  2. Cloudinary

    • Fire up your browser and login your Cloudinary Account. If you have no account yet, you can create one for free.
    • After logging in, navigate to the Cloudinary Console to retrieve your Cloudinary URL
    • Copy the value of API Environment variable to CLOUDINARY_URL of your ENV file

Running the project

Return to the table of contents

  1. Download and install Docker.

  2. Clone the project, then install the dependencies

    1. git clone https://github.com/RinMinase/anidb-be.git
    2. cd anidb-be
  3. Run the necessary docker containers

    1. docker compose up -d
    2. docker compose exec php sh

    This runs only the necessary containers. As for running the optional containers, please see the section below.

  4. Inside the docker image, copy the env file, install the necessary dependencies and generate the necessary key for laravel

    1. cp .env.example .env
    2. composer install
    3. php artisan key:generate
  5. Generate the necessary API key and take note of this is as this is REQUIRED to access the API

    1. php artisan app:generate-api-key

    or you can generate your own from any application, and add it under API_KEY in your .env file. Example:

    1. openssl rand -hex 36
  6. Generate the necessary root password key and take note of this is as this is REQUIRED to create admin accounts

    1. php artisan app:generate-root-password

    or generate your own, and add it under APP_REGISTRATION_ROOT_PASSWORD in your .env file.

  7. Run the database migrations

    1. php artisan migrate:fresh --seed
  8. (Optional) If you want to start the scheduler and queue workers

    1. supervisorctl start worker:
  9. Lastly, fire up your browser and go to localhost.

Note:
If you need to access the container run, docker compose exec php sh

Job / Commands / Schedule updates and restarting the supervisor

Return to the table of contents

In cases there are any updates to:

  • Jobs (found on app/Jobs)
  • Commands (found on app/Commands)
  • Schedules (found on bootstrap/app.php under withSchedule)

Please run the following:

  1. Navigate inside the php docker container [how]

  2. Run the command to restart the group (queue-worker and schedule-worker)

    1. supervisorctl restart worker:

Managing the supervisor

Return to the table of contents

This application runs supervisor on the php container. Supervisor runs these tasks:

Task Name Group Command Description
php-fpm - php-fpm Runs FastCGI Process Manager
queue-worker worker php artisan queue:work Runs Laravel’s Queue worker
schedule-worker worker php artisan schedule:work Runs Laravel’s Schedule worker

To manage the supervisor the commands below can be used:

Command Description
supervisorctl reread Re-reads changes in supervisor config files
supervisorctl update Updates supervisor with changes after reread
supervisorctl status Check status of all running tasks
supervisorctl start Starts the task
supervisorctl stop Stops the task
supervisorctl restart Restarts the task

Please note: Supervisor logs are kept in ./docker/logs/supervisor.log

Running the optional containers

Return to the table of contents

List of optional containers:

Name Description
(none) None as of yet

You can run them individually by:

  1. docker compose up -d <name>

Or run all of them by:

  1. docker compose up -d --profile optional

Re-running the project

Return to the table of contents

  1. Navigate inside the php docker container

    1. docker compose exec php sh
  2. Run the migrations when necessary, then install the dependencies also when necessary

    1. php artisan migrate
    2. composer install
  3. Fire up your browser and go to localhost.

Running the queue manually

Return to the table of contents

  1. Navigate inside the php docker container [how]

  2. Run the command to run the worker for the queue

    1. php artisan queue:work

Running the scheduled tasks manually

Return to the table of contents

  1. Navigate inside the php docker container [how]

  2. Run the command to run the scheduled tasks manually

    1. php artisan schedule:work

There are a few commands specific to running tasks:

Name Description
schedule:run Runs the scheduled tasks manually with respect to cron
schedule:work Runs the scheduler worker
schedule:list Lists the upcoming tasks to be run

Running the Swagger Generator / API Documentation Generator

Return to the table of contents

  1. Navigate inside the php docker container [how]

  2. Run the command to generate the documentations inside the container

    1. docs
  3. Fire up your browser and go to localhost/docs to open Swagger UI.

Running the Unit Tests

Return to the table of contents

  1. Navigate inside the php docker container [how]

  2. Run the command below:

    1. php artisan test

    or if you want to run a specific test module

    1. php artisan test --filter <Class name of Test File | function name>

    or if you want to run a specific single test

    1. php artisan test --filter test_function_name tests/Location/of/TestCase.php

Project shorthands / aliases inside the PHP Docker container

Return to the table of contents

This shortcuts were created to reduce the need to keep typing the same long commands over and over again.

Shortcut Long version
pa or artisan php artisan
docs composer docs
dump or da composer dumpautoload
sv supervisorctl

Project Structure

Return to the table of contents

  1. .
  2. ├── app/ # Application source code
  3. ├── docs.blade.php # Swagger page template
  4. ├── index.blade.php # Landing page template
  5. └── ... # Other application-related files
  6. ├── bootstrap/ # Project initializers
  7. ├── app.php # Framework bootstrapper
  8. ├── helpers.php # Helper functions
  9. └── routes.php # Route definitions
  10. ├── config/ # Laravel configuration files
  11. ├── database/ # Database migrations and seeders
  12. ├── docker/ # Docker functions
  13. ├── php-config/ # PHP settings for docker
  14. ├── caddyfile # Caddy container docker file
  15. ├── php.dockerfile # PHP container docker file
  16. └── ... # Other docker-related files
  17. ├── public/ # Project entry point
  18. ├── tests/ # Project test files
  19. ├── .czrc # Commitizen configuration file
  20. ├── docker-compose.yml # Main docker file
  21. ├── phpunit.xml # Unit test configuration file
  22. ├── Procfile # Heroku process file
  23. └── ... # Other project files

Built with

Deployed to