Skip to content

Commit 5a1996f

Browse files
author
John Ouellet
authored
Add in builder + tests (#1)
* Add in builder + tests * Adjust tests
1 parent 404c5b5 commit 5a1996f

35 files changed

+8597
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Node Tests
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
leia-tests:
8+
runs-on: ${{ matrix.os }}
9+
env:
10+
TERM: xterm
11+
strategy:
12+
matrix:
13+
leia-tests:
14+
- examples/10
15+
- examples/12
16+
- examples/14
17+
- examples/16
18+
lando-versions:
19+
- edge
20+
os:
21+
- ubuntu-20.04
22+
node-version:
23+
- '14'
24+
steps:
25+
# Install deps and cache
26+
# Eventually it would be great if these steps could live in a separate YAML file
27+
# that could be included in line to avoid code duplication
28+
- name: Checkout code
29+
uses: actions/checkout@v2
30+
- name: Install node ${{ matrix.node-version }}
31+
uses: actions/setup-node@v2
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
- name: Get Yarn cache directory
35+
id: yarn-cache-dir-path
36+
run: echo "::set-output name=dir::$(yarn cache dir)"
37+
- name: Use Yarn cache
38+
uses: actions/cache@v2
39+
id: yarn-cache
40+
with:
41+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
42+
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
43+
- name: Install Yarn dependencies
44+
run: yarn install --prefer-offline --frozen-lockfile
45+
46+
# This block should eventually become use lando/actions-hyperdrive@v2
47+
- name: Verify Docker dependencies
48+
run: |
49+
docker --version | grep "20.10."
50+
docker-compose --version | grep "1.29."
51+
- name: Grab latest edge Lando CLI
52+
run: |
53+
sudo curl -fsSL -o /usr/local/bin/lando "https://files.lando.dev/cli/lando-linux-x64-${{ matrix.lando-versions }}"
54+
sudo chmod +x /usr/local/bin/lando
55+
- name: Move in lando config appropriate for testing
56+
run: |
57+
mkdir -p ~/.lando/cache
58+
cp -f actions-lando-config.yml ~/.lando/config.yml
59+
echo false > ~/.lando/cache/report_errors
60+
lando --clear
61+
- name: Verify Lando works and we are dogfooding this plugin for tests
62+
run: |
63+
lando version
64+
lando config --path plugins | grep node | grep /home/runner/work/node/node || echo "::error:: Not dogfooding this plugin correctly! "
65+
66+
# This block should eventually become use lando/actions-leia@v2
67+
# @NOTE? Do we want a way for our leia-action to configure apparmor since
68+
# this might break a whole bunch of tests? or is this literally just a thing
69+
# for the Lagoon mysql/mariadb container?
70+
- name: Configure apparmor
71+
run: |
72+
set -x
73+
sudo apt-get remove mysql-server --purge
74+
sudo apt-get install apparmor-profiles
75+
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
76+
- name: Run leia tests
77+
shell: bash
78+
run: yarn leia "./${{ matrix.leia-tests }}/README.md" -c 'Destroy tests' --stdin --shell bash

examples/10/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.log
3+
package-lock.json

examples/10/.lando.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: lando-node-10
2+
services:
3+
defaults:
4+
type: node:10
5+
build:
6+
- yarn
7+
command: /app/node_modules/.bin/nodemon src/app-http.js --watch src --ignore *.test.js
8+
custom:
9+
type: node:11
10+
ssl: true
11+
globals:
12+
gulp-cli: latest
13+
port: 3000
14+
build:
15+
- yarn
16+
command: /app/node_modules/.bin/nodemon src/app-https.js --watch src --ignore *.test.js
17+
custom2:
18+
type: node:11
19+
ssl: 4444
20+
port: 3000
21+
build:
22+
- yarn
23+
command: /app/node_modules/.bin/nodemon src/app-custom.js --watch src --ignore *.test.js
24+
patch:
25+
type: node:10.19.0
26+
cli:
27+
type: node
28+
29+
# This is important because it lets lando know to test against the plugin in this repo
30+
# DO NOT REMOVE THIS!
31+
plugins:
32+
"@lando/node": ./../../

examples/10/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
Node 10 Example
2+
===============
3+
4+
This example exists primarily to test the following documentation:
5+
6+
* [Node 10-11 Service](https://docs.devwithlando.io/tutorials/node.html)
7+
8+
Start up tests
9+
--------------
10+
11+
Run the following commands to get up and running with this example.
12+
13+
```bash
14+
# Should start up successfully
15+
lando poweroff
16+
lando start
17+
```
18+
19+
Verification commands
20+
---------------------
21+
22+
Run the following commands to validate things are rolling as they should.
23+
24+
```bash
25+
# Should use 10.x as the default version
26+
lando ssh -s defaults -c "env | grep NODE_VERSION=10."
27+
28+
# Should use a user specified version if given
29+
lando ssh -s custom -c "env | grep NODE_VERSION=11."
30+
31+
# Should use a user specified patch version if given
32+
lando ssh -s patch -c "env | grep NODE_VERSION=10.19.0"
33+
34+
# Should serve over port 80 by default
35+
lando ssh -s defaults -c "curl http://localhost | grep tune"
36+
37+
# Should set NODE_EXTRA_CA_CERTS with lando domain CA
38+
lando ssh -s defaults -c "env" | grep NODE_EXTRA_CA_CERTS | grep "$LANDO_CA_CERT"
39+
40+
# Should only serve over http by default
41+
lando ssh -s defaults -c "curl https://localhost" || echo $? | grep 1
42+
43+
# Should serve over specified ports if given
44+
lando ssh -s custom -c "curl http://localhost:3000 | grep tune"
45+
46+
# Should serve over https is ssl is set by user
47+
lando ssh -s custom -c "curl https://localhost | grep tune"
48+
49+
# Should serve over a custom https port if ssl is set to a specific port
50+
lando ssh -s custom2 -c "curl https://localhost:4444 | grep DANCING"
51+
52+
# Should run as root if it needs to
53+
lando ssh -s defaults -c "ps -a -u root" | grep "node" | wc -l | grep 2
54+
lando ssh -s defaults -c "ls -lsa /certs" | grep "root root" | wc -l | grep 10
55+
lando ssh -s custom -c "ps -a -u root" | grep "node" | wc -l | grep 2
56+
lando ssh -s custom -c "ls -lsa /certs" | grep "root root" | wc -l | grep 10
57+
58+
# Should run as node if it can
59+
lando ssh -s custom2 -c "ps -a -u node" | grep "node" | wc -l | grep 2
60+
lando ssh -s custom2 -c "ls -lsa /certs" | grep "node" | wc -l | grep 8
61+
62+
# Should install global dependencies if specified by user and have them available in PATH
63+
lando ssh -s custom -c "gulp -v"
64+
lando ssh -s custom -c "which gulp | grep /var/www/.npm-global"
65+
66+
# Should PATH prefer node dependency binaries installed in /app/node_modules over global ones
67+
lando ssh -s custom -c "npm install gulp-cli --no-save"
68+
lando ssh -s custom -c "gulp -v"
69+
lando ssh -s custom -c "which gulp | grep /app/node_modules/.bin"
70+
lando ssh -s custom -c "npm uninstall gulp-cli"
71+
lando ssh -s custom -c "which gulp | grep /var/www/.npm-global"
72+
73+
# Should not serve port for cli
74+
lando ssh -s cli -c "curl http://localhost" || echo $? | grep 1
75+
```
76+
77+
Destroy tests
78+
-------------
79+
80+
Run the following commands to trash this app like nothing ever happened.
81+
82+
```bash
83+
# Should be destroyed with success
84+
lando destroy -y
85+
lando poweroff
86+
```

examples/10/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "node-lando",
3+
"version": "1.0.0",
4+
"description": "Node example for Lando",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/lando/lando/tree/master/examples/node"
12+
},
13+
"keywords": [
14+
"node",
15+
"docker",
16+
"localdev"
17+
],
18+
"author": "Mike Pirog",
19+
"license": "MIT",
20+
"dependencies": {
21+
"express": "^4.15.3"
22+
},
23+
"devDependencies": {
24+
"nodemon": "^1.17.2"
25+
}
26+
}

