Skip to content

Commit

Permalink
rework to use lando 3 service instead of nginx plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Jan 17, 2025
1 parent 65730c5 commit b1be697
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 114 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-varnish-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- examples/4.x
- examples/6.x
- examples/custom
- examples/defaults
lando-version:
- 3-edge
os:
Expand Down
15 changes: 0 additions & 15 deletions builders/varnish-nginx.js

This file was deleted.

49 changes: 18 additions & 31 deletions builders/varnish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@
const path = require('path');
const _ = require('lodash');

// Helper to get varnsh ssl nginx
const varnishSsl = options => {
return {
command: `/launch.sh /opt/bitnami/nginx/conf/lando.conf`,
image: 'bitnami/nginx:1.27.3-debian-12-r5',
depends_on: [options.name],
environment: {
NGINX_DAEMON_USER: 'root',
NGINX_DAEMON_GROUP: 'root',
NGINX_HTTP_PORT_NUMBER: '80',
NGINX_HTTPS_PORT_NUMBER: '443',
LANDO_VARNISH_ALIAS: `${options.name}_varnish`,
LANDO_VARNISH_UPSTREAM: `${options.name}.${options._app.project}.internal`,
LANDO_NEEDS_EXEC: 'DOEEET',
},
user: 'root',
volumes: [
`${options.confDest}/launch.sh:/launch.sh`,
`${options.confDest}/${options.defaultFiles.ssl}:/opt/bitnami/nginx/conf/lando.conf`,
],
};
};

