This project provides CI, Docker, Lint, Tests for Laravel.
Read this in these languages: English, 汉字.
This project build two Dockers for production and development.
build steps:
# default production
docker build -t laravel-demo:6 .
# development
docker build -t laravel-demo:6-dev --build-arg APP_ENV=local .
# speed up docker build by change apt, composer, npm mirror
docker build -t laravel-demo:6-dev --build-arg APP_ENV=local --build-arg SPEED=up .
build result on hub.docker.com:
docker pull sinkcup/laravel-demo:6
It has 3 roles, you can switch by CONTAINER_ROLE: app/scheduler/queue:
# default web app
docker run --rm --name laravel_demo -e DB_CONNECTION=sqlite -t sinkcup/laravel-demo:6
# scheduler(cron)
docker run --rm --name laravel_demo_scheduler -e DB_CONNECTION=sqlite -e CONTAINER_ROLE=scheduler -t sinkcup/laravel-demo:6
# queue
docker run --rm --name laravel_demo_queue -e DB_CONNECTION=sqlite -e CONTAINER_ROLE=queue -t sinkcup/laravel-demo:6

detail:
config/logging.php.routes/web.php and routes/api.php.ide-helper is only required in dev, how to run composer script only in dev?
If you add script to run it in composer.json, it will crash when to deploy using composer install --optimize-autoloader --no-dev.
the best way is:
"scripts":{
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
"if (php artisan | grep 'ide-helper:generate'); then php artisan ide-helper:generate; fi",
"if (php artisan | grep 'ide-helper:meta'); then php artisan ide-helper:meta; fi"
]
},
This project use PSR12 coding standard, you can find rules in phpcs.xml.
When you run composer install, the .git-pre-commit will be copyed to .git/hooks/pre-commit, so it will check locally when you commit codes.
If there are some format errors, you could try to fix automatically:
./lint.sh --fix
You can find lint.sh run in .circleci/config.yml and Jenkinsfile, so it will check coding standard when codes pushed or a PR created.
This project generate OpenAPI 3 Docs from code.
local:
php artisan serve
google-chrome http://127.0.0.1:8000/api/documentation
online(swaggerhub.com):
php artisan l5-swagger:generate
curl -X POST "https://api.swaggerhub.com/apis/sinkcup/laravel-demo?openapi=3.0.0" \
-H "Authorization: your-api-key" \
-H "Content-Type: application/json" \
--data-binary @storage/api-docs/api-docs.json
google-chrome https://app.swaggerhub.com/apis-docs/sinkcup/laravel-demo/1.0.0
docs: https://swagger.io/blog/api-development/integrating-with-the-swaggerhub-api/
When you run ./phpunit.sh, it will generate:
clover.xml: coverage report in Clover XML format, you can register for a TOKEN on codecov.io, so CI can upload the report to it.storage/app/public/coverage: coverage report in HTML format, you can access by http://localhost:8000/storage/coverage/junit.xml: test execution in JUnit XML format, it can be collected by Jenkins.Environment Variables:
| Name | Value |
|---|---|
| CODECOV_TOKEN | optional, get from codecov.io |

Environment Variables:
| Name | Value |
|---|---|
| DOCKER_USER | optional, Docker username, set this if you want to use private docker image |
| DOCKER_PASSWORD | optional, Docker password |
| DOCKER_SERVER | optional, Docker server |
| DOCKER_PATH_PREFIX | optional, Docker path prefix |
| SPEED | optional, change mirror to speed up docker build, values: up/down/keep |

Content type
Image
Digest
Size
189.8 MB
Last updated
over 5 years ago
docker pull sinkcup/laravel-demo