Skip to content

Commit d2fabba

Browse files
authored
Merge pull request #44 from fly-apps/use_upstream_base_image
Use upstream base image
2 parents 1f642e5 + a08614d commit d2fabba

49 files changed

Lines changed: 2423 additions & 35 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ The Dockerfile generated by this project aims to provide support for:
1515
4. Running the [Scheduler](https://laravel.com/docs/10.x/scheduling#running-the-scheduler) for your background tasks
1616
5. Generating [Fly.io](https://fly.io/) relevant scripts essential for deploying your application as a Laravel Fly App, if applicable
1717

18-
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 ).
18+
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!
19+
1920

2021
### Installation
2122

app/Services/File.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33

44
class File
55
{
6+
7+
/**
8+
* There are some files that need exact content copies, don't add new lines for this at end
9+
*/
10+
public function exactCopiesOnlyFiles()
11+
{
12+
return ['.fly/php/ondrej_ubuntu_php.gpg'];
13+
}
14+
615
/**
716
* Generate a file with content
817
*
@@ -23,7 +32,10 @@ public function createFile( $output, $result )
2332
}
2433

2534
// Create the file, finally!
26-
return file_put_contents($output, implode("\n", $result) . "\n");
35+
if( in_array( $output, $this->exactCopiesOnlyFiles()) )
36+
return file_put_contents($output, implode("\n", $result));
37+
else
38+
return file_put_contents($output, implode("\n", $result) . "\n");
2739
}
2840

2941
/**
@@ -65,6 +77,8 @@ public function deleteDir( $dir )
6577
$filePath = $dir.'/'.$fileName;
6678
if( is_file($filePath) )
6779
unlink( $filePath);
80+
else if( is_dir($filePath) && $fileName != '.' && $fileName != '..' )
81+
$this->deleteDir( $filePath );
6882
}
6983
rmdir( $dir );
7084
}

app/Services/Scanner.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function shouldBuildAssets( array $options )
8989
{
9090
$shouldBuild = !$options['no-assets'];
9191
$packageJsonExists = (new \App\Services\File())->packageJsonExists( $options['path'] );
92-
92+
9393
if( $shouldBuild && $packageJsonExists ) {
9494
// If want to build assets, make sure package.json exists
9595
return true;
@@ -117,13 +117,47 @@ public function templates( array $options )
117117

118118
// Scan for fly.io mark
119119
if ( $options['fly'] ) {
120+
// [directory.filename] => filepath to write to
120121
$templates[ 'fly.dockerignore' ] = '.dockerignore';
121-
$templates[ 'fly.entrypoint'] = '.fly/entrypoint.sh';
122-
$templates[ 'fly.scripts.caches'] = '.fly/scripts/caches.sh';
123122
}
124123

124+
// Generate files to be used alongside Upstream Base Image
125+
126+
// Additional config files needed by the Dockerfile
127+
$templates[ 'fly.entrypoint'] = '.fly/entrypoint.sh';
128+
$templates[ 'fly.start-nginx_sh' ] = '.fly/start-nginx.sh';
129+
$templates[ 'fly.scripts.caches'] = '.fly/scripts/caches.sh';
130+
131+
// Nginx
132+
$templates[ 'fly.fpm.pool_d.www_conf' ] = '.fly/fpm/pool.d/www.conf';
133+
$templates[ 'fly.nginx.conf_d.access-log_conf' ] = '.fly/nginx/conf.d/access-log.conf';
134+
$templates[ 'fly.nginx.conf_d.websockets_conf' ] = '.fly/nginx/conf.d/websockets.conf';
135+
$templates[ 'fly.nginx.sites-available.default-octane' ] = '.fly/nginx/sites-available/default-octane';
136+
$templates[ 'fly.nginx.sites-available.default' ] = '.fly/nginx/sites-available/default';
137+
$templates[ 'fly.nginx.nginx_conf' ] = '.fly/nginx/nginx.conf';
138+
139+
// PHP Version configs
140+
$templates[ 'fly.php.packages.7_4_txt' ] = '.fly/php/packages/7.4.txt';
141+
$templates[ 'fly.php.packages.8_0_txt' ] = '.fly/php/packages/8.0.txt';
142+
$templates[ 'fly.php.packages.8_1_txt' ] = '.fly/php/packages/8.1.txt';
143+
$templates[ 'fly.php.packages.8_2_txt' ] = '.fly/php/packages/8.2.txt';
144+
$templates[ 'fly.php.packages.8_3_txt' ] = '.fly/php/packages/8.3.txt';
145+
$templates[ 'fly.php.ondrej_ubuntu_php_gpg' ] = '.fly/php/ondrej_ubuntu_php.gpg';
146+
147+
// Supervisor Files
148+
$templates[ 'fly.supervisor.conf_d.fpm_conf' ] = '.fly/supervisor/conf.d/fpm.conf';
149+
$templates[ 'fly.supervisor.conf_d.nginx_conf' ] = '.fly/supervisor/conf.d/nginx.conf';
150+
$templates[ 'fly.supervisor.supervisord_conf' ] = '.fly/supervisor/supervisord.conf';
151+
152+
// Octane conf
153+
if( $options['octane']=='frankenphp' )
154+
$templates[ 'fly.supervisor.octane-franken_conf' ] = '.fly/supervisor/octane-franken.conf';
155+
else if( $options['octane']=='roadrunner' )
156+
$templates[ 'fly.supervisor.octane-rr_conf' ] = '.fly/supervisor/octane-rr.conf';
157+
else if( $options['octane']=='swoole' )
158+
$templates[ 'fly.supervisor.octane-swoole_conf' ] = '.fly/supervisor/octane-swoole.conf';
159+
125160
return $templates;
126161
}
127162

128-
129163
}

builds/dockerfile-laravel

14.5 KB
Binary file not shown.

resources/views/dockerfile.blade.php

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,61 @@
22

33
ARG PHP_VERSION=8.2
44
ARG NODE_VERSION=18
5-
FROM fideloper/fly-laravel:${PHP_VERSION} as base
5+
FROM ubuntu:22.04 as base
6+
LABEL fly_launch_runtime="laravel"
67

78
# PHP_VERSION needs to be repeated here
89
# See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
910
ARG PHP_VERSION
11+
ENV DEBIAN_FRONTEND=noninteractive \
12+
COMPOSER_ALLOW_SUPERUSER=1 \
13+
COMPOSER_HOME=/composer \
14+
COMPOSER_MAX_PARALLEL_HTTP=24 \
15+
PHP_PM_MAX_CHILDREN=10 \
16+
PHP_PM_START_SERVERS=3 \
17+
PHP_MIN_SPARE_SERVERS=2 \
18+
PHP_MAX_SPARE_SERVERS=4 \
19+
PHP_DATE_TIMEZONE=UTC \
20+
PHP_DISPLAY_ERRORS=Off \
21+
PHP_ERROR_REPORTING=22527 \
22+
PHP_MEMORY_LIMIT=256M \
23+
PHP_MAX_EXECUTION_TIME=90 \
24+
PHP_POST_MAX_SIZE=100M \
25+
PHP_UPLOAD_MAX_FILE_SIZE=100M \
26+
PHP_ALLOW_URL_FOPEN=Off
1027

11-
LABEL fly_launch_runtime="laravel"
28+
# Prepare base container:
29+
# 1. Install PHP, Composer
30+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
31+
COPY .fly/php/ondrej_ubuntu_php.gpg /etc/apt/trusted.gpg.d/ondrej_ubuntu_php.gpg
32+
ADD .fly/php/packages/${PHP_VERSION}.txt /tmp/php-packages.txt
33+
34+
RUN apt-get update \
35+
&& apt-get install -y --no-install-recommends gnupg2 ca-certificates git-core curl zip unzip \
36+
rsync vim-tiny htop sqlite3 nginx supervisor cron \
37+
&& ln -sf /usr/bin/vim.tiny /etc/alternatives/vim \
38+
&& ln -sf /etc/alternatives/vim /usr/bin/vim \
39+
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list \
40+
&& apt-get update \
41+
&& apt-get -y --no-install-recommends install $(cat /tmp/php-packages.txt) \
42+
&& ln -sf /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm \
43+
&& mkdir -p /var/www/html/public && echo "index" > /var/www/html/public/index.php \
44+
&& apt-get clean \
45+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
1246

13-
# copy application code, skipping files based on .dockerignore
47+
# 2. Copy config files to proper locations
48+
COPY .fly/nginx/ /etc/nginx/
49+
COPY .fly/fpm/ /etc/php/${PHP_VERSION}/fpm/
50+
COPY .fly/supervisor/ /etc/supervisor/
51+
COPY .fly/entrypoint.sh /entrypoint
52+
COPY .fly/start-nginx.sh /usr/local/bin/start-nginx
53+
RUN chmod 754 /usr/local/bin/start-nginx
54+
55+
# 3. Copy application code, skipping files based on .dockerignore
1456
COPY . /var/www/html
57+
WORKDIR /var/www/html
1558

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

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

134+
# 5. Setup Entrypoint
89135
@if($frankenphp_binary)
90136
@include('frankenphp.builder')
91137
@else
92138
EXPOSE 8080
93139
@endif
140+
141+
ENTRYPOINT ["/entrypoint"]

0 commit comments

Comments
 (0)