• This repository has been archived on 15/Nov/2023
  • Stars
    star
    176
  • Rank 216,131 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 3 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿš€ An example of Laravel app that runs in a docker container with RoadRunner

Logo

This repository contains an example of Laravel (PHP Framework) application that runs in a docker container with RoadRunner (high-performance PHP application server) as a web server.

๐Ÿ”ฅ Features list

  • For local application running, you need just two dependencies - installed docker and docker-compose (make is optional, but strongly recommended)
  • PostgreSQL as a database and Redis as a cache & queue driver already configured
  • One Dockerfile for local application development and running on production
  • All used images are based on Alpine (lightweight and security-oriented linux distributive)
  • Lightweight final docker image (compressed size ~65 Mb, ~16 downloadable layers)
  • Unprivileged user is used by default
  • Easy to update PHP and dependencies
  • Ready to run Laravel task scheduling, queue workers, and many others on your choice
  • Without file permission problems
  • For cron jobs running supercronic is used (crontab-compatible job runner, designed specifically to run in containers)
  • Self-signed SSL certificate for HTTPS support
  • Enabled opcache and jit compiler for the performance of your application
  • Composer dependencies caching using separate docker image layer
  • Well-documented code
  • HTTP server doesn't need to be restarted on source code changes
  • Works much faster than php-fpm + nginx and easy to deploy
  • Provided Makefile allows to perform familiar operations easy and fast
  • Ready to run phpunit (with code coverage) and phpstan (static analysis tool for source code)
  • GitHub actions for tests running, image building, etc.

How to use

If you want to integrate Docker + RoadRunner into an existing application, take a look at pull requests with the special label in the current repository - you can repeat these steps.

Another way is repository cloning, forking or usage this repository as a template for your application.

Don't forget to remove TestJob, TestController, and routes, that are declared for this controller in the routes/web.php file - it is used for internal application working tests.

First steps

Let's dive deeper and watch how to start application development, based on this template. First, we need to get the sources:

$ git clone https://github.com/tarampampam/laravel-roadrunner-in-docker.git
$ cd ./laravel-roadrunner-in-docker

After that - build image with our application and install composer dependencies:

$ make install
...
  - Installing spatie/laravel-ignition (2.0.0): Extracting archive
  - Installing symfony/psr-http-message-bridge (v2.1.4): Extracting archive
  - Installing spiral/goridge (v3.2.0): Extracting archive
  - Installing spiral/roadrunner-worker (v2.3.0): Extracting archive
  - Installing spiral/roadrunner-http (v2.2.0): Extracting archive
  - Installing nyholm/psr7 (1.5.1): Extracting archive
  - Installing spiral/roadrunner-laravel (v5.11.1): Extracting archive
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   INFO  Discovering packages.

  laravel/sail ...................................................... DONE
  laravel/sanctum ................................................... DONE
  laravel/tinker .................................................... DONE
  nesbot/carbon ..................................................... DONE
  nunomaduro/collision .............................................. DONE
  nunomaduro/termwind ............................................... DONE
  spatie/laravel-ignition ........................................... DONE
  spiral/roadrunner-laravel ......................................... DONE

Make full application initialization:

$ make init
...
   INFO  Preparing database.

  Creating migration table ..................................... 15ms DONE

   INFO  Running migrations.

  2014_10_12_000000_create_users_table ......................... 27ms DONE
  2014_10_12_100000_create_password_resets_table ............... 21ms DONE
  2019_08_19_000000_create_failed_jobs_table ................... 17ms DONE
  2019_12_14_000001_create_personal_access_tokens_table ........ 30ms DONE

   INFO  Seeding database.
...

Start the application:

$ make up
...

    Navigate your browser to โ‡’ http://127.0.0.1:8080 or https://127.0.0.1:8443

Voila! You can open http://127.0.0.1:8080 (or https://127.0.0.1:8443) in your browser and source code in your favorite IDE.

For watching all supported make commands execute make without parameters inside the project directory:

$ make

