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

Use upstream base image #44

Merged
merged 24 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ec65173
Add Dockerfile config files from laravel-docker, and create test to m…
Jul 18, 2024
a4472ad
generate only specific php package file based on version
Jul 19, 2024
c3d6012
Only generate octane supervisor configurations when their respective …
Jul 19, 2024
d99d920
re include entrypoint.sh in templates to render for fly apps
Jul 19, 2024
f4a82bf
Initially copy over all php version configs
Jul 20, 2024
f31a4ca
Properly relocate setting php packages
Jul 20, 2024
9cbf47f
Provide list of files that dont need a new line appended to
Jul 21, 2024
156c1d1
Revise dockerfile template to use an upstream base image, copying log…
Jul 21, 2024
fe013e4
Include test result for octane_rr dockerfile, include scripts/caches.…
Jul 21, 2024
1e2991e
Include Result for octane_frankenphp based Dockerfile for Laravel 11
Jul 21, 2024
b990941
Include Dockerfile test result for octane_swoole_laravel 11
Jul 21, 2024
f8814ce
Revert test result for base_10 to original state before upstream imag…
Jul 21, 2024
f302de3
Include Dockerfile test result for base 10 laravel apps
Jul 21, 2024
21fa6fd
Include Dockerfile test result for Laravel 10 octane swoole
Jul 21, 2024
46aa6e3
Include test result for Dockerfile generated for laravel 10 using oct…
Jul 21, 2024
1a27ea7
Include test result for Dockerfile generated for Laravel 10 octane fr…
Jul 21, 2024
e2bf2ef
Move new config templates inside resources.views.fly folder
Jul 21, 2024
57b654b
Remove phpversion function
Jul 21, 2024
09ed1d3
remove upstream-base-image flag, use upstream image by default
Jul 26, 2024
415ffb2
Update the Readme.md to mention the move to the use of upstream image…
Jul 26, 2024
ab3a923
Update the Readme.md to mention the move to the use of upstream image…
Jul 26, 2024
8a3e97b
Build new phar of the package
Jul 26, 2024
00f8db9
link to laravel-docker
Jul 26, 2024
a08614d
link to ubuntu docker hub image
Jul 26, 2024
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ The Dockerfile generated by this project aims to provide support for:
4. Running the [Scheduler](https://laravel.com/docs/10.x/scheduling#running-the-scheduler) for your background tasks
5. Generating [Fly.io](https://fly.io/) relevant scripts essential for deploying your application as a Laravel Fly App, if applicable

The Dockerfile generated uses the base image published from https://github.com/fly-apps/laravel-docker/tree/main. Every feature from the Docker image published from that repository, is of course, by nature of things-passed-over to a dependent, also available in the Dockerfile generated by this project ( unless overridden ).
The Dockerfile generated has been updated to merge with the Dockerfile logic found in https://github.com/fly-apps/laravel-docker, see [the Dockerfile ref](https://github.com/fly-apps/laravel-docker/blob/main/src/Dockerfile). This change has been made to allow the use of an [upstream image](https://hub.docker.com/_/ubuntu) while still providing the base logic provided by the previously used image, `fideloper/fly-laravel`, which is maintained by that repository. Further, it now visibly provides the necessary configuration files in the user's project directory, specifically in the `.fly` folder, finally allowing the user full control over these files!


### Installation

Expand Down
16 changes: 15 additions & 1 deletion app/Services/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

class File
{

/**
* There are some files that need exact content copies, don't add new lines for this at end
*/
public function exactCopiesOnlyFiles()
{
return ['.fly/php/ondrej_ubuntu_php.gpg'];
}

/**
* Generate a file with content
*
Expand All @@ -23,7 +32,10 @@ public function createFile( $output, $result )
}

// Create the file, finally!
return file_put_contents($output, implode("\n", $result) . "\n");
if( in_array( $output, $this->exactCopiesOnlyFiles()) )
return file_put_contents($output, implode("\n", $result));
else
return file_put_contents($output, implode("\n", $result) . "\n");
}

/**
Expand Down Expand Up @@ -65,6 +77,8 @@ public function deleteDir( $dir )
$filePath = $dir.'/'.$fileName;
if( is_file($filePath) )
unlink( $filePath);
else if( is_dir($filePath) && $fileName != '.' && $fileName != '..' )
$this->deleteDir( $filePath );
}
rmdir( $dir );
}
Expand Down
42 changes: 38 additions & 4 deletions app/Services/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function shouldBuildAssets( array $options )
{
$shouldBuild = !$options['no-assets'];
$packageJsonExists = (new \App\Services\File())->packageJsonExists( $options['path'] );

if( $shouldBuild && $packageJsonExists ) {
// If want to build assets, make sure package.json exists
return true;
Expand Down Expand Up @@ -117,13 +117,47 @@ public function templates( array $options )

// Scan for fly.io mark
if ( $options['fly'] ) {
// [directory.filename] => filepath to write to
$templates[ 'fly.dockerignore' ] = '.dockerignore';
$templates[ 'fly.entrypoint'] = '.fly/entrypoint.sh';
$templates[ 'fly.scripts.caches'] = '.fly/scripts/caches.sh';
}

// Generate files to be used alongside Upstream Base Image

// Additional config files needed by the Dockerfile
$templates[ 'fly.entrypoint'] = '.fly/entrypoint.sh';
$templates[ 'fly.start-nginx_sh' ] = '.fly/start-nginx.sh';
$templates[ 'fly.scripts.caches'] = '.fly/scripts/caches.sh';

// Nginx
$templates[ 'fly.fpm.pool_d.www_conf' ] = '.fly/fpm/pool.d/www.conf';
$templates[ 'fly.nginx.conf_d.access-log_conf' ] = '.fly/nginx/conf.d/access-log.conf';
$templates[ 'fly.nginx.conf_d.websockets_conf' ] = '.fly/nginx/conf.d/websockets.conf';
$templates[ 'fly.nginx.sites-available.default-octane' ] = '.fly/nginx/sites-available/default-octane';
$templates[ 'fly.nginx.sites-available.default' ] = '.fly/nginx/sites-available/default';
$templates[ 'fly.nginx.nginx_conf' ] = '.fly/nginx/nginx.conf';

// PHP Version configs
$templates[ 'fly.php.packages.7_4_txt' ] = '.fly/php/packages/7.4.txt';
$templates[ 'fly.php.packages.8_0_txt' ] = '.fly/php/packages/8.0.txt';
$templates[ 'fly.php.packages.8_1_txt' ] = '.fly/php/packages/8.1.txt';
$templates[ 'fly.php.packages.8_2_txt' ] = '.fly/php/packages/8.2.txt';
$templates[ 'fly.php.packages.8_3_txt' ] = '.fly/php/packages/8.3.txt';
$templates[ 'fly.php.ondrej_ubuntu_php_gpg' ] = '.fly/php/ondrej_ubuntu_php.gpg';

// Supervisor Files
$templates[ 'fly.supervisor.conf_d.fpm_conf' ] = '.fly/supervisor/conf.d/fpm.conf';
$templates[ 'fly.supervisor.conf_d.nginx_conf' ] = '.fly/supervisor/conf.d/nginx.conf';
$templates[ 'fly.supervisor.supervisord_conf' ] = '.fly/supervisor/supervisord.conf';

// Octane conf
if( $options['octane']=='frankenphp' )
$templates[ 'fly.supervisor.octane-franken_conf' ] = '.fly/supervisor/octane-franken.conf';
else if( $options['octane']=='roadrunner' )
$templates[ 'fly.supervisor.octane-rr_conf' ] = '.fly/supervisor/octane-rr.conf';
else if( $options['octane']=='swoole' )
$templates[ 'fly.supervisor.octane-swoole_conf' ] = '.fly/supervisor/octane-swoole.conf';

return $templates;
}


}
Binary file modified builds/dockerfile-laravel
Binary file not shown.
54 changes: 51 additions & 3 deletions resources/views/dockerfile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,61 @@

ARG PHP_VERSION=8.2
ARG NODE_VERSION=18
FROM fideloper/fly-laravel:${PHP_VERSION} as base
FROM ubuntu:22.04 as base
LABEL fly_launch_runtime="laravel"

# PHP_VERSION needs to be repeated here
# See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION
ENV DEBIAN_FRONTEND=noninteractive \
COMPOSER_ALLOW_SUPERUSER=1 \
COMPOSER_HOME=/composer \
COMPOSER_MAX_PARALLEL_HTTP=24 \
PHP_PM_MAX_CHILDREN=10 \
PHP_PM_START_SERVERS=3 \
PHP_MIN_SPARE_SERVERS=2 \
PHP_MAX_SPARE_SERVERS=4 \
PHP_DATE_TIMEZONE=UTC \
PHP_DISPLAY_ERRORS=Off \
PHP_ERROR_REPORTING=22527 \
PHP_MEMORY_LIMIT=256M \
PHP_MAX_EXECUTION_TIME=90 \
PHP_POST_MAX_SIZE=100M \
PHP_UPLOAD_MAX_FILE_SIZE=100M \
PHP_ALLOW_URL_FOPEN=Off

LABEL fly_launch_runtime="laravel"
# Prepare base container:
# 1. Install PHP, Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
COPY .fly/php/ondrej_ubuntu_php.gpg /etc/apt/trusted.gpg.d/ondrej_ubuntu_php.gpg
ADD .fly/php/packages/${PHP_VERSION}.txt /tmp/php-packages.txt

RUN apt-get update \
&& apt-get install -y --no-install-recommends gnupg2 ca-certificates git-core curl zip unzip \
rsync vim-tiny htop sqlite3 nginx supervisor cron \
&& ln -sf /usr/bin/vim.tiny /etc/alternatives/vim \
&& ln -sf /etc/alternatives/vim /usr/bin/vim \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list \
&& apt-get update \
&& apt-get -y --no-install-recommends install $(cat /tmp/php-packages.txt) \
&& ln -sf /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm \
&& mkdir -p /var/www/html/public && echo "index" > /var/www/html/public/index.php \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# copy application code, skipping files based on .dockerignore
# 2. Copy config files to proper locations
COPY .fly/nginx/ /etc/nginx/
COPY .fly/fpm/ /etc/php/${PHP_VERSION}/fpm/
COPY .fly/supervisor/ /etc/supervisor/
COPY .fly/entrypoint.sh /entrypoint
COPY .fly/start-nginx.sh /usr/local/bin/start-nginx
RUN chmod 754 /usr/local/bin/start-nginx

# 3. Copy application code, skipping files based on .dockerignore
COPY . /var/www/html
WORKDIR /var/www/html

# 4. Setup application dependencies
RUN composer install --optimize-autoloader --no-dev \
&& mkdir -p storage/logs \
&& php artisan optimize:clear \
Expand All @@ -36,6 +80,7 @@
RUN php artisan icons:cache && php artisan filament:cache-components
@endif


@if($build_assets)
# Multi-stage build: Build static assets
# This allows us to not include Node within the final container
Expand Down Expand Up @@ -86,8 +131,11 @@
&& chown -R www-data:www-data /var/www/html/public
@endif

# 5. Setup Entrypoint
@if($frankenphp_binary)
@include('frankenphp.builder')
@else
EXPOSE 8080
@endif

ENTRYPOINT ["/entrypoint"]
Loading
Loading