Skip to content

Commit

Permalink
Merge pull request #44 from fly-apps/use_upstream_base_image
Browse files Browse the repository at this point in the history
Use upstream base image
  • Loading branch information
KTanAug21 authored Jul 26, 2024
2 parents 1f642e5 + a08614d commit d2fabba
Show file tree
Hide file tree
Showing 49 changed files with 2,423 additions and 35 deletions.
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

0 comments on commit d2fabba

Please sign in to comment.