Skip to content

Commit

Permalink
refactor: custom php
Browse files Browse the repository at this point in the history
  • Loading branch information
batonac committed Sep 11, 2024
1 parent 59bc057 commit 0bca1ed
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 267 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/oci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push PHP 8.1 image
run: |
nix build .#wordpress-php81
docker load < result
docker tag wordpress-php81:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php81
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php81
- name: Build and push PHP 8.2 image
run: |
nix build .#wordpress-php82
docker load < result
docker tag wordpress-php82:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php82
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php82
docker tag wordpress-php82:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Build and push PHP 8.3 image
run: |
nix build .#wordpress-php83
docker load < result
docker tag wordpress-php83:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php83
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php83
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php83
docker tag wordpress-php83:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Build and push PHP 8.4 image
run: |
nix build .#wordpress-php84
docker load < result
docker tag wordpress-php84:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php84
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php84
18 changes: 9 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
wordpress:
# image: ghcr.io/avunu/wordpress:latest-php83
image: wordpress-php82:latest
image: wordpress-php83:latest
ports:
- "8080:80"
volumes:
Expand All @@ -13,14 +13,14 @@ services:
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpresspassword
- WORDPRESS_DB_NAME=wordpress
- WORDPRESS_AUTH_KEY=$AUTH_KEY
- WORDPRESS_SECURE_AUTH_KEY=$SECURE_AUTH_KEY
- WORDPRESS_LOGGED_IN_KEY=$LOGGED_IN_KEY
- WORDPRESS_NONCE_KEY=$NONCE_KEY
- WORDPRESS_AUTH_SALT=$AUTH_SALT
- WORDPRESS_SECURE_AUTH_SALT=$SECURE_AUTH_SALT
- WORDPRESS_LOGGED_IN_SALT=$LOGGED_IN_SALT
- WORDPRESS_NONCE_SALT=$NONCE_SALT
- WORDPRESS_AUTH_KEY=${WORDPRESS_AUTH_KEY}
- WORDPRESS_SECURE_AUTH_KEY=${WORDPRESS_SECURE_AUTH_KEY}
- WORDPRESS_LOGGED_IN_KEY=${WORDPRESS_LOGGED_IN_KEY}
- WORDPRESS_NONCE_KEY=${WORDPRESS_NONCE_KEY}
- WORDPRESS_AUTH_SALT=${WORDPRESS_AUTH_SALT}
- WORDPRESS_SECURE_AUTH_SALT=${WORDPRESS_SECURE_AUTH_SALT}
- WORDPRESS_LOGGED_IN_SALT=${WORDPRESS_LOGGED_IN_SALT}
- WORDPRESS_NONCE_SALT=${WORDPRESS_NONCE_SALT}
depends_on:
- db

Expand Down
133 changes: 14 additions & 119 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,133 +1,28 @@
{
description = "FrankenPHP with latest PHP versions using nix2container and skopeo";
description = "WordPress FrankenPHP NixOS containers with multiple PHP versions";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix2container = {
url = "github:nlewo/nix2container";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, nix2container, ... }:
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
phpCommonConfig = {
embedSupport = true;
ztsSupport = true;
apxs2Support = false;
systemdSupport = false;
phpdbgSupport = false;
cgiSupport = false;
fpmSupport = false;
};

optimizePhp = phpPackage: (phpPackage.override final.phpCommonConfig).withExtensions
({ all, ... }: with all; [
curl dom exif fileinfo gd iconv imagick intl
mbstring mysqli opcache openssl sodium xml zip
]);

php81Optimized = final.optimizePhp prev.php81;
php82Optimized = final.optimizePhp prev.php82;
php83Optimized = final.optimizePhp prev.php83;

buildWordpressPhp = { php, name }:
let
busyboxWithApps = pkgs.busybox.override {
enableStatic = true;
enableAppletSymlinks = true;
};
image = nix2container.packages.${system}.nix2container.buildImage {
inherit name;
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "root";
paths = [
busyboxWithApps
pkgs.coreutils
pkgs.curl
pkgs.frankenphp
php
pkgs.cacert
pkgs.ghostscript
pkgs.libxml2
pkgs.mariadb.client
pkgs.unzip
(pkgs.writeTextFile {
name = "wp-config.php";
text = builtins.readFile ./wp-config.php;
destination = "/opt/wp-config.php";
})
(pkgs.writeScriptBin "docker-entrypoint.sh" (builtins.readFile ./docker-entrypoint.sh))
(pkgs.runCommand "shell-setup" {} ''
mkdir -p $out/bin
ln -s ${busyboxWithApps}/bin/sh $out/bin/sh
'')
];
pathsToLink = [ "/bin" "/etc" "/lib" "/opt" "/usr" ];
};
config = {
Entrypoint = [ "/bin/docker-entrypoint.sh" ];
Cmd = [ "frankenphp" "php-server" "--root" "/var/www/html" "--listen" "0.0.0.0:80" ];
ExposedPorts = {
"80/tcp" = {};
};
Env = [
"WORDPRESS_SOURCE_URL=https://wordpress.org/latest.zip"
"WORDPRESS_DB_HOST=localhost"
"WORDPRESS_DB_USER=wordpress"
"WORDPRESS_DB_PASSWORD=wordpress"
"WORDPRESS_DB_NAME=wordpress"
"WORDPRESS_AUTH_KEY=key"
"WORDPRESS_SECURE_AUTH_KEY=key"
"WORDPRESS_LOGGED_IN_KEY=key"
"WORDPRESS_NONCE_KEY=key"
"WORDPRESS_AUTH_SALT=key"
"WORDPRESS_SECURE_AUTH_SALT=key"
"WORDPRESS_LOGGED_IN_SALT=key"
"WORDPRESS_NONCE_SALT=key"
];
};
};
in pkgs.buildPackages.runCommand "docker-image-${name}"
{
nativeBuildInputs = [ pkgs.buildPackages.skopeo pkgs.buildPackages.bubblewrap ];
}
''
mkdir -p $out
# Create a fake /var/tmp directory for skopeo
mkdir -p $TMPDIR/fake-var/tmp
args=(--unshare-user --bind "$TMPDIR/fake-var" /var)
for dir in /*; do
args+=(--dev-bind "/$dir" "/$dir")
done
bwrap ''${args[@]} -- ${pkgs.lib.getExe image.copyTo} docker-archive:$out/${name}.tar
gzip $out/${name}.tar
echo "${name}" > $out/image-name
'';
})
];
};
pkgs = nixpkgs.legacyPackages.${system};

mkWordPressImage = phpVersion:
import ./wordpress.nix {
inherit pkgs;
php = pkgs.${phpVersion};
imageName = "wordpress-${phpVersion}";
};
in {
packages = {
wordpress-php81 = pkgs.buildWordpressPhp {
php = pkgs.php81Optimized;
name = "wordpress-php81";
};
wordpress-php82 = pkgs.buildWordpressPhp {
php = pkgs.php82Optimized;
name = "wordpress-php82";
};
wordpress-php83 = pkgs.buildWordpressPhp {
php = pkgs.php83Optimized;
name = "wordpress-php83";
};
wordpress-php82 = mkWordPressImage "php82";
wordpress-php83 = mkWordPressImage "php83";
wordpress-php84 = mkWordPressImage "php84";
default = self.packages.${system}.wordpress-php83;
};
}
);
Expand Down
101 changes: 0 additions & 101 deletions flake.nix.bak

This file was deleted.

Loading

0 comments on commit 0bca1ed

Please sign in to comment.