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

Move _lamp.js from core to lamp.js builder. Purge LEMP stuff. #38

Merged
merged 23 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
34f0bf7
Move _lamp.js from core to lamp.js builder. Purge LEMP stuff.
reynoldsalec Oct 31, 2023
2516eed
Remove dogfooding test.
reynoldsalec Oct 31, 2023
a5fa8ea
Change class name to LandoLamp/purge more nginx.
reynoldsalec Oct 31, 2023
70468ac
Update LAMP test with new setup logic.
reynoldsalec Nov 6, 2023
99bbdc5
Revert "Update LAMP test with new setup logic."
reynoldsalec Nov 6, 2023
f9ab056
Use our own service dependency versions.
reynoldsalec Nov 7, 2023
f317e50
Revert "Revert "Update LAMP test with new setup logic.""
reynoldsalec Nov 7, 2023
a0174b9
Feed the linter.
reynoldsalec Nov 7, 2023
daf8aea
Try OG PHP to get around dependency issue.
reynoldsalec Nov 7, 2023
413aa01
Try changing the order of services.
reynoldsalec Nov 7, 2023
b5e7b2e
Debugging code.
reynoldsalec Nov 7, 2023
9d1727c
Update node to 18 and add debugging code.
reynoldsalec Nov 7, 2023
0f51df9
More debugging code yay.
reynoldsalec Nov 7, 2023
ec2d81d
See if plugins exist in test runner dir.
reynoldsalec Nov 7, 2023
603dd78
Add bundle deps step.
reynoldsalec Nov 7, 2023
747baea
Use prepare-release-action to bundle deps.
reynoldsalec Nov 7, 2023
707142b
Remove debugging code. Update codeigniter version in Leia test.
reynoldsalec Nov 7, 2023
1c75773
Use @lando/php updated branch.
reynoldsalec Nov 8, 2023
79d9c1d
Script adding logic.
reynoldsalec Nov 9, 2023
cf3836c
Update to node 18.
reynoldsalec Nov 9, 2023
8db8f8c
Rerun netlify build.
reynoldsalec Nov 10, 2023
866fdf4
Update .node-version file.
reynoldsalec Nov 10, 2023
b53ab0e
Add back in nginx related settings.
reynoldsalec Nov 11, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/pr-docs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
os:
- ubuntu-22.04
node-version:
- '16'
- '18'
steps:
# Install deps and cache
- name: Checkout code
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/pr-lamp-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
os:
- ubuntu-22.04
node-version:
- '16'
- '18'
leia-test:
- examples/lamp
steps:
Expand All @@ -30,17 +30,20 @@ jobs:
cache: yarn
- name: Install Yarn dependencies
run: yarn install --prefer-offline --frozen-lockfile
- name: Bundle Deps
uses: lando/prepare-release-action@v2
with:
lando-plugin: true
version: dev
sync: false
- name: Setup lando ${{ matrix.lando-version }}
uses: lando/setup-lando@v2
with:
lando-version: ${{ matrix.lando-version }}
config: |
plugins.@lando/lamp=/home/runner/work/lamp/lamp
setup.skipCommonPlugins=true
setup.plugins.@lando/lamp=/home/runner/work/lamp/lamp
telemetry: false
- name: Verify Lando works and we are dogfooding this plugin for tests
run: |
lando version
lando config --path plugins | grep lamp | grep /home/runner/work/lamp/lamp || (echo "::error:: Not dogfooding this plugin correctly!" && exit 1)
- name: Run Leia Tests
uses: lando/run-leia-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
os:
- ubuntu-22.04
node-version:
- '16'
- '18'
steps:
# Install deps and cache
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- ubuntu-22.04
- macos-12
node-version:
- '16'
- '18'
steps:
# Install deps and cache
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
os:
- ubuntu-22.04
node-version:
- '16'
- '18'
steps:
# Install deps and cache
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
18
242 changes: 242 additions & 0 deletions builders/lamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
'use strict';

