Open jemiliolopez opened 4 years ago
En la carpeta builder se encuentran lo scripts s2i que se ejecutaran para crear las nuevas imagenes streams de wordpress. The image_contexto/builder/metadata.json content the metadata labels to the new builder image. { "labels": [ {"io.k8s.display-name":"WordPress"}, {"io.k8s.description":"WordPress application and S2I builder."}, {"io.openshift.s2i.scripts-url":"image:///opt/app-root/s2i"}, {"io.s2i.scripts-url":"image:///opt/app-root/s2i"}, {"io.openshift.tags":"builder,php,wordpress"} ] }
In the builder folder are the s2i scripts that will be executed to create the new wordpress stream images. In the contexto/builder/save-artifacts, its preserves artifacts from one builder image to the other in a progressive compilation.
true
In the builder folder are the s2i scripts that will be executed to create the new wordpress stream images.
The content to contexto/builder/assemble is:
#!/bin/bash
set -x
shopt -s dotglob ## para mover los archivos ocultos set -eo pipefail
# When the custom image is run as a S2I builder we allow for the user to # provide their own plugins, themes and languages directories. We need to # stash these away and they will be applied only when the final application # image is run so that they can be applied to what is contained in the # persistent volume.
# mv /opt/app-root/src/wp-content /silo/wordpress && export MI_PID="$!" && \ # while $(kill -0 "$MI_PID");do sleep 1;done # fi
# while ['0'] ; do # echo "el 0 es true" # done
mkdir -p /opt/app-root/silo/wordpress
mv /tmp/src/* /opt/app-root/silo/wordpress
# rm -fr /opt/app-root/silo/wordpress/*
# export APP_DATA="/opt/app-root/silo/wordpress"
# mv /tmp/src/* /opt/app-root/silo/wordpress/
# rm -f /opt/app-root/silo/wordpress/README.md # rm -fr /opt/app-root/silo/wordpress/.git
fix-permissions ./ fix-permissions /opt/app-root fix-permissions /silo/wordpress
n the builder folder are the s2i scripts that will be executed to create the new wordpress stream images.
The content to contexto/builder/run is:
set -x
set -eo pipefail
shopt -s dotglob ## para mover los archivos ocultos
if [ -f "/opt/app-root/silo/wordpress/wp-config.php" ] && [ -d "/opt/app-root/silo/wordpress/wp-content" ];then gulp tmoverwpconfigpriv gulp tmoverwpcontentpriv gulp tmoverwphtcaccesspriv gulp enlacesSymlinkpriv
fi
gulp default &
sleep 5
if [ -f "/opt/app-root/src/wp-config-sample.php" ] && [ -d "/opt/app-root/src/wp-content" ];then
if [ -z "${DB_USER}" ] || [ -z "${DB_PASSWORD}" ] || [ -z "${DB_NAME}" ] || [ -z "${DB_HOST}" ];then
echo "Procedemos desde el propio instalador php de wordpress (web) mediante el browser."
else
wp config create --dbname="${DB_NAME}" --dbuser="${DB_USER}" --dbpass="${DB_PASSWORD}" --dbhost="${DB_HOST}"
# wp config create --dbname="${DB_NAME}" --dbuser="${DB_USER}" --dbpass="${DB_PASSWORD}" --dbhost="${DB_HOST}" --skip-check
fi
fi
The content contexto/.htcaccess:
# BEGIN WordPress
RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
# END WordPress
The content contexto/add-wp-config-php: define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define('FORCE_SSL_ADMIN', true); define('FORCE_SSL_LOGIN', true); if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on'; define( 'WP_CONTENT_DIR', '/silo/wordpress'); define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/'); define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/'); define('FS_METHOD', 'direct'); if ( defined( 'WP_CLI' ) ) { $_SERVER['HTTP_HOST'] = 'localhost'; }; # if ( ! defined( 'WP_CLI' ) ) { # // remove x-pingback HTTP header # add_filter('wp_headers', function($headers) { # unset($headers['X-Pingback']); # return $headers; # }); # // disable pingbacks # add_filter( 'xmlrpc_methods', function( $methods ) { # unset( $methods['pingback.ping'] ); # return $methods; # }); # add_filter( 'auto_update_translation', '__return_false' ); # };
The gulpfile.js: 'use strict';
const gulp = require('gulp'); const fs = require('fs-extra'); var concat = require('gulp-concat');
const srcwpcontent = '/opt/app-root/src/wp-content'; const srcwpcontentpriv = '/opt/app-root/silo/wordpress/wp-content'; const dstwpcontent = '/silo/wordpress/wp-content'; const srcwphtcaccess = '/opt/app-root/src/.htcaccess'; const srcwphtcaccesspriv = '/opt/app-root/silo/wordpress/.htcaccess'; const dstwphtcaccess = '/silo/wordpress/.htcaccess'; const srcwpconfig = '/opt/app-root/src/wp-config.php'; const srcwpconfigpriv = '/opt/app-root/silo/wordpress/wp-config.php'; const dstwpconfig = '/silo/wordpress/wp-config.php';
// // With async/await: // async function createdirwpcontent () { // try { // await fs.emptyDir('/silo/wordpress,wp-content'); // console.log('success!'); // } catch (err) { // console.error(err); // } // }
// Async/Await: async function moverwpcontentpriv () { if ( fs.pathExists(srcwpcontentpriv)) { try { // createdirwpcontent(); await fs.move( srcwpcontentpriv, dstwpcontent, {overwrite: true}); await fs.remove(srcwpcontent); // await fs.remove(srcwpcontent); // await fs.ensureSymlink( dstwpcontent, srcwpcontent, 'dir'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", moverwpcontentpriv); } };
// Async/Await: async function moverwpcontent () { if ( fs.pathExists(srcwpcontent)) { try { // createdirwpcontent(); await fs.move( srcwpcontent, dstwpcontent, {overwrite: true}); // await fs.remove(srcwpcontent); // await fs.ensureSymlink( dstwpcontent, srcwpcontent, 'dir'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", moverwpcontent); } };
gulp.task('tmoverwpcontent', function(done) { moverwpcontent(); done(); });
gulp.task('tmoverwpcontentpriv', function(done) { moverwpcontentpriv(); done(); });
// Async/Await: async function moverwpconfigpriv () {
if ( fs.pathExists(srcwpconfigpriv)) { try { await fs.move( srcwpconfigpriv, dstwpconfig, {overwrite: true}); await fs.remove( '/opt/app-root/src/wp-config-sample.php'); // await fs.remove(srcwpconfig); // await fs.ensureSymlink( dstwpconfig, srcwpconfig, 'file'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", srcwpconfigpriv); }
};
// Async/Await: async function moverwpconfig () {
if ( fs.pathExists(srcwpconfig)) { try { await fs.move( srcwpconfig, dstwpconfig, {overwrite: true}); fs.remove( '/opt/app-root/src/wp-config-sample.php'); // await fs.remove(srcwpconfig); // await fs.ensureSymlink( dstwpconfig, srcwpconfig, 'file'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", srcwpconfig); }
};
gulp.task('tmoverwpconfigpriv', function(done) { moverwpconfigpriv(); done(); });
gulp.task('tmoverwpconfig', function(done) { moverwpconfig(); done(); });
// Async/Await: async function moverwphtcaccesspriv () { if ( fs.pathExists(srcwphtcaccesspriv)) { try { await fs.move( srcwphtcaccesspriv, dstwphtcaccess, {overwrite: true}); await fs.remove(srcwphtcaccess); //await fs.ensureSymlink( dstwphtcaccess, srcwphtcaccess, 'file'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", srcwphtcaccesspriv); } };
// Async/Await: async function moverwphtcaccess () { if ( fs.pathExists(srcwphtcaccess)) { try { await fs.move( srcwphtcaccess, dstwphtcaccess, {overwrite: true}); await fs.remove(srcwphtcaccess); //await fs.ensureSymlink( dstwphtcaccess, srcwphtcaccess, 'file'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", srcwphtcaccesspriv); } };
gulp.task('tmoverwphtcaccesspriv', function(done) { moverwphtcaccesspriv(); done(); });
gulp.task('tmoverwphtcaccess', function(done) { moverwphtcaccess(); done(); });
gulp.task('createSymlinkwpconfig', async function(done) {
if ( fs.pathExists(dstwpconfig)) { try { await fs.ensureSymlink( dstwpconfig, srcwpconfig, 'file'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", srcwpconfig); }; done(); });
gulp.task('createSymlinkhtcaccess', async function(done) {
if ( fs.pathExists(dstwphtcaccess)) { try { await fs.ensureSymlink( dstwphtcaccess, srcwphtcaccess, 'file'); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", srcwpconfig); }; done(); });
gulp.task('removewpconfig', async function(done) {
if ( fs.pathExists(srcwpconfig)) { try { await fs.remove(srcwpconfig); console.log('success!'); } catch (err) { console.error(err); } } else { console.log("No existe el archivo ", srcwpconfig); }; done(); });
gulp.task('tmoveyaddwpconfig', function() { if ( (fs.pathExists(srcwpconfig)) && (! fs.existsSync(dstwpconfig) )) { // return gulp.src([srcwpconfig,'/opt/app-root/src/add-wp-config-php'],{ sourcemaps: true }, {allowEmpty:true}) return gulp.src([srcwpconfig,'/opt/app-root/src/add-wp-config-php'],{allowEmpty:true}) .pipe(concat( 'wp-config.php')) // .pipe(concat({ path: 'wp-config.php', stat: { mode: '0777' }})) .pipe(gulp.dest('/silo/wordpress')); } else { return console.log("Nada por hacer. "); };
});
gulp.task('enlacesSymlinkpriv', gulp.series('createSymlinkwpconfig','createSymlinkhtcaccess'));
// gulp.task('task-kill', function() { // console.log("before kill task");
// process.exit(0);
// console.log("after kill task"); // });
gulp.task('watch', function(done) { // gulp.watch('/opt/app-root/src/wp-content',gulp.series('tmoverwpcontent')); // gulp.watch('/opt/app-root/src/.htcaccess',gulp.series('tmoverwphtcaccess')); gulp.watch('/opt/app-root/src/*/wp-confi?.php', gulp.series('tmoveyaddwpconfig','removewpconfig','createSymlinkwpconfig', 'tmoverwpcontent','tmoverwphtcaccess','createSymlinkhtcaccess',)); // gulp.watch('/silo/wordpdres/', gulp.series('createSymlinkwpconfig', 'createSymlinkhtcaccess')); // gulp.watch('/opt/silo/wordpdres/*', gulp.series('createSymlinkwpconfig', 'createSymlinkhtcaccess', 'task-kill'));
// gulp.watch('/opt/app-root/src/wp-config.php', { ignoreInitial: false },{events: ['add']}, gulp.series('tmoveyaddwpconfig')); done(); });
gulp.task('default', gulp.series('watch'));
//##########################################################
// // With async/await: // async function createdirwpcontent () { // try { // await fs.emptyDir('/silo/wordpress,wp-content'); // console.log('success!'); // } catch (err) { // console.error(err); // } // }
// // Async/Await: // async function linkremovewpcontentwpconfightcaccess () { // try { // await fs.remove(srcwpcontent); // await fs.remove(srcwpconfig); // await fs.ensureSymlink( dstwpcontent, srcwpcontent, 'dir'); // await fs.ensureSymlink( dstwpconfig, srcwpconfig, 'file'); // if ( fs.pathExists(dstwphtcaccess)) { // try { // await fs.remove(srcwphtcaccess); // await fs.ensureSymlink( dstwphtcaccess, srcwphtcaccess, 'file'); // console.log('success!'); // } catch (err) { // console.error(err); // } // } else { // console.log("No existe el archivo ", dstwphtcaccess); // }
// console.log('success!'); // } catch (err) { // console.error(err); // } // }
// // Async/Await: // async function moverwpcontent () { // try { // createdirwpcontent(); // await fs.move( srcwpcontent, dstwpcontent, {overwrite: true}); // // await fs.remove(srcwpcontent); // // await fs.ensureSymlink( dstwpcontent, srcwpcontent, 'dir'); // console.log('success!'); // } catch (err) { // console.error(err); // } // }
// // Async/Await: // async function moverwpconfig () {
// if ( fs.pathExists(srcwpconfig)) { // try { // await fs.move( srcwpconfig, dstwpconfig, {overwrite: true}); // // await fs.remove(srcwpconfig); // await fs.ensureSymlink( dstwpconfig, srcwpconfig, 'file'); // console.log('success!'); // } catch (err) { // console.error(err); // } // } else { // console.log("No existe el archivo ", srcwpconfig); // }
// }
// // Async/Await: // async function moverwphtcaccess () { // if ( fs.pathExists(srcwphtcaccess)) { // try { // await fs.move( srcwphtcaccess, dstwphtcaccess, {overwrite: true}); // // await fs.remove(srcwphtcaccess); // await fs.ensureSymlink( dstwphtcaccess, srcwphtcaccess, 'file'); // console.log('success!'); // } catch (err) { // console.error(err); // } // } else { // console.log("No existe el archivo ", srcwphtcaccess); // } // }
// // async function crearlinkwpcontent () { // // try { // // await fs.ensureSymlink( srcwpcontent, dstwpcontent, 'dir'); // // console.log('success!'); // // } catch (err) { // // console.error(err); // // } // // }
// // async function crearlinkwpconfig () { // // try { // // await fs.ensureSymlink( dstwpconfig, srcwpconfig); // // console.log('success!'); // // } catch (err) { // // console.error(err); // // } // // }
// // async function crearlinkwphtcaccess () { // // try { // // await fs.ensureSymlink (srcwphtaccess, dstwphtaccess); // // console.log('success!'); // // } catch (err) { // // console.error(err); // // } // // }
// gulp.task('tlinkremovewpcontentwpconfightcaccess', function(done) { // linkremovewpcontentwpconfightcaccess(); // done(); // });
// gulp.task('tmoverwpcontent', function(done) { // moverwpcontent(); // done(); // });
// gulp.task('tmoverwpconfig', function(done) { // moverwpconfig(); // done(); // });
// gulp.task('tmoverwphtcaccess', function(done) { // moverwphtcaccess(); // done(); // });
// gulp.task('watch', function(done) { // // gulp.watch('/opt/app-root/src/wp-content',gulp.series('tmoverwpcontent')); // // gulp.watch('/opt/app-root/src/.htcaccess',gulp.series('tmoverwphtcaccess')); // gulp.watch('/opt/app-root/src/wp-config.php',gulp.series('tmoverwpconfig', 'tmoverwpcontent', 'tmoverwphtcaccess')); // done(); // });
// gulp.task('default', gulp.parallel('watch'));
The file test_connect_db.php we test connection wodrpress (php) to databse: \<?php $dbhost = getenv("MYSQL_SERVICE_HOST"); $dbport = getenv("MYSQL_SERVICE_PORT"); $dbuser = getenv("databaseuser"); $dbpwd = getenv("databasepassword"); $dbname = getenv("databasename"); $connection = new mysqli($dbhost, $dbuser, $dbpwd, $dbname); if ($connection->connect_errno) { printf("Connect failed: %s\n", $mysqli->connect_error); exit(); } else { printf("Connected to the database"); } $connection->close(); ?>
Create folder /contexto with this files:
y the folder contexto/builder: