Skip to content

Commit

Permalink
use and allow nodejs 20 LTS (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Rainer Friederich <friederich@parkside-interactive.com>
  • Loading branch information
reynoldsalec and yobottehg committed Jan 2, 2024
1 parent 252f4e2 commit 75425c7
Show file tree
Hide file tree
Showing 11 changed files with 1,325 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-node-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- examples/18
- examples/18
- examples/19
- examples/20
lando-version:
- 3-dev-slim
os:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.1.0 - [January 2, 2023](https://github.com/lando/node/releases/tag/v1.1.0)
* Added support for Node 20. [#47](https://github.com/lando/node/issues/47)

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

Expand Down
10 changes: 10 additions & 0 deletions builders/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ const _ = require('lodash');

// Constants
const supportedVersions = [
'20',
'20.9',
'20.8',
'20.7',
'20.6',
'20.5',
'20.4',
'20.3',
'20.2',
'20.1',
'19',
'19.5',
'19.4',
Expand Down
3 changes: 3 additions & 0 deletions examples/20/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
package-lock.json
43 changes: 43 additions & 0 deletions examples/20/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: lando-node-20
services:
defaults:
type: node:20
build:
- yarn
command: /app/node_modules/.bin/nodemon src/app-http.js --watch src --ignore *.test.js
cli:
type: node
compass:
type: node:20
globals:
grunt-cli: latest
build_as_root:
- apt-get update -y
- apt-get install ruby-full -y
- gem install compass
custom:
type: node:20
ssl: true
globals:
gulp-cli: latest
port: 3000
build:
- yarn
command: /app/node_modules/.bin/nodemon src/app-https.js --watch src --ignore *.test.js
custom2:
type: node:20.9.0
ssl: 4444
port: 3000
build:
- yarn
command: /app/node_modules/.bin/nodemon src/app-custom.js --watch src --ignore *.test.js
tooling:
ruby:
service: compass
compass:
service: compass

# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/node": ./../../
91 changes: 91 additions & 0 deletions examples/20/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Node 20 Example
===============

This example exists primarily to test the following documentation:

* [Node 14-20 Service](https://docs.devwithlando.io/tutorials/node.html)
* [Installing compass in your node service](https://docs.lando.dev/guides/using-compass-on-a-lando-node-service.html)

Start up tests
--------------

Run the following commands to get up and running with this example.

```bash
# Should start up successfully
lando poweroff
lando start
```

Verification commands
---------------------

Run the following commands to validate things are rolling as they should.

```bash
# Should use 20.x as the default version
lando ssh -s defaults -c "env | grep NODE_VERSION=20."

# Should use a user specified version if given
lando ssh -s custom -c "env | grep NODE_VERSION=20."

# Should use a user specified patch version if given
lando ssh -s custom2 -c "env | grep NODE_VERSION=20.9.0"

# Should serve over port 80 by default
lando ssh -s defaults -c "curl http://localhost | grep tune"

# Should set NODE_EXTRA_CA_CERTS with lando domain CA
lando ssh -s defaults -c "env" | grep NODE_EXTRA_CA_CERTS | grep "$LANDO_CA_CERT"

# Should only serve over http by default
lando ssh -s defaults -c "curl https://localhost" || echo $? | grep 1

# Should serve over specified ports if given
lando ssh -s custom -c "curl http://localhost:3000 | grep tune"

# Should serve over https is ssl is set by user
lando ssh -s custom -c "curl https://localhost | grep tune"

# Should servce over a custom https port if ssl is set to a specific port
lando ssh -s custom2 -c "curl https://localhost:4444 | grep DANCING"

# Should run as root if it needs to
lando ssh -s defaults -c "ps -a -u root" | grep "node" | wc -l | grep 2
lando ssh -s defaults -c "ls -lsa /certs" | grep "root root" | wc -l | grep 10
lando ssh -s custom -c "ps -a -u root" | grep "node" | wc -l | grep 2
lando ssh -s custom -c "ls -lsa /certs" | grep "root root" | wc -l | grep 10

# Should run as node if it can
lando ssh -s custom2 -c "ps -a -u node" | grep "node" | wc -l | grep 2
lando ssh -s custom2 -c "ls -lsa /certs" | grep "node" | wc -l | grep 8

# Should install global dependencies if specified by user and have them available in PATH
lando ssh -s custom -c "gulp -v"
lando ssh -s custom -c "which gulp | grep /var/www/.npm-global"

# Should PATH prefer node dependency binaries installed in /app/node_modules over global ones
lando ssh -s custom -c "npm install gulp-cli --no-save"
lando ssh -s custom -c "gulp -v"
lando ssh -s custom -c "which gulp | grep /app/node_modules/.bin"
lando ssh -s custom -c "npm uninstall gulp-cli"
lando ssh -s custom -c "which gulp | grep /var/www/.npm-global"

# Should not serve port for cli
lando ssh -s cli -c "curl http://localhost" || echo $? | grep 1

# Should install ruby and compass on the compass service
lando ruby -v
lando compass -v
```

Destroy tests
-------------

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be destroyed with success
lando destroy -y
lando poweroff
```
27 changes: 27 additions & 0 deletions examples/20/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "node-lando",
"version": "1.0.0",
"description": "Node example for Lando",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/lando/lando/tree/master/examples/node"
},
"keywords": [
"node",
"docker",
"localdev"
],
"author": "Mike Pirog",
"license": "MIT",
"dependencies": {
"express": "^4.15.3"
},
"devDependencies": {
"grunt-contrib-compass": "^1.1.1",
"nodemon": "^3.0.1"
}
}
28 changes: 28 additions & 0 deletions examples/20/src/app-custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Lando node express example
*
* @name taylorswift
*/

'use strict';

// Load modules
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
const app = express();

// Create our HTTPS server options
const key = fs.readFileSync('/certs/cert.key');
const cert = fs.readFileSync('/certs/cert.crt');

// Create our servers
https.createServer({key, cert}, app).listen(4444);
http.createServer(app).listen(3000);

// Basic HTTP response
app.get('/', (req, res) => {
res.header('Content-type', 'text/html');
return res.end('<h1>DANCING DANCING STARLIGHT</h1>');
});
21 changes: 21 additions & 0 deletions examples/20/src/app-http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Lando node express example
*
* @name taylorswift
*/

'use strict';

// Load modules
const http = require('http');
const express = require('express');
const app = express();

// Create our server
http.createServer(app).listen(80);

// Basic HTTP response
app.get('/', (req, res) => {
res.header('Content-type', 'text/html');
return res.end('<h1>I said "Oh my!" What a marvelous tune!!!</h1>');
});
28 changes: 28 additions & 0 deletions examples/20/src/app-https.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Lando node express example
*
* @name taylorswift
*/

'use strict';

// Load modules
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
const app = express();

// Create our HTTPS server options
const key = fs.readFileSync('/certs/cert.key');
const cert = fs.readFileSync('/certs/cert.crt');

// Create our servers
https.createServer({key, cert}, app).listen(443);
http.createServer(app).listen(3000);

// Basic HTTP response
app.get('/', (req, res) => {
res.header('Content-type', 'text/html');
return res.end('<h1>I said "Oh my!" What a marvelous tune!!!</h1>');
});

0 comments on commit 75425c7

Please sign in to comment.