// Builder
module.exports = {
name: 'varnish',
Expand Down Expand Up @@ -94,29 +71,39 @@ module.exports = {
// Set the opts for this custom swill
const sslOpts = _.assign(_.cloneDeep(options), {
name: `${options.name}_ssl`,
type: 'varnish-nginx',
version: 'custom',
config: {
server: `${options.confDest}/${options.defaultFiles.ssl}`,
type: 'lando',
api: '3',
services: {
image: 'nginx:1.27.3',
command: '/docker-entrypoint.sh nginx -g "daemon off;"',
depends_on: [options.name],
environment: {
LANDO_VARNISH_ALIAS: `${options.name}_varnish`,
LANDO_VARNISH_UPSTREAM: [options._app.project, options.name, '1'].join(separator),
},
ports: ['443'],
volumes: [
`${options.confDest}/${options.defaultFiles.ssl}:/etc/nginx/templates/default.conf.template`,
],
},
info: {
backend: options.name,
managed: true,
},
meUser: 'www-data',
overrides: require('../utils/clone-overrides')(options.overrides),
ports: ['443'],
ssl: true,
sslExpose: true,
});

// Set another lando service we can pass down the stream
const LandoCompose = factory.get('_lando');
const nginx = {services: _.set({}, sslOpts.name, varnishSsl(options))};
const data = new LandoCompose(sslOpts.name, sslOpts, nginx);
const Lando3Service = factory.get('lando', 3);
const data = new Lando3Service(sslOpts.name, sslOpts);

// This is a trick to basically replicate what happens upstream
options._app.add(data);
options._app.info.push(data.info);

// Indicate the relationship on the primary service
options.info.ssl_served_by = sslOpts.name;
}
Expand Down
31 changes: 0 additions & 31 deletions config/launch.sh

This file was deleted.

3 changes: 1 addition & 2 deletions config/ssl-termination.conf.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
upstream varnish {
server {{LANDO_VARNISH_UPSTREAM}};
server ${LANDO_VARNISH_UPSTREAM};
}

server {
listen *:443 ssl;
server_name localhost;
ssl on;
ssl_certificate /certs/cert.crt;
ssl_certificate_key /certs/cert.key;
Expand Down
4 changes: 2 additions & 2 deletions examples/4.x/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +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/nginx": ./../../node_modules/@lando/nginx
"@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 @@ -20,10 +20,10 @@ Run the following commands to validate things are rolling as they should.

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

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

## Destroy tests
Expand Down
4 changes: 2 additions & 2 deletions examples/6.x/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +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/nginx": ./../../node_modules/@lando/nginx
"@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 @@ -20,10 +20,10 @@ Run the following commands to validate things are rolling as they should.

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

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

## Destroy tests
Expand Down
29 changes: 16 additions & 13 deletions examples/custom/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ services:
MEGAMAN: X
config:
vcl: config/custom.vcl
# customport:
# type: varnish:6
# backends:
# - backend2
# backend_port: 8000
# ssl: true
customport:
type: varnish:6
backend: backend2
backend_port: 8000
ssl: true
appserver:
type: nginx
# backend2:
# type: python
# port: 8000
# command: python /app/python.py
backend2:
type: python
port: 8000
command: python /app/python.py
curl:
api: 4
image: curlimages/curl:8.10.1
command: sleep infinity

# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/varnish": ./../../
"@lando/python": ./../../node_modules/@lando/python
"@lando/nginx": ./../../node_modules/@lando/nginx
"@lando/varnish": ../..
"@lando/nginx": ../../node_modules/@lando/nginx
"@lando/python": ../../node_modules/@lando/python
19 changes: 10 additions & 9 deletions examples/custom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This example exists primarily to test the following documentation:

* [Varnish Service](https://docs.devwithlando.io/tutorials/varnish.html)

# #Start up tests
## Start up tests

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

Expand All @@ -20,22 +20,23 @@ Run the following commands to validate things are rolling as they should.

```bash
# Should also serve over https if specified
lando ssh -s custom_ssl -c "curl https://localhost | grep sophisticated"
lando exec curl -- curl https://custom_ssl | grep sophisticated
lando exec curl -- curl https://customport_ssl | grep SAWGUERROA

# Shoule use a custom vcl file if specified
lando ssh -s custom -c "cat /etc/varnish/lando.vcl | grep LANDOVARNISH"
lando ssh -s custom -c "env | grep LANDO_CUSTOM_VCL | grep YOUBETCHA"
lando ssh -s custom -c "curl -I localhost" | grep X-Lando-Varnish | grep capes
lando exec custom -- cat /etc/varnish/lando.vcl | grep LANDOVARNISH
lando exec custom -- env | grep LANDO_CUSTOM_VCL | grep YOUBETCHA
lando exec custom -- curl -I localhost | grep X-Lando-Varnish | grep capes

# Should inherit overrides from its generator
lando ssh -s custom -c "env | grep MEGAMAN | grep X"
lando ssh -s custom_ssl -c "env | grep MEGAMAN | grep X"
lando exec custom -- env | grep MEGAMAN | grep X
lando exec custom_ssl -- env | grep MEGAMAN | grep X

# Should use a custom backend port when specified
lando ssh -s customport -c "curl http://localhost | grep SAW"
lando exec customport -- curl http://localhost | grep SAW

# Should use a custom backend port with SSL if specified
lando ssh -s customport_ssl -c "curl https://localhost | grep SAW"
lando exec customport_ssl -- curl https://localhost | grep SAW
```

## Destroy tests
Expand Down
2 changes: 1 addition & 1 deletion examples/defaults/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ services:
# DO NOT REMOVE THIS!
plugins:
"@lando/varnish": ./../../
"@lando/nginx": ./../../node_modules/@lando/nginx
"@lando/nginx": ../../node_modules/@lando/nginx
4 changes: 2 additions & 2 deletions examples/defaults/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Run the following commands to validate things are rolling as they should.

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

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

## Destroy tests
Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"test": "npm run lint && npm run test:unit"
},
"dependencies": {
"@lando/nginx": "^1.4.4",
"lodash": "^4.17.21"
},
"devDependencies": {
"@babel/eslint-parser": "^7.16.0",
"@lando/leia": "^1.0.0-beta.4",
"@lando/nginx": "^1.4.4",
"@lando/python": "^0.8.0",
"@lando/vitepress-theme-default-plus": "^1.1.0-beta.24",
"chai": "^4.3.4",
Expand Down

0 comments on commit b1be697

Please sign in to comment.