Skip to content

Commit f646452

Browse files
authored
hardcore (#26)
* 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.
1 parent cb3f4ba commit f646452

20 files changed

+78
-24
lines changed

.github/workflows/pr-docs-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
os:
1212
- ubuntu-22.04
1313
node-version:
14-
- '16'
14+
- '18'
1515
steps:
1616
# Install deps and cache
1717
- name: Checkout code

.github/workflows/pr-linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
os:
1212
- ubuntu-22.04
1313
node-version:
14-
- '16'
14+
- '18'
1515
steps:
1616
# Install deps and cache
1717
- name: Checkout code

.github/workflows/pr-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- ubuntu-22.04
1414
- macos-12
1515
node-version:
16-
- '16'
16+
- '18'
1717
steps:
1818
# Install deps and cache
1919
- name: Checkout code

.github/workflows/pr-varnish-tests.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
os:
2121
- ubuntu-22.04
2222
node-version:
23-
- '16'
23+
- '18'
2424
steps:
2525

2626
- name: Checkout code
@@ -38,12 +38,9 @@ jobs:
3838
with:
3939
lando-version: ${{ matrix.lando-version }}
4040
config: |
41-
plugins.@lando/varnish=/home/runner/work/varnish/varnish
41+
setup.skipCommonPlugins=true
42+
setup.plugins.@lando/varnish=/home/runner/work/varnish/varnish
4243
telemetry: false
43-
- name: Verify Lando works and we are dogfooding this plugin for tests
44-
run: |
45-
lando version
46-
lando config --path plugins | grep varnish | grep /home/runner/work/varnish/varnish || (echo "::error:: Not dogfooding this plugin correctly!" && exit 1)
4744
- name: Run Leia Tests
4845
uses: lando/run-leia-action@v2
4946
with:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
os:
1818
- ubuntu-22.04
1919
node-version:
20-
- '16'
20+
- '18'
2121
steps:
2222
# Install deps and cache
2323
- name: Checkout code

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16
1+
18

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.9.0 - [November 15, 2023](https://github.com/lando/varnish/releases/tag/v0.9.0)
2+
* Moved builder file to the new builders/ directory.
3+
* Isolated testing to fit with HARDCORE strategy.
4+
15
## v0.8.0 - [July 3, 2023](https://github.com/lando/varnish/releases/tag/v0.8.0)
26
* Removed bundle-dependencies and version-bump-prompt from plugin.
37
* Updated package to use prepare-release-action.

services/varnish/builder.js renamed to builders/varnish.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

33
// Modules
4+
const fs = require('fs');
5+
const path = require('path');
46
const _ = require('lodash');
5-
const utils = require('./../../lib/utils');
67

78
// Helper to get varnsh ssl nginx
89
const varnishSsl = options => ({
@@ -22,14 +23,44 @@ const varnishSsl = options => ({
2223
],
2324
});
2425

26+
// Add hardcoded varnishServices to lando.factory.registry.
27+
const addDependencies = options => {
28+
const lando = _.get(options, '_app._lando');
29+
// Traverse registry and remove any services that we have locally
30+
const varnishServices = ['nginx'];
31+
_.remove(lando.factory.registry, service => {
32+
return _.includes(varnishServices, service.name);
33+
});
34+
35+
// Make an array of absolute paths to the plugins we need to add
36+
const varnishServicesPath = varnishServices.map(service => {
37+
return path.join(__dirname, `../node_modules/@lando/${service}`);
38+
});
39+
40+
// Loop that array and add each plugin to the registry and move scripts if the folder exists.
41+
varnishServicesPath.forEach(servicePath => {
42+
// Add the plugin to the registry
43+
lando.factory.add(path.join(servicePath, 'builders', `${servicePath.split('/').pop()}.js`));
44+
45+
// Move the script to the conDir and make executable.
46+
if (fs.existsSync(path.join(servicePath, 'scripts'))) {
47+
const confDir = path.join(lando.config.userConfRoot, 'scripts');
48+
const dest = lando.utils.moveConfig(path.join(servicePath, 'scripts'), confDir);
49+
lando.utils.makeExecutable(fs.readdirSync(dest), dest);
50+
lando.log.debug('automoved scripts from %s to %s and set to mode 755',
51+
path.join(servicePath, 'scripts'), confDir);
52+
}
53+
});
54+
};
55+
2556
// Builder
2657
module.exports = {
2758
name: 'varnish',
2859
config: {
2960
version: '4.1',
3061
supported: ['6', '6.0', '4', '4.1'],
3162
backends: ['appserver'],
32-
confSrc: __dirname,
63+
confSrc: path.resolve(__dirname, '..', 'config'),
3364
backend_port: '80',
3465
ssl: false,
3566
sslExpose: false,
@@ -45,6 +76,8 @@ module.exports = {
4576
builder: (parent, config) => class LandoVarnish extends parent {
4677
constructor(id, options = {}, factory) {
4778
options = _.merge({}, config, options);
79+
addDependencies(options);
80+
4881
// Arrayify the backend
4982
if (!_.isArray(options.backends)) options.backends = [options.backends];
5083
// Build the default stuff here
@@ -87,7 +120,7 @@ module.exports = {
87120
config: `${options.confDest}/${options.defaultFiles.ssl}`,
88121
info: {backend: 'edge', managed: true},
89122
meUser: 'www-data',
90-
overrides: utils.cloneOverrides(options.overrides),
123+
overrides: require('../utils/clone-overrides')(options.overrides),
91124
ssl: true,
92125
sslExpose: true,
93126
});
File renamed without changes.

examples/4.x/.lando.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ services:
88
# This is important because it lets lando know to test against the plugin in this repo
99
# DO NOT REMOVE THIS!
1010
plugins:
11-
"@lando/varnish": ./../../
11+
"@lando/varnish": ./../../
12+
"@lando/nginx": ./../../node_modules/@lando/nginx

examples/4.x/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Verification commands
2222
Run the following commands to validate things are rolling as they should.
2323

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

2828
# Should backend from appserver by default
2929
lando ssh -s defaults -c "curl localhost | grep sophisticated"

examples/6.x/.lando.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ services:
88
# This is important because it lets lando know to test against the plugin in this repo
99
# DO NOT REMOVE THIS!
1010
plugins:
11-
"@lando/varnish": ./../../
11+
"@lando/varnish": ./../../
12+
"@lando/nginx": ./../../node_modules/@lando/nginx

examples/6.x/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Verification commands
2222
Run the following commands to validate things are rolling as they should.
2323

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

2828
# Should backend from appserver by default
2929
lando ssh -s defaults -c "curl localhost | grep sophisticated"

examples/custom/.lando.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: lando-varnish
22
services:
3-
appserver:
4-
type: nginx
53
custom:
64
type: varnish:4
75
backends:
@@ -18,6 +16,8 @@ services:
1816
- backend2
1917
backend_port: 8000
2018
ssl: true
19+
appserver:
20+
type: nginx
2121
backend2:
2222
type: python
2323
port: 8000
@@ -26,4 +26,6 @@ services:
2626
# This is important because it lets lando know to test against the plugin in this repo
2727
# DO NOT REMOVE THIS!
2828
plugins:
29-
"@lando/varnish": ./../../
29+
"@lando/varnish": ./../../
30+
"@lando/python": ./../../node_modules/@lando/python
31+
"@lando/nginx": ./../../node_modules/@lando/nginx

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@
4545
"test": "yarn lint && yarn test:unit"
4646
},
4747
"dependencies": {
48+
"@lando/nginx": "^0.10.0",
4849
"lodash": "^4.17.21"
4950
},
5051
"devDependencies": {
5152
"@babel/eslint-parser": "^7.16.0",
5253
"@lando/leia": "^0.6.5",
54+
"@lando/python": "^0.8.0",
5355
"@lando/vuepress-theme-default-plus": "1.0.0-beta.49",
5456
"chai": "^4.3.4",
5557
"command-line-test": "^1.0.10",

lib/utils.js renamed to utils/clone-overrides.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const _ = require('lodash');
77
* Helper to get global deps
88
* @TODO: this looks pretty testable? should services have libs?
99
*/
10-
exports.cloneOverrides = (overrides = {}) => {
10+
module.exports = (overrides = {}) => {
1111
const newOverrides = _.cloneDeep(overrides);
1212
if (_.has(newOverrides, 'image')) delete newOverrides.image;
1313
if (_.has(newOverrides, 'build')) delete newOverrides.build;

yarn.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,20 @@
474474
mocha "^5.2.0"
475475
object-hash "^2.2.0"
476476

477+
"@lando/nginx@^0.10.0":
478+
version "0.10.0"
479+
resolved "https://registry.yarnpkg.com/@lando/nginx/-/nginx-0.10.0.tgz#c2d63d112a615d19c4313b18bf2e97a7fcab0308"
480+
integrity sha512-aKpULGWimycpSYpQAqBtiFwt/zfXACxN59vugEnQNypVkVCPTzq0A2Gk2rcd41DaCpR8cmf8BM80Eqz+GeM7UA==
481+
dependencies:
482+
lodash "^4.17.21"
483+
484+
"@lando/python@^0.8.0":
485+
version "0.8.0"
486+
resolved "https://registry.yarnpkg.com/@lando/python/-/python-0.8.0.tgz#c3dc1a35a7595271e0973ec72de8d2918f0cac51"
487+
integrity sha512-ovOjuGoOV6hhXmRfEp04fICafMcBilN9fYe0c/llDQrhOJZloH1Oj4aKJUNrlhUnmtiJvoXuzh6AE+ujnL+Dew==
488+
dependencies:
489+
lodash "^4.17.21"
490+
477491
478492
version "1.0.0-beta.49"
479493
resolved "https://registry.yarnpkg.com/@lando/vuepress-theme-default-plus/-/vuepress-theme-default-plus-1.0.0-beta.49.tgz#857476a02680845522ff9db06316e6f22143a2a6"

0 commit comments

Comments
 (0)