// Modules
const _ = require('lodash');
const fs = require('fs');
const path = require('path');

// Tooling defaults
const toolingDefaults = {
'composer': {
service: 'appserver',
cmd: 'composer --ansi',
},
'db-import <file>': {
service: ':host',
description: 'Imports a dump file into a database service',
cmd: '/helpers/sql-import.sh',
user: 'root',
options: {
'host': {
description: 'The database service to use',
default: 'database',
alias: ['h'],
},
'no-wipe': {
description: 'Do not destroy the existing database before an import',
boolean: true,
},
},
},
'db-export [file]': {
service: ':host',
description: 'Exports database from a database service to a file',
cmd: '/helpers/sql-export.sh',
user: 'root',
options: {
host: {
description: 'The database service to use',
default: 'database',
alias: ['h'],
},
stdout: {
description: 'Dump database to stdout',
},
},
},
'php': {
service: 'appserver',
cmd: 'php',
},
};

// Default DB cli commands
const mysqlCli = {
service: ':host',
description: 'Drops into a MySQL shell on a database service',
cmd: 'mysql -uroot',
options: {
host: {
description: 'The database service to use',
default: 'database',
alias: ['h'],
},
},
};
const postgresCli = {
service: ':host',
description: 'Drops into a psql shell on a database service',
cmd: 'psql -Upostgres',
user: 'root',
options: {
host: {
description: 'The database service to use',
default: 'database',
alias: ['h'],
},
},
};

/*
* Helper to get config defaults
*/
const getConfigDefaults = options => {
// Get the viaconf
if (_.startsWith(options.via, 'nginx')) options.defaultFiles.vhosts = 'default.conf.tpl';

// Get the default db conf
const dbConfig = _.get(options, 'database', 'mysql');
const database = _.first(dbConfig.split(':'));
const version = _.last(dbConfig.split(':')).substring(0, 2);
if (database === 'mysql' || database === 'mariadb') {
if (version === '8.') {
options.defaultFiles.database = 'mysql8.cnf';
} else {
options.defaultFiles.database = 'mysql.cnf';
}
}

// Verify files exist and remove if it doesn't
_.forEach(options.defaultFiles, (file, type) => {
if (!fs.existsSync(`${options.confDest}/${file}`)) {
delete options.defaultFiles[type];
}
});

// Return
return options.defaultFiles;
};

/*
* Helper to get services
*/
const getServices = options => ({
appserver: {
build_as_root_internal: options.build_root,
build_internal: options.build,
composer: options.composer,
composer_version: options.composer_version,
config: getServiceConfig(options),
run_as_root_internal: options.run_root,
ssl: true,
type: `php:${options.php}`,
via: options.via,
xdebug: options.xdebug,
webroot: options.webroot,
},
database: {
config: getServiceConfig(options, ['database']),
authentication: 'mysql_native_password',
type: options.database,
portforward: true,
creds: {
user: options.recipe,
password: options.recipe,
database: options.recipe,
},
},
});

/*
* Helper to get the phar build command
*/
const getDbTooling = database => {
// Make sure we strip out any version number
database = database.split(':')[0];
// Choose wisely
if (_.includes(['mysql', 'mariadb'], database)) {
return {mysql: mysqlCli};
} else if (database === 'postgres') {
return {psql: postgresCli};
} else if (database === 'mongo') {
return {mongo: {
service: 'database',
description: 'Drop into the mongo shell',
}};
}
};

/*
* Helper to get service config
*/
const getServiceConfig = (options, types = ['php', 'server', 'vhosts']) => {
const config = {};
_.forEach(types, type => {
if (_.has(options, `config.${type}`)) {
config[type] = options.config[type];
} else if (!_.has(options, `config.${type}`) && _.has(options, `defaultFiles.${type}`)) {
if (_.has(options, 'confDest')) {
config[type] = path.join(options.confDest, options.defaultFiles[type]);
}
}
});
return config;
};

