feat: WordPress migration support — upload existing site files
- Add two deployment modes for WordPress: Fresh Install vs Migrate Existing Site - Fresh Install: vanilla WordPress from official image (existing behavior) - Migrate: upload ZIP with wp-content/ (themes, plugins, uploads), wp-config.php, .htaccess - Custom entrypoint merges staged wp-content into PVC on first container run - Add init container for fresh WordPress builds (empty source context for Kaniko) - Increase upload limit to 200MB for WordPress sites - Add PHP upload limits (64MB) and memory config in WordPress Dockerfile - Update deploy page review step to show WordPress mode info - All UI in English
This commit is contained in:
@@ -51,7 +51,7 @@ export class ApplicationsController {
|
||||
@ApiOperation({ summary: 'Upload application code (zip file)' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FileInterceptor('file', {
|
||||
limits: { fileSize: 100 * 1024 * 1024 }, // 100MB
|
||||
limits: { fileSize: 200 * 1024 * 1024 }, // 200MB (WordPress sites can be large)
|
||||
}))
|
||||
async uploadCode(
|
||||
@Param('id') id: string,
|
||||
|
||||
@@ -205,12 +205,23 @@ export class BuildService {
|
||||
{ name: 'workspace', mountPath: '/workspace' },
|
||||
];
|
||||
|
||||
// If no uploaded code and no git, mount dockerfile directly
|
||||
// If no uploaded code and no git, we need to prepare the workspace
|
||||
if (!hasUploadedCode && !hasGitUrl) {
|
||||
kanikoVolumeMounts.push({
|
||||
name: 'dockerfile',
|
||||
mountPath: '/workspace/Dockerfile',
|
||||
subPath: 'Dockerfile',
|
||||
// For runtimes that don't need source (e.g. fresh WordPress),
|
||||
// add an init container that creates empty source dir + copies Dockerfile
|
||||
initContainers.push({
|
||||
name: 'prepare-workspace',
|
||||
image: 'alpine:3.19',
|
||||
command: ['sh', '-c', `
|
||||
mkdir -p /workspace-out/source &&
|
||||
cp /dockerfile/Dockerfile /workspace-out/Dockerfile &&
|
||||
echo ">>> Prepared empty workspace for fresh install" &&
|
||||
ls -la /workspace-out/
|
||||
`],
|
||||
volumeMounts: [
|
||||
{ name: 'workspace', mountPath: '/workspace-out' },
|
||||
{ name: 'dockerfile', mountPath: '/dockerfile' },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -391,6 +402,8 @@ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||
private wordpressDockerfile(app: Application): string {
|
||||
const wpVersion = app.runtimeVersion || '6.7';
|
||||
const phpVersion = app.phpVersion || '8.3';
|
||||
const hasUploadedCode = !!app.codePath;
|
||||
|
||||
return `FROM wordpress:${wpVersion}-php${phpVersion}-apache
|
||||
|
||||
# Install additional PHP extensions commonly needed by WordPress
|
||||
@@ -399,27 +412,51 @@ RUN docker-php-ext-install opcache
|
||||
# Enable Apache mod_rewrite for pretty permalinks
|
||||
RUN a2enmod rewrite
|
||||
|
||||
# Copy user's custom themes, plugins, and uploads if provided
|
||||
# Increase PHP upload limits for WordPress media
|
||||
RUN echo "upload_max_filesize = 64M\\npost_max_size = 64M\\nmax_execution_time = 300\\nmemory_limit = 256M" > /usr/local/etc/php/conf.d/uploads.ini
|
||||
|
||||
${hasUploadedCode ? `# Copy user's custom WordPress files
|
||||
COPY . /tmp/user-content
|
||||
|
||||
# Merge user content into the WordPress installation
|
||||
# - wp-content/themes, wp-content/plugins, wp-content/uploads
|
||||
# - Also support full WordPress roots (with wp-config.php, etc.)
|
||||
RUN if [ -d /tmp/user-content/wp-content ]; then \\
|
||||
cp -a /tmp/user-content/wp-content/. /var/www/html/wp-content/; \\
|
||||
# Merge user content into a staging area for wp-content
|
||||
# The actual wp-content is on a PVC, so we stage it and copy at runtime
|
||||
RUN mkdir -p /usr/src/wordpress-user && \\
|
||||
if [ -d /tmp/user-content/wp-content ]; then \\
|
||||
echo ">>> Staging user wp-content (themes, plugins, uploads)..." && \\
|
||||
cp -a /tmp/user-content/wp-content /usr/src/wordpress-user/wp-content; \\
|
||||
fi && \\
|
||||
if [ -f /tmp/user-content/wp-config.php ]; then \\
|
||||
echo ">>> Copying custom wp-config.php" && \\
|
||||
cp /tmp/user-content/wp-config.php /var/www/html/wp-config.php; \\
|
||||
fi && \\
|
||||
# Copy any loose PHP files (custom root files)
|
||||
if [ -f /tmp/user-content/.htaccess ]; then \\
|
||||
echo ">>> Copying .htaccess" && \\
|
||||
cp /tmp/user-content/.htaccess /var/www/html/.htaccess; \\
|
||||
fi && \\
|
||||
find /tmp/user-content -maxdepth 1 -name "*.php" ! -name "wp-config.php" -exec cp {} /var/www/html/ \\\\; 2>/dev/null || true && \\
|
||||
rm -rf /tmp/user-content
|
||||
rm -rf /tmp/user-content && \\
|
||||
echo ">>> WordPress user content staged"
|
||||
|
||||
# Custom entrypoint: merge staged wp-content into PVC on first run, then run WP
|
||||
RUN { \\
|
||||
echo '#!/bin/bash'; \\
|
||||
echo 'set -e'; \\
|
||||
echo 'if [ -d /usr/src/wordpress-user/wp-content ] && [ ! -f /var/www/html/wp-content/.user-content-merged ]; then'; \\
|
||||
echo ' echo ">>> First run: merging user wp-content into PVC..."'; \\
|
||||
echo ' cp -a /usr/src/wordpress-user/wp-content/. /var/www/html/wp-content/'; \\
|
||||
echo ' touch /var/www/html/wp-content/.user-content-merged'; \\
|
||||
echo ' chown -R www-data:www-data /var/www/html/wp-content'; \\
|
||||
echo ' echo ">>> User wp-content merged successfully"'; \\
|
||||
echo 'fi'; \\
|
||||
echo 'exec docker-entrypoint.sh apache2-foreground'; \\
|
||||
} > /usr/local/bin/cloudhost-entrypoint.sh && chmod +x /usr/local/bin/cloudhost-entrypoint.sh
|
||||
` : `# Fresh install — no user content to merge
|
||||
`}
|
||||
# Set proper ownership
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["apache2-foreground"]
|
||||
CMD [${hasUploadedCode ? '"cloudhost-entrypoint.sh"' : '"apache2-foreground"'}]
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user