examples/10/src/app-custom.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Lando node express example
3+
*
4+
* @name taylorswift
5+
*/
6+
7+
'use strict';
8+
9+
// Load modules
10+
const fs = require('fs');
11+
const http = require('http');
12+
const https = require('https');
13+
const express = require('express');
14+
const app = express();
15+
16+
// Create our HTTPS server options
17+
const key = fs.readFileSync('/certs/cert.key');
18+
const cert = fs.readFileSync('/certs/cert.crt');
19+
20+
// Create our servers
21+
https.createServer({key, cert}, app).listen(4444);
22+
http.createServer(app).listen(3000);
23+
24+
// Basic HTTP response
25+
app.get('/', (req, res) => {
26+
res.header('Content-type', 'text/html');
27+
return res.end('<h1>DANCING DANCING STARLIGHT</h1>');
28+
});

examples/10/src/app-http.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Lando node express example
3+
*
4+
* @name taylorswift
5+
*/
6+
7+
'use strict';
8+
9+
// Load modules
10+
const http = require('http');
11+
const express = require('express');
12+
const app = express();
13+
14+
// Create our server
15+
http.createServer(app).listen(80);
16+
17+
// Basic HTTP response
18+
app.get('/', (req, res) => {
19+
res.header('Content-type', 'text/html');
20+
return res.end('<h1>I said "Oh my!" What a marvelous tune!!!</h1>');
21+
});

examples/10/src/app-https.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Lando node express example
3+
*
4+
* @name taylorswift
5+
*/
6+
7+
'use strict';
8+
9+
// Load modules
10+
const fs = require('fs');
11+
const http = require('http');
12+
const https = require('https');
13+
const express = require('express');
14+
const app = express();
15+
16+
// Create our HTTPS server options
17+
const key = fs.readFileSync('/certs/cert.key');
18+
const cert = fs.readFileSync('/certs/cert.crt');
19+
20+
// Create our servers
21+
https.createServer({key, cert}, app).listen(443);
22+
http.createServer(app).listen(3000);
23+
24+
// Basic HTTP response
25+
app.get('/', (req, res) => {
26+
res.header('Content-type', 'text/html');
27+
return res.end('<h1>I said "Oh my!" What a marvelous tune!!!</h1>');
28+
});

0 commit comments

Comments
 (0)