Skip to content

Commit

Permalink
hardcore (#26)
Browse files Browse the repository at this point in the history
* Convert to new builder format, update node to 18.x.

* Standalone test, remove dogfood check.

* Include path module.

* Load nginx dependency.

* Add fs as dependency.

* Correct directory path for node_modules

* Update tests to reflect unpinned varnish.

* Add in python for testing the custom case.

* Explicitly include nginx as plugin in Landofile for test cases.

* Update changelog.

* Fix typo.
  • Loading branch information
reynoldsalec authored Nov 15, 2023
1 parent cb3f4ba commit f646452
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-docs-tests.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-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 @@ -13,7 +13,7 @@ jobs:
- ubuntu-22.04
- macos-12
node-version:
- '16'
- '18'
steps:
# Install deps and cache
- name: Checkout code
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/pr-varnish-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
os:
- ubuntu-22.04
node-version:
- '16'
- '18'
steps:

- name: Checkout code
Expand All @@ -38,12 +38,9 @@ jobs:
with:
lando-version: ${{ matrix.lando-version }}
config: |
plugins.@lando/varnish=/home/runner/work/varnish/varnish
setup.skipCommonPlugins=true
setup.plugins.@lando/varnish=/home/runner/work/varnish/varnish
telemetry: false
- name: Verify Lando works and we are dogfooding this plugin for tests
run: |
lando version
lando config --path plugins | grep varnish | grep /home/runner/work/varnish/varnish || (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/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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.9.0 - [November 15, 2023](https://github.com/lando/varnish/releases/tag/v0.9.0)
* Moved builder file to the new builders/ directory.
* Isolated testing to fit with HARDCORE strategy.

## v0.8.0 - [July 3, 2023](https://github.com/lando/varnish/releases/tag/v0.8.0)
* Removed bundle-dependencies and version-bump-prompt from plugin.
* Updated package to use prepare-release-action.
Expand Down
39 changes: 36 additions & 3 deletions services/varnish/builder.js → builders/varnish.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

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

// Helper to get varnsh ssl nginx
const varnishSsl = options => ({
Expand All @@ -22,14 +23,44 @@ const varnishSsl = options => ({
],
});

// Add hardcoded varnishServices to lando.factory.registry.
const addDependencies = options => {
const lando = _.get(options, '_app._lando');
// Traverse registry and remove any services that we have locally
const varnishServices = ['nginx'];
_.remove(lando.factory.registry, service => {
return _.includes(varnishServices, service.name);
});

// Make an array of absolute paths to the plugins we need to add
const varnishServicesPath = varnishServices.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.
varnishServicesPath.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);
}
});
};

// Builder
module.exports = {
name: 'varnish',
config: {
version: '4.1',
supported: ['6', '6.0', '4', '4.1'],
backends: ['appserver'],
confSrc: __dirname,
confSrc: path.resolve(__dirname, '..', 'config'),
backend_port: '80',
ssl: false,
sslExpose: false,
Expand All @@ -45,6 +76,8 @@ module.exports = {
builder: (parent, config) => class LandoVarnish extends parent {
constructor(id, options = {}, factory) {
options = _.merge({}, config, options);
addDependencies(options);

// Arrayify the backend
if (!_.isArray(options.backends)) options.backends = [options.backends];
// Build the default stuff here
Expand Down Expand Up @@ -87,7 +120,7 @@ module.exports = {
config: `${options.confDest}/${options.defaultFiles.ssl}`,
info: {backend: 'edge', managed: true},
meUser: 'www-data',
overrides: utils.cloneOverrides(options.overrides),
overrides: require('../utils/clone-overrides')(options.overrides),
ssl: true,
sslExpose: true,
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion examples/4.x/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/varnish": ./../../
"@lando/varnish": ./../../
"@lando/nginx": ./../../node_modules/@lando/nginx
4 changes: 2 additions & 2 deletions examples/4.x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Verification commands
Run the following commands to validate things are rolling as they should.

```bash
# Should use varnish 4.1 by default
lando ssh -s defaults -c "varnishd -V 2>&1 | grep varnish-4.1.11"
# Should use varnish 4.x by default
lando ssh -s defaults -c "varnishd -V 2>&1 | grep varnish-4"

# Should backend from appserver by default
lando ssh -s defaults -c "curl localhost | grep sophisticated"
Expand Down
3 changes: 2 additions & 1 deletion examples/6.x/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/varnish": ./../../
"@lando/varnish": ./../../
"@lando/nginx": ./../../node_modules/@lando/nginx
4 changes: 2 additions & 2 deletions examples/6.x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Verification commands
Run the following commands to validate things are rolling as they should.

```bash
# Should use varnish 6.0.10 by user specification
lando ssh -s defaults -c "varnishd -V 2>&1 | grep varnish-6.0.11"
# Should use varnish 6.x
lando ssh -s defaults -c "varnishd -V 2>&1 | grep varnish-6"

# Should backend from appserver by default
lando ssh -s defaults -c "curl localhost | grep sophisticated"
Expand Down
8 changes: 5 additions & 3 deletions examples/custom/.lando.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: lando-varnish
services:
appserver:
type: nginx
custom:
type: varnish:4
backends:
Expand All @@ -18,6 +16,8 @@ services:
- backend2
backend_port: 8000
ssl: true
appserver:
type: nginx
backend2:
type: python
port: 8000
Expand All @@ -26,4 +26,6 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/varnish": ./../../
"@lando/varnish": ./../../
"@lando/python": ./../../node_modules/@lando/python
"@lando/nginx": ./../../node_modules/@lando/nginx
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@
"test": "yarn lint && yarn test:unit"
},
"dependencies": {
"@lando/nginx": "^0.10.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"@babel/eslint-parser": "^7.16.0",
"@lando/leia": "^0.6.5",
"@lando/python": "^0.8.0",
"@lando/vuepress-theme-default-plus": "1.0.0-beta.49",
"chai": "^4.3.4",
"command-line-test": "^1.0.10",
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js → utils/clone-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const _ = require('lodash');
* Helper to get global deps
* @TODO: this looks pretty testable? should services have libs?
*/
exports.cloneOverrides = (overrides = {}) => {
module.exports = (overrides = {}) => {
const newOverrides = _.cloneDeep(overrides);
if (_.has(newOverrides, 'image')) delete newOverrides.image;
if (_.has(newOverrides, 'build')) delete newOverrides.build;
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,20 @@
mocha "^5.2.0"
object-hash "^2.2.0"

"@lando/nginx@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@lando/nginx/-/nginx-0.10.0.tgz#c2d63d112a615d19c4313b18bf2e97a7fcab0308"
integrity sha512-aKpULGWimycpSYpQAqBtiFwt/zfXACxN59vugEnQNypVkVCPTzq0A2Gk2rcd41DaCpR8cmf8BM80Eqz+GeM7UA==
dependencies:
lodash "^4.17.21"

"@lando/python@^0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@lando/python/-/python-0.8.0.tgz#c3dc1a35a7595271e0973ec72de8d2918f0cac51"
integrity sha512-ovOjuGoOV6hhXmRfEp04fICafMcBilN9fYe0c/llDQrhOJZloH1Oj4aKJUNrlhUnmtiJvoXuzh6AE+ujnL+Dew==
dependencies:
lodash "^4.17.21"

"@lando/[email protected]":
version "1.0.0-beta.49"
resolved "https://registry.yarnpkg.com/@lando/vuepress-theme-default-plus/-/vuepress-theme-default-plus-1.0.0-beta.49.tgz#857476a02680845522ff9db06316e6f22143a2a6"
Expand Down

0 comments on commit f646452

Please sign in to comment.