Skip to content

Commit

Permalink
Merge pull request #1 from Avunu/temp
Browse files Browse the repository at this point in the history
init temp branch
  • Loading branch information
batonac authored Sep 11, 2024
2 parents e5f9802 + d099285 commit c1c1680
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 86 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
result*
result
resutlt/*
wordpress
result*
wordpress
wordpress*
wordpress/*
14 changes: 10 additions & 4 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: localhost/avunu-wordpress:latest-php83
image: wordpress-php82:latest
ports:
- "8080:80"
volumes:
Expand All @@ -13,8 +13,14 @@ services:
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpresspassword
- WORDPRESS_DB_NAME=wordpress
# override cmd with busybox
command: /usr/bin/sh
- 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
depends_on:
- db

Expand All @@ -30,4 +36,4 @@ services:
- MYSQL_PASSWORD=wordpresspassword

volumes:
db_data:
db_data:
27 changes: 15 additions & 12 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/bin/sh
set -euo pipefail
set -e

# Default WordPress URL if not provided
WORDPRESS_SOURCE_URL=${WORDPRESS_SOURCE_URL:-"https://wordpress.org/latest.zip"}

# Function to download and install WordPress
install_wordpress() {
echo "WordPress not found. Downloading and installing from: $WORDPRESS_SOURCE_URL"
curl -o wordpress.zip "$WORDPRESS_SOURCE_URL"
wget -O wordpress.zip "$WORDPRESS_SOURCE_URL"

# Create a temporary directory for extraction
TEMP_DIR="/tmp/wp_install_$(date +%s)"
TEMP_DIR="/tmp/wordpress"
mkdir -p "$TEMP_DIR"
unzip wordpress.zip -d "$TEMP_DIR"

# Find WordPress files
WP_ROOT=$(find "$TEMP_DIR" -name wp-config-sample.php -exec dirname {} \; | head -n 1)

if [ -z "$WP_ROOT" ]; then
echo "Error: WordPress files not found in the downloaded archive."
rm -rf "$TEMP_DIR"
exit 1
fi

Expand All @@ -27,13 +27,13 @@ install_wordpress() {

# Clean up
rm -rf "$TEMP_DIR" wordpress.zip
chown -R nobody:nobody /var/www/html
# chown -R nobody:nobody /var/www/html

# Import database if WORDPRESS_DB_URL is set
if [ -n "${WORDPRESS_DB_URL:-}" ]; then
if command -v wp &> /dev/null; then
if command -v wp >/dev/null 2>&1; then
import_db_wp_cli
elif command -v mysql &> /dev/null; then
elif command -v mysql >/dev/null 2>&1; then
import_db_mysql
else
echo "Error: Neither wp-cli nor mysql cli are available. Cannot import database."
Expand All @@ -44,29 +44,32 @@ install_wordpress() {
# Function to import database using wp-cli
import_db_wp_cli() {
echo "Importing database using wp-cli from: $WORDPRESS_DB_URL"
curl -o db_dump.sql "$WORDPRESS_DB_URL"
wget -O db_dump.sql "$WORDPRESS_DB_URL"
wp db import db_dump.sql --allow-root
rm db_dump.sql
}

# Function to import database using mysql cli
import_db_mysql() {
echo "Importing database using mysql from: $WORDPRESS_DB_URL"
curl -o db_dump.sql "$WORDPRESS_DB_URL"
wget -O db_dump.sql "$WORDPRESS_DB_URL"
mysql -h"$WORDPRESS_DB_HOST" -u"$WORDPRESS_DB_USER" -p"$WORDPRESS_DB_PASSWORD" "$WORDPRESS_DB_NAME" < db_dump.sql
rm db_dump.sql
}

# Always copy the custom wp-config.php
echo "Copying custom wp-config.php"
cp /opt/wp-config.php /var/www/html/wp-config.php
# chown nobody:nobody /var/www/html/wp-config.php
cp /wp-config.php /var/www/html/wp-config.php
chmod 644 /var/www/html/wp-config.php


# Check if WordPress is installed
if [ ! -f /var/www/html/wp-includes/version.php ]; then
install_wordpress
fi

# # Always copy the custom mu-plugins
# echo "Copying custom mu-plugins"
# cp -r /mu-plugins /var/www/html/wp-content/mu-plugins
# chmod 755 /var/www/html/wp-content/mu-plugins

exec "$@"
61 changes: 3 additions & 58 deletions flake.lock

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

14 changes: 14 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# Generate random keys and salts
export WORDPRESS_AUTH_KEY=$(openssl rand -base64 32)
export WORDPRESS_SECURE_AUTH_KEY=$(openssl rand -base64 32)
export WORDPRESS_LOGGED_IN_KEY=$(openssl rand -base64 32)
export WORDPRESS_NONCE_KEY=$(openssl rand -base64 32)
export WORDPRESS_AUTH_SALT=$(openssl rand -base64 32)
export WORDPRESS_SECURE_AUTH_SALT=$(openssl rand -base64 32)
export WORDPRESS_LOGGED_IN_SALT=$(openssl rand -base64 32)
export WORDPRESS_NONCE_SALT=$(openssl rand -base64 32)

# Run docker-compose
docker-compose up
19 changes: 10 additions & 9 deletions wordpress.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,26 @@ pkgs.dockerTools.buildLayeredImage {
tag = "latest";
contents = [
phpBuild
pkgs.bashInteractive
pkgs.busybox
pkgs.cacert
pkgs.coreutils
pkgs.curl
pkgs.findutils
pkgs.frankenphp
pkgs.ghostscript
pkgs.gnused
pkgs.imagemagick
pkgs.mysql.client
pkgs.unzip
pkgs.vips
pkgs.wp-cli
];

config = {
Entrypoint = [ "/bin/bash" "/docker-entrypoint.sh" ];
Cmd = [ "frankenphp" "php-server" "--root" "/var/www/html" "--listen" "0.0.0.0:80" ];
Entrypoint = [ "${pkgs.busybox}/bin/sh" "/docker-entrypoint.sh" ];
Cmd = [ "${pkgs.lib.getExe pkgs.frankenphp}" "php-server" "--root" "/var/www/html" "--listen" "0.0.0.0:80" ];
ExposedPorts = {
"80/tcp" = {};
"80/tcp" = { };
};
Env = [
"SERVER_NAME=0.0.0.0:80"
"WORDPRESS_SOURCE_URL=https://wordpress.org/latest.zip"
"WORDPRESS_DB_URL="
"WORDPRESS_DB_HOST=localhost"
"WORDPRESS_DB_USER=wordpress"
"WORDPRESS_DB_PASSWORD=wordpress"
Expand All @@ -81,10 +79,13 @@ pkgs.dockerTools.buildLayeredImage {
};

extraCommands = ''
# Copy WordPress files
mkdir -p var/www/html
cp ${./wp-config.php} wp-config.php
cp ${./docker-entrypoint.sh} docker-entrypoint.sh
chmod +x docker-entrypoint.sh
# Symlink CA certificates
ln -s ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt etc/ssl/certs/ca-certificates.crt
'';
}

0 comments on commit c1c1680

Please sign in to comment.