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

Create Nix base image #3

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 0 additions & 29 deletions .github/workflows/build-push.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
/result
14 changes: 14 additions & 0 deletions config/entrypoint-sh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ writeText
, bash
, busybox
, nginxConf
, phpFpmConf
, phpIni
}: writeText "entrypoint.sh" ''
#!${bash}/bin/bash
find /entrypoint.d -type f -executable -print0 | xargs -0I{} {}
nginx -e /dev/null -c ${nginxConf} &
php-fpm -Fy ${phpFpmConf} -c ${phpIni} &
wait -n
echo $?
''
40 changes: 40 additions & 0 deletions config/nginx-conf.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ nginx
, writeText
}: writeText "nginx.conf" ''
user nobody nobody;
worker_processes 1;
daemon off;
error_log /dev/stdout info;
pid /dev/null;
events {
worker_connections 1024;
}
http {
access_log /dev/stdout;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
include ${nginx}/conf/mime.types;
default_type application/octet-stream;
upstream php {
server 127.0.0.1:9000;
}
server {
listen 80;
index index.php;
client_max_body_size 50m;
root /app/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php;
include ${nginx}/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_read_timeout 600;
}
}
}
''
20 changes: 20 additions & 0 deletions config/php-fpm-conf.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ writeText }: writeText "php-fpm.conf" ''
[global]
error_log = /dev/stderr
log_limit = 8192
[www]
access.log = /dev/stderr
access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
clear_env = no
catch_workers_output = yes
decorate_workers_output = no
user = nobody
group = nobody
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 20
pm.max_requests = 1000
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
''
20 changes: 20 additions & 0 deletions config/php-ini.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ writeText }: writeText "php.ini" ''
display_errors = On
log_errors = On
error_log = /dev/stderr
short_open_tag = Off
variables_order = 'GPCS'
request_order = 'GP'
memory_limit = 512M
max_execution_time = 300
max_input_time = 300
post_max_size = 50M
upload_max_size = 50M
max_input_vars = 5000
expose_php = Off
date.timezone = UTC
opcache.memory_consumption = 512
opcache.interned_strings_buffer = 64
opcache.max_accelerated_files = 32531
opcache.fast_shutdown = Off
''
42 changes: 42 additions & 0 deletions flake.lock

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

24 changes: 24 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05";
systems.url = "github:nix-systems/default";
};

outputs = { self, nixpkgs, systems }:
let
lib = nixpkgs.lib;
eachSystem = lib.genAttrs (import systems);
pkgsFor = eachSystem (system: nixpkgs.legacyPackages.${system});
in {
packages = eachSystem (system: let
pkgs = pkgsFor.${system};
in {
default = pkgs.callPackage ./image.nix {};
php74 = pkgs.callPackage ./image.nix { php = pkgs.php74; };
php80 = pkgs.callPackage ./image.nix { php = pkgs.php80; };
php81 = pkgs.callPackage ./image.nix { php = pkgs.php81; };
php82 = pkgs.callPackage ./image.nix { php = pkgs.php82; };
php83 = pkgs.callPackage ./image.nix { php = pkgs.php83; };
});
};
}
60 changes: 60 additions & 0 deletions image.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{ lib
, pkgs
, hiPrio
, nginx
, php
, busybox
, bash
, buildEnv
, runCommand
, dockerTools
, imageName ? "laravel-base-image"
, imageTag ? "local"
, extraEnv ? []
, extraPkgs ? []
, extraPhpExtensions ? ({enabled, all}: enabled)
}: let
callPackage = lib.callPackageWith (pkgs // config);
config = {
entrypointSh = callPackage ./config/entrypoint-sh.nix {};
phpFpmConf = callPackage ./config/php-fpm-conf.nix {};
phpIni = callPackage ./config/php-ini.nix {};
nginxConf = callPackage ./config/nginx-conf.nix {};
};
phpWithExtensions = php.withExtensions extraPhpExtensions;
bin = buildEnv {
name = "bin";
paths = [
(hiPrio busybox)
bash
nginx
phpWithExtensions
phpWithExtensions.packages.composer
] ++ extraPkgs;
pathsToLink = [ "/bin" ];
};
in dockerTools.buildImage {
name = imageName;
tag = imageTag;
copyToRoot = buildEnv {
name = "laravel-base";
paths = with dockerTools; [
bin
usrBinEnv
caCertificates
fakeNss
];
};
runAsRoot = ''
#!${bash}/bin/bash
mkdir -pm1777 /tmp
mkdir -p /entrypoint.d /var/cache/nginx /app
'';
config = {
Cmd = [ "${bash}/bin/bash" config.entrypointSh ];
WorkingDir = "/app";
Env = [
"PHPRC=${config.phpIni}"
] ++ extraEnv;
};
}
27 changes: 0 additions & 27 deletions laravel-nginx.Dockerfile

This file was deleted.

73 changes: 0 additions & 73 deletions laravel-swoole.Dockerfile

This file was deleted.