Skip to content

Commit 1f73f51

Browse files
author
John Ouellet
authored
Add in builder + tests (#1)
1 parent ffcaa87 commit 1f73f51

18 files changed

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

examples/4.x/.lando.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: lando-varnish-4
2+
services:
3+
defaults:
4+
type: varnish
5+
appserver:
6+
type: nginx
7+
8+
# This is important because it lets lando know to test against the plugin in this repo
9+
# DO NOT REMOVE THIS!
10+
plugins:
11+
"@lando/varnish": ./../../

examples/4.x/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Varnish Example
2+
===============
3+
4+
This example exists primarily to test the following documentation:
5+
6+
* [Varnish Service](https://docs.devwithlando.io/tutorials/varnish.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 varnish 4.1 by default
26+
lando ssh -s defaults -c "varnishd -V 2>&1 | grep varnish-4.1.11"
27+
28+
# Should backend from appserver by default
29+
lando ssh -s defaults -c "curl localhost | grep sophisticated"
30+
```
31+
32+
Destroy tests
33+
-------------
34+
35+
Run the following commands to trash this app like nothing ever happened.
36+
37+
```bash
38+
# Should be destroyed with success
39+
lando destroy -y
40+
lando poweroff
41+
```

examples/4.x/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this page requires sophisticated caching techniques

examples/6.x/.lando.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: lando-varnish-6
2+
services:
3+
defaults:
4+
type: varnish:6
5+
appserver:
6+
type: nginx
7+
8+
# This is important because it lets lando know to test against the plugin in this repo
9+
# DO NOT REMOVE THIS!
10+
plugins:
11+
"@lando/varnish": ./../../

examples/6.x/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Varnish Example
2+
===============
3+
4+
This example exists primarily to test the following documentation:
5+
6+
* [Varnish Service](https://docs.devwithlando.io/tutorials/varnish.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 varnish 6.0.9 by user specification
26+
lando ssh -s defaults -c "varnishd -V 2>&1 | grep varnish-6.0.9"
27+
28+
# Should backend from appserver by default
29+
lando ssh -s defaults -c "curl localhost | grep sophisticated"
30+
```
31+
32+
Destroy tests
33+
-------------
34+
35+
Run the following commands to trash this app like nothing ever happened.
36+
37+
```bash
38+
# Should be destroyed with success
39+
lando destroy -y
40+
lando poweroff
41+
```

examples/6.x/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this page requires sophisticated caching techniques

examples/custom/.lando.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: lando-varnish
2+
services:
3+
appserver:
4+
type: nginx
5+
custom:
6+
type: varnish:4
7+
backends:
8+
- appserver
9+
ssl: true
10+
overrides:
11+
environment:
12+
MEGAMAN: X
13+
config:
14+
vcl: config/custom.vcl
15+
customport:
16+
type: varnish:6
17+
backends:
18+
- backend2
19+
backend_port: 8000
20+
ssl: true
21+
backend2:
22+
type: python
23+
port: 8000
24+
command: python /app/python.py
25+
26+
# This is important because it lets lando know to test against the plugin in this repo
27+
# DO NOT REMOVE THIS!
28+
plugins:
29+
"@lando/varnish": ./../../

examples/custom/README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Varnish Example
2+
===============
3+
4+
This example exists primarily to test the following documentation:
5+
6+
* [Varnish Service](https://docs.devwithlando.io/tutorials/varnish.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 also serve over https if specified
26+
lando ssh -s custom_ssl -c "curl https://localhost | grep sophisticated"
27+
28+
# Shoule use a custom vcl file if specified
29+
lando ssh -s custom -c "cat /etc/varnish/lando.vcl | grep LANDOVARNISH"
30+
lando ssh -s custom -c "env | grep LANDO_CUSTOM_VCL | grep YOUBETCHA"
31+
lando ssh -s custom -c "curl -I localhost" | grep X-Lando-Varnish | grep capes
32+
33+
# Should inherit overrides from its generator
34+
lando ssh -s custom -c "env | grep MEGAMAN | grep X"
35+
lando ssh -s custom_ssl -c "env | grep MEGAMAN | grep X"
36+
37+
# Should use a custom backend port when specified
38+
lando ssh -s customport -c "curl http://localhost | grep SAW"
39+
40+
# Should use a custom backend port with SSL if specified
41+
lando ssh -s customport_ssl -c "curl https://localhost | grep SAW"
42+
```
43+
44+
Destroy tests
45+
-------------
46+
47+
Run the following commands to trash this app like nothing ever happened.
48+
49+
```bash
50+
# Should be destroyed with success
51+
lando destroy -y
52+
lando poweroff
53+
```

examples/custom/config/custom.vcl

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# LANDOVARNISH
2+
vcl 4.0;
3+
# For debugging, use the following and inspect the output of `varnishlog`:
4+
5+
sub vcl_recv {
6+
if (req.method == "GET" && req.url == "/.lando") {
7+
return (synth(204, "OK"));
8+
}
9+
}
10+
11+
sub vcl_backend_response {
12+
set beresp.http.X-Lando-Varnish = "capes";
13+
}
14+
15+
sub vcl_recv {
16+
if (req.http.CF-IPCountry) {
17+
set req.http.X-Country-Code = req.http.CF-IPCountry;
18+
} elseif (req.http.X-Real-IP) {
19+
set req.http.X-Country-Code = geoip.country_code(req.http.X-Real-IP);
20+
} else {
21+
set req.http.X-Country-Code = geoip.country_code(client.ip);
22+
}
23+
24+
if (req.http.X-Country-Code) {
25+
26+
27+
28+
if (req.http.X-Country-Code ~ "US|AS|BQ|IO|EC|SV|GU|HT|MH|FM|MP|PA|PW|PR|TL|TC|UM|VG|VI") {
29+
set req.http.X-Currency = "USD";
30+
} else if (req.http.X-Country-Code ~ "AD|AT|BE|CY|EE|FI|FR|GF|TF|DE|GP|GR|VA|IE|IT|LV|LT|LU|MT|MQ|YT|MC|ME|NL|PT|RE|BL|MF|PM|SM|SK|SI|ES|CE|CH|AX") {
31+
set req.http.X-Currency = "EUR";
32+
}
33+
}
34+
}

examples/custom/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this page requires sophisticated caching techniques

examples/custom/python.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
from http.server import HTTPServer, BaseHTTPRequestHandler
3+
4+
class myHandler(BaseHTTPRequestHandler):
5+
def do_GET(self):
6+
# Send response status code
7+
self.send_response(200)
8+
9+
# Send headers
10+
self.send_header('Content-type','text/html')
11+
self.end_headers()
12+
13+
# Send message back to client
14+
message = "SAWGUERROA"
15+
# Write content as utf-8 data
16+
self.wfile.write(bytes(message, "utf8"))
17+
return
18+
19+
# http
20+
httpd = HTTPServer(('0.0.0.0', 8000), myHandler)
21+
print('starting http server...')
22+
httpd.serve_forever()

lib/utils.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
// Modules
4+
const _ = require('lodash');
5+
6+
/*
7+
* Helper to get global deps
8+
* @TODO: this looks pretty testable? should services have libs?
9+
*/
10+
exports.cloneOverrides = (overrides = {}) => {
11+
const newOverrides = _.cloneDeep(overrides);
12+
if (_.has(newOverrides, 'image')) delete newOverrides.image;
13+
if (_.has(newOverrides, 'build')) delete newOverrides.build;
14+
return newOverrides;
15+
};

0 commit comments

Comments
 (0)