Available commands:
help               Show this help
install            Install all app dependencies
shell              Start shell into app container
init               Make full application initialization
...

How to

Open the shell in the application container?

Execute in your terminal:

$ make shell

In this shell, you can use composer, php, and any other tools, which are installed into a docker image.

Watch logs?

$ docker-compose logs -f

All messages from all containers output will be listed here.

Install composer dependency?

As it was told above - execute make shell and after that composer require %needed/package%.

Add my own make command?

Append into Makefile something like:

your-command: ## Your command help
	/bin/your/app -goes -here

Tab character in front of your command is mandatory!

Read more about makefiles here.

To Do

  • Describe front-end development/building

Useful links

Troubleshooting

MacOS Unprivileged User

This repo was created for Linux users. It maps /etc/passwd in docker-compose.yml to set the current host user for the Docker containers.

MacOS doesn't use /etc/passwd unless it's operating in single-user mode. Instead, it uses a system called Open Directory.

If you do make shell; whoami and get user errors, then you can fix by running ./scripts/fix_mac_user.sh. This script will create a mac_passwd file that plays nice with /etc/passwd used by docker-compose.yml under the volumes mapping section.

#!/bin/sh
// File: ./scripts/fix_mac_user.sh

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd $SCRIPT_DIR/../
echo "$USER:x:$(id -u):$(id -g):ns,,,:$HOME:/bin/bash" > mac_passwd
sed -i.backup 's~/etc/passwd:/etc/passwd:ro~./mac_passwd:/etc/passwd:ro~' docker-compose.yml

Support

Issues Issues

If you find any package errors, please, make an issue in current repository.

License

This project is open-sourced software licensed under the MIT license.

More Repositories

1

error-pages

๐Ÿšง Pretty server's error pages in the docker image & git repository (for traefik, k8s, nginx and so on)
Go
823
star
2

domains

๐ŸŒ DNS configuration for some of my domains
JavaScript
777
star
3

random-user-agent

๐Ÿ˜Ž Browser extension that automatically replaces the User-Agent with a randomized one
TypeScript
567
star
4

mikrotik-hosts-parser

โœ‚ Mikrotik hosts parser
Go
249
star
5

webhook-tester

๐Ÿ”ญ The powerful tool to test webhooks and not only
Go
171
star
6

3proxy-docker

๐Ÿ“ฒ Docker image with 3proxy - Tiny free proxy server
Dockerfile
120
star
7

nod32-update-mirror

๐Ÿ”ถ [WIP] ESET Nod32 Updates Mirror
Shell
107
star
8

tinifier

๐Ÿผ CLI client for images compressing using tinypng.com API
Go
76
star
9

node-docker

๐Ÿณ Docker image, based on node, with git, bash, and openssh
Dockerfile
51
star
10

indocker-app

๐Ÿ’ฅ Domain names with valid SSL for your local docker containers
Go
33
star
11

curl-docker

๐Ÿฆพ curl (static binary file) in a scratch docker image
Dockerfile
22
star
12

mustpl

๐Ÿงฐ Logic-less CLI templating tool
C
21
star
13

hydra-docker

๐Ÿ™ Dockerized hydra application
Dockerfile
6
star
14

rssbot-docker

๐Ÿค– Docker image with lightweight Telegram RSS notification bot
Dockerfile
5
star
15

colors

๐Ÿฆœ One more Go library for using colors in the terminal console
Go
4
star
16

go-filecache

โšก File-based cache with entries expiration, checksum validation and others
Go
3
star
17

tarampampam

โœจ I found a secret โœจ
HTML
2
star
18

http-proxy-daemon

๐Ÿ’Ž Http Proxy Daemon
Go
2
star
19

arduino-deps-installer

๐ŸŽฏ Arduino sketch dependencies installer
Go
1
star
20

urfave-cli-docs

๐Ÿ“š CLI usage docs generator (markdown)
Go
1
star
21

arduino-elscooter-lighting

๐Ÿ”ฉ My electric scooter lighting firmware
C++
1
star