Last active
September 19, 2023 07:41
-
-
Save drupol/2fc21f99190be727a438810db3a7dad9 to your computer and use it in GitHub Desktop.
flake.nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```nix | |
packages = let | |
src = ./.; | |
php = pkgs.php81; | |
in { | |
app = php.buildComposerProject { | |
inherit src; | |
pname = "app-demo"; | |
version = "1.0.0"; | |
vendorHash = "sha256-SrE51k3nC5idaDHNxiNM7NIbIERIf8abrCzFEdxOQWA="; | |
}; | |
oci-image = let | |
webroot = "${app}/share/php/app-demo/public"; | |
caddyFile = pkgs.writeText "Caddyfile" '' | |
{ | |
email [email protected] | |
} | |
:80 { | |
root * ${webroot} | |
log | |
encode gzip | |
php_fastcgi 127.0.0.1:9000 | |
file_server | |
} | |
:443 { | |
root * ${webroot} | |
log | |
encode gzip | |
php_fastcgi 127.0.0.1:9000 | |
file_server | |
tls internal { | |
on_demand | |
} | |
} | |
''; | |
in | |
pkgs.dockerTools.buildLayeredImage { | |
name = self'.packages.app.pname; | |
tag = "latest"; | |
contents = [ | |
php | |
pkgs.caddy | |
pkgs.dockerTools.caCertificates | |
pkgs.fakeNss | |
(pkgs.writeScriptBin "start-server" '' | |
#!${pkgs.runtimeShell} | |
php-fpm -D -y /etc/php-fpm.d/www.conf.default | |
caddy run --adapter caddyfile --config ${caddyFile} | |
'') | |
]; | |
extraCommands = '' | |
mkdir -p tmp | |
chmod 1777 tmp | |
''; | |
config = { | |
Cmd = [ "start-server" ]; | |
ExposedPorts = { | |
"80/tcp" = {}; | |
"443/tcp" = {}; | |
}; | |
}; | |
}; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment