Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string version denotes subdir, build provides xdebug #144

Open
wants to merge 1 commit into
base: release/1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zend_extension=xdebug.so
serverName=wp-cypress
xdebug.client_host=host.docker.internal
xdebug.mode=debug
xdebug.idekey=PhpStorm
24 changes: 22 additions & 2 deletions lib/modules/createConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable global-require, import/no-dynamic-require */
const fs = require('fs-extra');
const { execSync } = require('child_process');
const path = require('path');
const glob = require('glob');
const { get, defaults } = require('lodash');
Expand Down Expand Up @@ -135,13 +136,31 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
const version = Array.isArray(config.version) ? config.version : [config.version];
const validVersions = await getValidVersions(version);

const composerWordpress = path.resolve( CWD, version[0] );
let usableVersions;
if ( fs.existsSync( composerWordpress ) ) {
if ( ! hasVolumeSupport ) {
const vendorSync = `${packageDir}/wordpress`;
if ( !fs.existsSync( vendorSync ) ) {
fs.mkdirSync( vendorSync );
}
execSync(`rsync -r --delete ${composerWordpress}/ ${vendorSync}/`);
} else {
volumes.push( `${composerWordpress}:/var/www/wordpress` );
}
usableVersions = [ 'wordpress' ];
} else {
usableVersions = validVersions;
}

await renderTemplate(
`${packageDir}/lib/templates/docker-compose.ejs`,
`${packageDir}/docker-compose.yml`,
{
port: config.port || 80,
dbPort: config.dbPort || 3306,
volumes: hasVolumeSupport ? volumes : false,
env: config.env || {},
},
);

Expand All @@ -155,18 +174,19 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {

await renderTemplate(`${packageDir}/lib/templates/dockerfile.ejs`, `${packageDir}/Dockerfile`, {
isWpContent: config.wpContent,
versions: validVersions,
versions: usableVersions,
vip: config.muPlugins ? config.muPlugins.vip : false,
phpVersion: config.phpVersion || 7.4,
phpMemoryLimit: config.phpMemoryLimit || '128M',
htaccessFile,
workingDir,
volumes,
});

const wpCypressConfig = {
...config,
version,
validVersions,
validVersions: usableVersions,
volumes,
activePlugins,
activeTheme,
Expand Down
7 changes: 7 additions & 0 deletions lib/templates/docker-compose.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
depends_on:
- db
build: .
environment:
CYPRESS_TEST: 1 <% Object.entries( env ).forEach(([n,v]) => { %>
<%= n %> : <%= v %> <% }); %>
ports:
- <%= port %>:80
<% if (volumes) { %>volumes: <% volumes.forEach((volume) => { %>
Expand All @@ -19,3 +22,7 @@ services:
- db:/var/lib/mysql
volumes:
db: {}

networks:
bridge0:

15 changes: 12 additions & 3 deletions lib/templates/dockerfile.ejs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
FROM php:<%= phpVersion %>-apache

RUN apt-get update && apt-get install -y wget libpng-dev libjpeg-dev gnupg default-mysql-client nano less unzip && rm -rf /var/lib/apt/lists/* \
RUN apt-get update && apt-get install -y wget rsync libpng-dev libjpeg-dev gnupg default-mysql-client nano less unzip && rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd \
&& docker-php-ext-install gd mysqli
&& docker-php-ext-install gd mysqli \
&& pecl install xdebug

COPY config/xdebug.ini /usr/local/etc/php/conf.d

RUN a2enmod rewrite

Expand All @@ -22,14 +25,20 @@ RUN curl -sS https://getcomposer.org/installer --output composer-setup.php \
&& php composer-setup.php --version=1.10.16 \
&& mv composer.phar /bin/composer

<% versions.forEach((version) => { %>
<% versions.forEach((version) => {
if ( version.match(/(\d+.?)+/) ) {
%>
RUN curl https://wordpress.org/wordpress-<%= version %>.tar.gz > wordpress-<%= version %>.tar.gz && \
mkdir -p <%= workingDir %>/<%= version %> && \
tar -xzf wordpress-<%= version %>.tar.gz -C <%= workingDir %>/<%= version %> && \
mv <%= workingDir %>/<%= version %>/wordpress/* <%= workingDir %>/<%= version %> && \
rm -rf <%= workingDir %>/<%= version %>/wordpress && \
chown -R www-data:www-data <%= workingDir %>/<%= version %><% if (isWpContent) { %> && \<% } else { %>;<% } %>
<% if (isWpContent) { %>rm -rf <%= workingDir %>/<%= version %>/wp-content;<% } %>
<% } else if ( ! volumes.find( (v) => v.includes('/var/www/wordpress') ) ) { %>
ADD <%= version %> /var/www/wordpress
RUN chown -R www-data:www-data /var/www/wordpress
<% } %>
<% }); %>

<% if (vip) { %>
Expand Down