Skip to content

Commit

Permalink
feat(vendor-sync): use specified directory instead of curl and zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
claimableperch committed Oct 29, 2024
1 parent 1f3d491 commit 3d87547
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/modules/createConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable global-require, import/no-dynamic-require */
const fs = require('fs-extra');
const { copyDirSync } = require('../utils/copy');
const { rmDirSync } = require('../utils/rm');
const path = require('path');
const glob = require('glob');
const { get, defaults } = require('lodash');
Expand Down Expand Up @@ -153,9 +155,19 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
htaccessFile = `${htaccessFile}-subfolder`;
}

const composerWordpress = path.resolve( CWD, version[0] );
const vendorSync = `${packageDir}/wordpress`;
if ( fs.existsSync( vendorSync ) ) {
rmDirSync( vendorSync );
}
if ( fs.existsSync( composerWordpress ) ) {
copyDirSync( composerWordpress, vendorSync );
}
const usableVersions = fs.existsSync( vendorSync ) ? [ 'wordpress' ] : validVersions;

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',
Expand All @@ -166,7 +178,7 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
const wpCypressConfig = {
...config,
version,
validVersions,
validVersions: usableVersions,
volumes,
activePlugins,
activeTheme,
Expand Down
8 changes: 6 additions & 2 deletions lib/templates/dockerfile.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ 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 { %>
ADD <%= version %> /var/www/wordpress
<% } }); %>
<% if (vip) { %>
RUN curl https://github.com/Automattic/vip-go-mu-plugins-built/archive/master.zip -L -o /usr/src/vip-mu-plugins.zip && \
Expand Down
22 changes: 22 additions & 0 deletions lib/utils/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require('fs-extra');
const path = require('path');
const rmDirSync = (src) => {
if (!fs.lstatSync(src).isDirectory()) {
return;
}

fs.readdirSync(src)
.forEach((item) => {
const srcItem = path.join(src, item);

if (fs.lstatSync(srcItem).isDirectory()) {
rmDirSync(srcItem);
} else {
fs.unlinkSync(srcItem);
}
});
fs.rmdirSync(src);
};
module.exports = {
rmDirSync,
};

0 comments on commit 3d87547

Please sign in to comment.