Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker for production #1834

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
ARG PHP_VERSION=8.3
ARG FRANKENPHP_VERSION=latest

FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}

ARG TZ=UTC
ARG APP_DIR=/app

# IMPORTANT: If you're using a reverse proxy use :80, else set your domain name
ENV SERVER_NAME=:80 \
WITH_SCHEDULER=true \
WITH_HORIZON=true \
USER=www-data \
ROOT=${APP_DIR}

WORKDIR ${ROOT}

# INSTALL DEPS AND PHP EXTESIONS
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -

RUN apt-get update; \
apt-get upgrade -yqq; \
apt-get install -yqq --no-install-recommends --show-progress \
apt-utils \
curl \
wget \
nano \
git \
ncdu \
procps \
ca-certificates \
supervisor \
libsodium-dev \
unzip \
nodejs \
mariadb-client \
# Install PHP extensions (included with dunglas/frankenphp)
&& install-php-extensions \
@composer \
pcntl \
pdo_mysql \
gd \
intl \
opcache \
mbstring \
bcmath \
gmp \
zip \
redis \
&& apt-get -y autoremove \
&& apt-get clean \
&& docker-php-source delete \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm /var/log/lastlog /var/log/faillog


RUN arch="$(uname -m)" \
&& case "$arch" in \
armhf) _cronic_fname='supercronic-linux-arm' ;; \
aarch64) _cronic_fname='supercronic-linux-arm64' ;; \
x86_64) _cronic_fname='supercronic-linux-amd64' ;; \
x86) _cronic_fname='supercronic-linux-386' ;; \
*) echo >&2 "error: unsupported architecture: $arch"; exit 1 ;; \
esac \
&& wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/${_cronic_fname}" \
-O /usr/bin/supercronic \
&& chmod +x /usr/bin/supercronic \
&& mkdir -p /etc/supercronic \
&& echo "*/1 * * * * php ${ROOT}/artisan schedule:run --no-interaction" > /etc/supercronic/laravel

RUN cp ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini

COPY --link --chown=${USER}:${USER} composer.json composer.lock ./

RUN composer install \
--no-dev \
--no-interaction \
--no-autoloader \
--no-ansi \
--no-scripts

COPY --link . .

RUN mkdir -p \
storage/framework/{sessions,views,cache,testing} \
storage/logs \
bootstrap/cache && chmod -R a+rw storage

COPY --link resources/docker/supervisord.conf /etc/supervisor/
COPY --link resources/docker/supervisord.*.conf /etc/supervisor/conf.d/

COPY --link resources/docker/php.ini ${PHP_INI_DIR}/conf.d/99-octane.ini

COPY --link resources/docker/start-task-runner /usr/local/bin/start-task-runner

RUN chmod +x /usr/local/bin/start-task-runner

# FrankenPHP embedded PHP configuration
COPY --link resources/docker/php.ini /lib/php.ini

RUN npm install --loglevel=error --no-audit
RUN npm run production

RUN cat resources/docker/utilities.sh >> ~/.bashrc
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ make build-assets
```

This will build all of the assets according to the webpack file.

## Production Environment with Docker

You may also want to use Docker in production. We have chosen to use [FrankenPHP](https://frankenphp.dev/docs/), which is a module based on the [Caddy web server](https://caddyserver.com/docs/) and serves as a replacement for PHP-FPM. You will also have access to MariaDB and Redis.

First, you need to set your domain name in the `SERVER_NAME` of the `Dockerfile`

Then, to start the production environment, run:

```bash
docker-compose -f docker-compose.prod.yml up -d
```
38 changes: 38 additions & 0 deletions app/Providers/HorizonServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Laravel\Horizon\Horizon;
use Laravel\Horizon\HorizonApplicationServiceProvider;

class HorizonServiceProvider extends HorizonApplicationServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void
{
parent::boot();

// Horizon::routeSmsNotificationsTo('15556667777');
// Horizon::routeMailNotificationsTo('example@example.com');
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel');
}

/**
* Register the Horizon gate.
*
* This gate determines who can access Horizon in non-local environments.
*/
protected function gate(): void
{
Gate::define('viewHorizon', function ($user) {
// By default only allow the first user to view the horizon dashboard
// TODO: use an env key for this?
return in_array($user->id, [
1,
]);
});
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
"spatie/laravel-activitylog": "^4.7",
"socialiteproviders/vatsim": "^5.0",
"socialiteproviders/ivao": "^4.0",
"mailersend/laravel-driver": "^2.6"
"mailersend/laravel-driver": "^2.6",
"laravel/horizon": "^5.29"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8.1",
Expand Down
86 changes: 83 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
App\Providers\CronServiceProvider::class,
App\Providers\DirectiveServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\HorizonServiceProvider::class,
App\Providers\MeasurementsProvider::class,
App\Providers\ObserverServiceProviders::class,
App\Providers\RouteServiceProvider::class,
Expand Down
Loading
Loading