Skip to content

Commit

Permalink
#39: attempt to install render template in all nginx services (#41)
Browse files Browse the repository at this point in the history
* #39: attempt to install render template in all nginx services

* #39: added generic render template support, removed 1.14, set 1.25 as default

* #39: added generic render template support, removed 1.14, set 1.25 as default part 2

* #39: added generic render template support, removed 1.14, set 1.25 as default part 3
  • Loading branch information
pirog authored Dec 9, 2023
1 parent d3a2302 commit 9c495eb
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 52 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## v1.0.0 - [December 7, 2023](https://github.com/lando/ngin/releases/tag/v1.0.0)

* Changed default version to `1.25`
* Dialed fully for `lando update`
* Redadded `render-template` tooling as possible
* Removed support for `nginx:1.14`

## v0.11.0 - [December 5, 2023](https://github.com/lando/nginx/releases/tag/v0.11.0)

* Got rid of render-template tooling. [#33](https://github.com/lando/nginx/pull/33)
* Got rid of `render-template` tooling [#33](https://github.com/lando/nginx/pull/33)
* Added support for `nginx:1.25`.

## v0.10.0 - [November 15, 2023](https://github.com/lando/nginx/releases/tag/v0.10.0)
Expand Down
29 changes: 13 additions & 16 deletions builders/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const path = require('path');
module.exports = {
name: 'nginx',
config: {
version: '1.17',
supported: ['1.14', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22', '1.23', '1.24', '1.25'],
legacy: ['1.14'],
version: '1.25',
supported: ['1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22', '1.23', '1.24', '1.25'],
pinPairs: {
'1.25': 'bitnami/nginx:1.25.3-debian-11-r1',
'1.24': 'bitnami/nginx:1.24.0-debian-11-r153',
Expand All @@ -22,7 +21,6 @@ module.exports = {
'1.18': 'bitnami/nginx:1.18.0-debian-10-r363',
'1.17': 'bitnami/nginx:1.17.10-debian-10-r71',
'1.16': 'bitnami/nginx:1.16.1-debian-10-r106',
'1.14': 'bitnami/nginx:1.14.2-r125',
},
patchesSupported: true,
confSrc: path.resolve(__dirname, '..', 'config'),
Expand All @@ -41,28 +39,27 @@ module.exports = {
server: '/tmp/server.conf.lando',
vhosts: '/tmp/vhosts.conf.lando',
},
renderArch: 'amd64',
renderTemplate: '1.0.6',
ssl: false,
webroot: '.',
},
parent: '_webserver',
builder: (parent, config) => class LandoNginx extends parent {
constructor(id, options = {}) {
options = _.merge({}, config, options);

// compute the minor version
const mv = _(options.version.split('.')).thru(versions => [versions[0], versions[1]].join('.')).value();

// Are we strapped?
if (_.get(options, '_app._config.isArmed', false)) options.renderArch = 'arm64';
// Use different default for ssl
if (options.ssl) options.defaultFiles.vhosts = 'default-ssl.conf.tpl';

// If we are using the older 1.14 version we need different locations
if (mv === '1.14') {
options.finalFiles = _.merge({}, options.finalFiles, {
server: '/opt/bitnami/extra/nginx/templates/nginx.conf.tpl',
vhosts: '/opt/bitnami/extra/nginx/templates/default.conf.tpl',
});
options.defaultFiles = _.merge({}, options.defaultFiles, {server: 'nginx.conf.tpl'});
}
// attempt to install the render-template
require('../utils/add-build-step')(
[`/helpers/install-render-template.sh ${options.renderTemplate} ${options.renderArch}`],
options._app,
options.name,
'build_as_root_internal',
);

// Get the config files final destination
// @TODO: we cp the files instead of directly mounting them to
Expand Down
10 changes: 8 additions & 2 deletions config/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ if [ -f "$PARAMS_SOURCE" ]; then
fi

# Replace LANDO_WEBROOT in the vhost template
lando_info "Using sed to place correct webroot in vhost template"
sed 's@{{LANDO_WEBROOT}}@'"${LANDO_WEBROOT}"'@g' "$VHOST_SOURCE" > /opt/bitnami/nginx/conf/vhosts/lando.conf
# Render the template if render-template exists
if [ -x "$(command -v render-template)" ]; then
render-template "$VHOST_SOURCE" > /opt/bitnami/nginx/conf/vhosts/lando.conf
else
lando_warn "Command render-template not found, using sed fallback"
lando_warn "If your template replaced more than LANDO_WEBROOT this is probably going to be an issue"
sed 's@{{LANDO_WEBROOT}}@'"${LANDO_WEBROOT}"'@g' "$VHOST_SOURCE" > /opt/bitnami/nginx/conf/vhosts/lando.conf
fi

lando_info "Rendered template /tmp/vhosts.lando to /opt/bitnami/nginx/conf/vhosts/lando.conf"
lando_debug $(cat /opt/bitnami/nginx/conf/vhosts/lando.conf)
Expand Down
9 changes: 2 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@ services:
## Supported versions
* **[1.25](https://hub.docker.com/r/bitnami/nginx)** **(default)**
* [1.24](https://hub.docker.com/r/bitnami/nginx)
* [1.23](https://hub.docker.com/r/bitnami/nginx)
* [1.22](https://hub.docker.com/r/bitnami/nginx)
* [1.21](https://hub.docker.com/r/bitnami/nginx)
* [1.20](https://hub.docker.com/r/bitnami/nginx)
* [1.19](https://hub.docker.com/r/bitnami/nginx)
* [1.18](https://hub.docker.com/r/bitnami/nginx)
* **[1.17](https://hub.docker.com/r/bitnami/nginx)** **(default)**
* [1.17](https://hub.docker.com/r/bitnami/nginx)
* [1.16](https://hub.docker.com/r/bitnami/nginx)
* [custom](https://docs.lando.dev/config/services.html#advanced)
## Legacy versions
You can still run these versions with Lando but for all intents and purposes they should be considered deprecated (e.g. YMMV and do not expect a ton of support if you have an issue).
* [1.14](https://hub.docker.com/r/bitnami/nginx)
## Patch versions
::: warning Not officially supported!
Expand Down
2 changes: 1 addition & 1 deletion examples/1.16/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.17/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.18/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.19/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.20/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.21/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.22/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.23/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.24/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
2 changes: 1 addition & 1 deletion examples/1.25/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
12 changes: 7 additions & 5 deletions examples/custom/.lando.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
name: lando-nginx-custom
services:
custom:
type: nginx:1.17
type: nginx:1.25
ssl: true
webroot: www
build_as_root:
- apt-get update && apt-get install -y curl
config:
server: config/server2.conf
vhosts: config/custom.conf
params: config/params
custom_legacy:
type: nginx:1.14
custom_116:
type: nginx:1.16
ssl: true
webroot: www
config:
server: config/server.conf
server: config/server2.conf
vhosts: config/custom.conf
params: config/params

# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/nginx": ./../../
"@lando/nginx": ../..
20 changes: 10 additions & 10 deletions examples/custom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ Run the following commands to validate things are rolling as they should.

```bash
# Should serve from webroot if specified
lando ssh -s custom_legacy -c "curl http://localhost | grep WWWDIR"
lando ssh -s custom -c "curl http://localhost" | grep WWWDIR
lando ssh -s custom_116 -c "curl http://localhost | grep WWWDIR"

# Should serve from https when specified
lando ssh -s custom_legacy -c "curl https://localhost | grep WWWDIR"
lando ssh -s custom -c "curl https://localhost | grep WWWDIR"

# Should mount custom config to the correct locations
lando ssh -s custom_legacy -c "cat /opt/bitnami/extra/nginx/templates/nginx.conf.tpl | grep LANDOSERVER"
lando ssh -s custom_legacy -c "cat /opt/bitnami/nginx/conf/vhosts/lando.conf | grep LANDOVHOSTS"
lando ssh -s custom_legacy -c "cat /opt/bitnami/nginx/conf/fastcgi_params | grep LANDOPARAMS"
lando ssh -s custom -c "cat /opt/bitnami/nginx/conf/nginx.conf | grep LANDOSERVER"
lando ssh -s custom -c "cat /opt/bitnami/nginx/conf/vhosts/lando.conf | grep LANDOVHOSTS"
lando ssh -s custom -c "cat /opt/bitnami/nginx/conf/fastcgi_params | grep LANDOPARAMS"
lando ssh -s custom_116 -c "curl https://localhost | grep WWWDIR"

# Should mount custom config to the correct locations and render the correct vars
lando ssh -s custom -c "cat /opt/bitnami/nginx/conf/nginx.conf" | grep LANDOSERVER
lando ssh -s custom -c "cat /opt/bitnami/nginx/conf/vhosts/lando.conf" | grep server_name | grep test.landonginxcustom.lndo.site
lando ssh -s custom -c "cat /opt/bitnami/nginx/conf/fastcgi_params" | grep LANDOPARAMS
lando ssh -s custom_116 -c "cat /opt/bitnami/nginx/conf/nginx.conf" | grep LANDOSERVER
lando ssh -s custom_116 -c "cat /opt/bitnami/nginx/conf/vhosts/lando.conf" | grep server_name | grep test.landonginxcustom.lndo.site
lando ssh -s custom_116 -c "cat /opt/bitnami/nginx/conf/fastcgi_params" | grep LANDOPARAMS
```

Destroy tests
Expand Down
2 changes: 1 addition & 1 deletion examples/custom/config/custom.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
server {
listen 443 ssl;
listen 80;
server_name localhost;
server_name "test.{{LANDO_APP_COMMON_NAME}}.lndo.site";

ssl_certificate /certs/cert.crt;
ssl_certificate_key /certs/cert.key;
Expand Down
47 changes: 47 additions & 0 deletions scripts/install-render-template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

# allow this to run through without failing
# set -e

# args
version="${1:-"1.0.6"}"
# @TODO: swtich back to amd64?
arch="${2:-"arm64"}"

# if we have render-template then just exit
if [ "$(command -v render-template)" ]; then exit 0; fi

# computed
url="https://github.com/bitnami/render-template/releases/download/v${version}/render-template-linux-${arch}.tar.gz"
tmpdir="/tmp/render-template-${version}"

# prep
rm -rf "$tmpdir" && mkdir -p "$tmpdir"
mkdir -p /usr/local/bin

# there are different considerations around 1.0.0
if [ "$version" == "1.0.0" ] && [ "$arch" == "arm64" ]; then
curl -fsSL \
-o "${tmpdir}/render-template-linux-${arch}" \
"https://github.com/bitnami/render-template/releases/download/v1.0/render-template-arm64"

# amd situation
elif [ "$version" == "1.0.0" ] && [ "$arch" == "amd64" ]; then
curl -fsSL \
-o "${tmpdir}/render-template-linux-${arch}.zip" \
"https://github.com/bitnami/render-template/releases/download/v1.0/render-template.zip"
unzip "${tmpdir}/render-template-linux-${arch}.zip" -d "${tmpdir}"
mv "${tmpdir}/render-template" "${tmpdir}/render-template-linux-${arch}"

# everything else can go here though
else
curl -fsSL "$url" | tar -xz -C "$tmpdir"
fi

# mv & execute
mv "${tmpdir}/render-template-linux-${arch}" /usr/local/bin/render-template
chmod +x /usr/local/bin/render-template

# allows return fine
# this isnt great but is probably good enough to last us until the lando 4 config generator
exit 0
14 changes: 14 additions & 0 deletions utils/add-build-step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

// Modules
const _ = require('lodash');

/*
* Helper to get global deps
* @TODO: this looks pretty testable? should services have libs?
*/
module.exports = (steps, app, name, step = 'build_internal', front = false) => {
const current = _.get(app, `config.services.${name}.${step}`, []);
const add = (front) ? _.flatten([steps, current]) : _.flatten([current, steps]);
_.set(app, `config.services.${name}.${step}`, _.uniq(add));
};

0 comments on commit 9c495eb

Please sign in to comment.