Skip to content

Commit

Permalink
Improve database selection. (#31)
Browse files Browse the repository at this point in the history
* Improve database selection.

* Remove laravel references.

* Update little doc issues.

* Reorganize tests in more standardized fashion.

* Add default config for mysql/mariadb. Improve db selection logic.

* Fix issues with config loading.

* Fix downstreamer tests.
  • Loading branch information
reynoldsalec authored Mar 6, 2024
1 parent bb11621 commit 6d0119a
Show file tree
Hide file tree
Showing 23 changed files with 524 additions and 20 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/pr-mean-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ jobs:
fail-fast: false
matrix:
leia-test:
- examples/mean
- examples/custom
- examples/mean-custom
- examples/mean-defaults
- examples/mean-downstreamer-1
- examples/mean-downstreamer-2
lando-version:
- 3-dev-slim
os:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v1.0.1 - [March 4, 2024](https://github.com/lando/mean/releases/tag/v1.0.1)

### Fixes

* Improved `database` selection for purposes of `config` loading, fixes some `database` bootup issues when the `database` type is overriden downstream

## v1.0.0 - [December 7, 2023](https://github.com/lando/mean/releases/tag/v1.0.0)
* Dialed fully for `lando update`

Expand Down
43 changes: 42 additions & 1 deletion builders/mean.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,52 @@

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

/*
* Helper to get database type
*/
const getDatabaseType = options => {
return _.get(options, '_app.config.services.database.type', options.database) ?? 'mysql';
};

// Tooling defaults
const toolingDefaults = {
node: {service: 'appserver'},
npm: {service: 'appserver'},
yarn: {service: 'appserver'},
};

/*
* Helper to get config defaults
*/
const getConfigDefaults = options => {
// attempt to discover the database that is actually being used
// @NOTE: this will look to see if database is overridden
const dbConfig = getDatabaseType(options);
const database = _.first(dbConfig.split(':'));
const version = _.last(dbConfig.split(':')).substring(0, 2);
if (database.includes('mysql') || database.includes('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
*/
Expand Down Expand Up @@ -53,18 +89,23 @@ module.exports = {
confSrc: path.resolve(__dirname, '..', 'config'),
command: 'npm start',
database: 'mongo:7.0',
defaultFiles: {
},
globals: {},
node: '18',
port: '80',
ssl: false,
proxy: {},
},
builder: (parent, config) => class LandoMean extends parent {
constructor(id, options = {}) {
options = _.merge({}, config, options);
options.defaultFiles = _.merge({}, getConfigDefaults(_.cloneDeep(options)), options.defaultFiles);
options.services = _.merge({}, getServices(options), options.services);
options.tooling = _.merge({}, getTooling(options), options.tooling);
options.proxy = _.set({}, 'appserver', [`${options.app}.${options._app._config.domain}:${options.port}`]);
super(id, options);
// Send downstream
super(id, _.merge({}, config, options));
};
},
};
110 changes: 110 additions & 0 deletions config/mysql.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#
# The MySQL database server configuration file for Lando
# LANDOMEANMYSQLCNF

[mysqld]
#
# * Basic Settings
#
# Data is stored in a volume on the db container /sql
default-storage-engine = innodb

#
# * Fine Tuning
#
key_buffer_size = 384M
max_allowed_packet = 32M
thread_stack = 400K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M

#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 64M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /src/.lando/log/mysql.log
#general_log = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /src/.lando/log/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# Uncomment the following if you are using InnoDB tables
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 384M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 101M
#innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 0
#innodb_lock_wait_timeout = 50
innodb_buffer_pool_size = 384M
innodb_log_buffer_size = 4M
innodb_file_per_table = 1
innodb_open_files = 256
innodb_io_capacity = 512
innodb_flush_method = O_DIRECT
innodb_thread_concurrency = 8
innodb_lock_wait_timeout = 121
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

[mysqldump]
quick
quote-names
max_allowed_packet = 32M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completion

[isamchk]
key_buffer_size = 384M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
105 changes: 105 additions & 0 deletions config/mysql8.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# The MySQL database server configuration file for Lando
# LANDOMEANMYSQL8CNF

[mysqld]
#
# * Basic Settings
#
# Data is stored in a volume on the db container /sql
default-storage-engine = innodb

#
# * Fine Tuning
#
key_buffer_size = 384M
max_allowed_packet = 32M
thread_stack = 400K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /src/.lando/log/mysql.log
#general_log = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /src/.lando/log/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 101M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# Uncomment the following if you are using InnoDB tables
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 384M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 100M
#innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 0
#innodb_lock_wait_timeout = 50
innodb_buffer_pool_size = 384M
innodb_log_buffer_size = 4M
innodb_file_per_table = 1
innodb_open_files = 256
innodb_io_capacity = 512
innodb_flush_method = O_DIRECT
innodb_thread_concurrency = 8
innodb_lock_wait_timeout = 127
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

[mysqldump]
quick
quote-names
max_allowed_packet = 32M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completion

[isamchk]
key_buffer_size = 384M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
2 changes: 1 addition & 1 deletion docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function sidebar() {
{text: 'Overview', link: '/'},
{text: 'Installation', link: '/install'},
{text: 'Getting Started', link: '/getting-started'},
{text: 'Usage', link: '/config'},
{text: 'Configuration', link: '/config'},
{text: 'Tooling', link: '/tooling'},
],
},
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Lando offers a configurable [recipe](https://docs.lando.dev/core/v3/recipes.html
#### Features of this plugin:

* Configurable `node` version from `6` all the way to `16`
* Configurable database backend (`mariadb`, '`mongo`, `mysql`, or `postgres`)
* Configurable database backend (`mariadb`, `mongo`, `mysql`, or `postgres`)
* Setting start commands at recipe level
* Install global dependencies at recipe level

2 changes: 2 additions & 0 deletions examples/.lando.upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins:
"@lando/mean": ../..
File renamed without changes.
12 changes: 12 additions & 0 deletions examples/mean-custom/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: lando-mean-mysql
recipe: mean
config:
node: '14'
port: '8055'
database: mysql
config:
database: config/mysql.cnf

# do not remove this
plugins:
"@lando/mean": ../..
Loading

0 comments on commit 6d0119a

Please sign in to comment.