/*
* Helper to get tooling
*/
const getTooling = options => _.merge({}, toolingDefaults, getDbTooling(options.database));

/*
* Build L(E)AMP
*/
module.exports = {
name: 'lamp',
parent: '_recipe',
config: {
confSrc: __dirname,
database: 'mysql',
defaultFiles: {
},
php: '7.4',
via: 'apache',
webroot: '.',
xdebug: false,
proxy: {},
},
builder: (parent, config) => class LandoLamp extends parent {
constructor(id, options = {}) {
const lando = _.get(options, '_app._lando');
// Traverse registry and remove any services that we have locally
const lampServices = ['php', 'mysql', 'mariadb', 'postgres', 'mongo'];
_.remove(lando.factory.registry, service => {
return _.includes(lampServices, service.name);
});

// Make an array of absolute paths to the plugins we need to add
const lampServicesPath = lampServices.map(service => {
return path.join(__dirname, `../node_modules/@lando/${service}`);
});

// Loop that array and add each plugin to the registry and move scripts if the folder exists.
lampServicesPath.forEach(servicePath => {
// Add the plugin to the registry
lando.factory.add(path.join(servicePath, 'builders', `${servicePath.split('/').pop()}.js`));

// Move the script to the conDir and make executable.
if (fs.existsSync(path.join(servicePath, 'scripts'))) {
const confDir = path.join(lando.config.userConfRoot, 'scripts');
const dest = lando.utils.moveConfig(path.join(servicePath, 'scripts'), confDir);
lando.utils.makeExecutable(fs.readdirSync(dest), dest);
lando.log.debug('automoved scripts from %s to %s and set to mode 755',
path.join(servicePath, 'scripts'), confDir);
}
});

options = _.merge({}, config, options);
// Rebase on top of any default config we might already have
options.defaultFiles = _.merge({}, getConfigDefaults(_.cloneDeep(options)), options.defaultFiles);
options.services = _.merge({}, getServices(options), options.services);
options.tooling = _.merge({}, getTooling(options), options.tooling);
// Switch the proxy if needed
if (!_.has(options, 'proxyService')) {
if (_.startsWith(options.via, 'nginx')) options.proxyService = 'appserver_nginx';
else if (_.startsWith(options.via, 'apache')) options.proxyService = 'appserver';
}
options.proxy = _.set(options.proxy, options.proxyService, [`${options.app}.${options._app._config.domain}`]);
// Downstream
super(id, options);
};
},
};
2 changes: 1 addition & 1 deletion examples/lamp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lando poweroff

# Should initialize the latest codeignitor codebase
rm -rf lamp && mkdir -p lamp && cd lamp
lando init --source remote --remote-url https://github.com/bcit-ci/CodeIgniter/archive/3.1.10.tar.gz --remote-options="--strip-components 1" --recipe lamp --webroot . --name lando-lamp --option composer_version=1.10.1
lando init --source remote --remote-url https://github.com/bcit-ci/CodeIgniter/archive/3.1.13.tar.gz --remote-options="--strip-components 1" --recipe lamp --webroot . --name lando-lamp --option composer_version=1.10.1
cp -f ../.lando.local.yml .lando.local.yml && cat .lando.local.yml

# Should start up successfully
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lamp"
],
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"bundledDependencies": [
"lodash"
Expand Down Expand Up @@ -45,6 +45,11 @@
"test": "yarn lint && yarn test:unit"
},
"dependencies": {
"@lando/mariadb": "^0.9.0",
"@lando/mongo": "^0.9.0",
"@lando/mysql": "^0.9.0",
"@lando/php": "https://github.com/lando/php#66-remove-multiviews",
"@lando/postgres": "^0.10.0",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
25 changes: 0 additions & 25 deletions recipes/lamp/builder.js

This file was deleted.

Loading
Loading