Skip to content

Commit

Permalink
Merge branch 'main' into temp
Browse files Browse the repository at this point in the history
  • Loading branch information
batonac authored Sep 11, 2024
2 parents 7a6603b + e5f9802 commit d099285
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 27 deletions.
37 changes: 37 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# WordPress Database Settings
WORDPRESS_DB_HOST=mysql
WORDPRESS_DB_USER=wordpress
WORDPRESS_DB_PASSWORD=your_strong_password_here
WORDPRESS_DB_NAME=wordpress
WORDPRESS_TABLE_PREFIX=wp_wordpress

# WordPress Source URL (optional, uncomment to use)
# WORDPRESS_SOURCE_URL=https://wordpress.org/latest.zip

# WordPress Database Import URL (optional, uncomment to use)
# WORDPRESS_DB_URL=http://example.com/path/to/your/database_dump.sql

# WordPress Authentication Unique Keys and Salts
# Generate these using: https://api.wordpress.org/secret-key/1.1/salt/
WORDPRESS_AUTH_KEY='put your unique phrase here'
WORDPRESS_SECURE_AUTH_KEY='put your unique phrase here'
WORDPRESS_LOGGED_IN_KEY='put your unique phrase here'
WORDPRESS_NONCE_KEY='put your unique phrase here'
WORDPRESS_AUTH_SALT='put your unique phrase here'
WORDPRESS_SECURE_AUTH_SALT='put your unique phrase here'
WORDPRESS_LOGGED_IN_SALT='put your unique phrase here'
WORDPRESS_NONCE_SALT='put your unique phrase here'

# WordPress Debug Mode (set to true for development, false for production)
WORDPRESS_DEBUG=false

# Extra WordPress Configuration (optional, uncomment and modify as needed)
# WORDPRESS_CONFIG_EXTRA="define( 'WP_MEMORY_LIMIT', '256M' );"

# FrankenPHP specific settings (if any)
# Add any FrankenPHP specific environment variables here

# Other optional settings
# Uncomment and set these if needed for your specific setup
# WORDPRESS_SITE_URL=https://your-domain.com
# WORDPRESS_HOME=https://your-domain.com
26 changes: 13 additions & 13 deletions .github/workflows/oci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install Nix
uses: cachix/install-nix-action@v18
uses: cachix/install-nix-action@v27
with:
extra_nix_config: |
experimental-features = nix-command flakes
- name: Build Docker Images
run: |
nix build .#wordpress-php81 .#wordpress-php82 .#wordpress-php83
docker load < result
docker load < result-1
docker load < result-2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -52,14 +49,17 @@ jobs:
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
# Get the actual image names from Docker
IMAGES=($(docker images --format "{{.Repository}}:{{.Tag}}" | grep wordpress))
for IMAGE in "${IMAGES[@]}"; do
PHP_VERSION=$(echo $IMAGE | sed -n 's/.*-php\([0-9]\+\).*/\1/p')
# Load and push images
for result in result*; do
IMAGE_NAME=$(cat $result/image-name)
PHP_VERSION=$(echo $IMAGE_NAME | sed -n 's/.*-php\([0-9]\+\).*/\1/p')
FULL_IMAGE_ID=$IMAGE_ID:php$PHP_VERSION
docker tag $IMAGE $FULL_IMAGE_ID
# Load the image
docker load < $result/${IMAGE_NAME}.tar.gz
# Tag and push the image
docker tag $IMAGE_NAME:latest $FULL_IMAGE_ID
docker push $FULL_IMAGE_ID
if [ "$VERSION" == "latest" ]; then
Expand All @@ -69,6 +69,6 @@ jobs:
done
# Tag one version as the default latest
DEFAULT_PHP_VERSION=82
DEFAULT_PHP_VERSION=83
docker tag $IMAGE_ID:php$DEFAULT_PHP_VERSION $IMAGE_ID:latest
docker push $IMAGE_ID:latest
133 changes: 119 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,28 +1,133 @@
{
description = "WordPress FrankenPHP NixOS containers with multiple PHP versions";
description = "FrankenPHP with latest PHP versions using nix2container and skopeo";

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 }:
outputs = { self, nixpkgs, flake-utils, nix2container, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};

mkWordPressImage = phpVersion:
import ./wordpress.nix {
inherit pkgs;
php = pkgs.${phpVersion};
imageName = "wordpress-${phpVersion}";
};
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
'';
})
];
};
in {
packages = {
wordpress-php81 = mkWordPressImage "php81";
wordpress-php82 = mkWordPressImage "php82";
wordpress-php83 = mkWordPressImage "php83";
default = self.packages.${system}.wordpress-php82;
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";
};
};
}
);
Expand Down
101 changes: 101 additions & 0 deletions flake.nix.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
description = "FrankenPHP with latest PHP versions";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# frankenwp = {
# url = "github:StephenMiracle/frankenwp";
# flake = false;
# };
};

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;

buildwordpress-php = { php, name }:
final.dockerTools.buildLayeredImage {
inherit name;
tag = "latest";
contents = [
final.frankenphp
php
final.busybox
final.cacert
final.curl
final.ghostscript
final.libxml2
final.mariadb.client
final.unzip
];
extraCommands = ''
mkdir -p var/www/html usr/bin
cp ${./wp-config.php} wp-config.php
cp ${./docker-entrypoint.sh} docker-entrypoint.sh
chmod +x docker-entrypoint.sh
ln -s ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt etc/ssl/certs/ca-certificates.crt
ln -s ${pkgs.busybox}/bin/sh usr/bin/bash
'';
config = {
Entrypoint = [ "/docker-entrypoint.sh" ];
Cmd = [ "frankenphp" "php-server" "--root" "/var/www/html" "--listen" "0.0.0.0:80" ];
ExposedPorts = {
"80/tcp" = {};
};
Env = [
"PHP_INI_DIR=/usr/local/etc/php"
"WORDPRESS_VERSION=latest"
"WORDPRESS_SHA1="
"WORDPRESS_DB_HOST=localhost"
"WORDPRESS_DB_USER=wordpress"
"WORDPRESS_DB_PASSWORD=wordpress"
"WORDPRESS_DB_NAME=wordpress"
"WORDPRESS_TABLE_PREFIX=wp_"
];
};
};
})
];
};
in {
packages = {
wordpress-php81 = pkgs.buildwordpress-php {
php = pkgs.php81Optimized;
name = "wordpress-php81";
};
wordpress-php82 = pkgs.buildwordpress-php {
php = pkgs.php82Optimized;
name = "wordpress-php82";
};
wordpress-php83 = pkgs.buildwordpress-php {
php = pkgs.php83Optimized;
name = "wordpress-php83";
};
};
}
);
}

0 comments on commit d099285

Please sign in to comment.