Skip to content

Commit

Permalink
Get rid of render template and add nginx 1.25 support (#33)
Browse files Browse the repository at this point in the history
* Update pinPairs and add nginx 1.25 support.

* Get rid of render-template.

* Add tests for nginx 1.25.
  • Loading branch information
reynoldsalec authored Dec 5, 2023
1 parent 873762f commit 0b6d872
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-nginx-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- examples/1.22
- examples/1.23
- examples/1.24
- examples/1.25
- examples/custom

steps:
Expand Down
17 changes: 6 additions & 11 deletions builders/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ 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'],
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'],
pinPairs: {
'1.24': 'bitnami/nginx:1.24.0-debian-11-r1',
'1.23': 'bitnami/nginx:1.23.4-debian-11-r10',
'1.22': 'bitnami/nginx:1.22.1-debian-11-r64',
'1.25': 'bitnami/nginx:1.25.3-debian-11-r1',
'1.24': 'bitnami/nginx:1.24.0-debian-11-r153',
'1.23': 'bitnami/nginx:1.23.4-debian-11-r24',
'1.22': 'bitnami/nginx:1.22.1-debian-11-r66',
'1.21': 'bitnami/nginx:1.21.6-debian-11-r21',
'1.20': 'bitnami/nginx:1.20.2-debian-11-r9',
'1.19': 'bitnami/nginx:1.19.10-debian-10-r94',
Expand Down Expand Up @@ -42,7 +43,6 @@ module.exports = {
},
ssl: false,
webroot: '.',
renderTemplate: '1.0.5-5',
},
parent: '_webserver',
builder: (parent, config) => class LandoNginx extends parent {
Expand All @@ -64,11 +64,6 @@ module.exports = {
options.defaultFiles = _.merge({}, options.defaultFiles, {server: 'nginx.conf.tpl'});
}

// swap to older render template as needed
if (mv === '1.14' || mv === '1.15' || mv === '1.16') {
options.renderTemplate = '1.0.0-3';
}

// Get the config files final destination
// @TODO: we cp the files instead of directly mounting them to
// prevent unexpected edits to this files
Expand All @@ -78,7 +73,7 @@ module.exports = {
// Build the default stuff here
const nginx = {
image: `bitnami/nginx:${options.version}`,
command: `/launch.sh ${vhosts} ${server} ${params} ${options.renderTemplate}`,
command: `/launch.sh ${vhosts} ${server} ${params}`,
environment: {
NGINX_HTTP_PORT_NUMBER: '80',
NGINX_DAEMON_USER: 'root',
Expand Down
15 changes: 3 additions & 12 deletions config/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set -e
: ${VHOST:="$1"}
: ${SERVER:="$2"}
: ${PARAMS:="$3"}
: ${RENDER_TEMPLATE:="$4"}
: ${VHOST_SOURCE:="/tmp/vhosts.conf.lando"}
: ${SERVER_SOURCE:="/tmp/server.conf.lando"}
: ${PARAMS_SOURCE:="/tmp/fastcgi_params.lando"}
Expand Down Expand Up @@ -35,18 +34,10 @@ if [ -f "$PARAMS_SOURCE" ]; then
cp -f "$PARAMS_SOURCE" "$PARAMS"
fi

# Unpack components
if [ -f "/opt/bitnami/scripts/libcomponent.sh" ] && ! command -v render-template &> /dev/null; then
. /opt/bitnami/scripts/libcomponent.sh && component_unpack "render-template" "$RENDER_TEMPLATE"
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_info "Command render-template not found, using sed"
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
11 changes: 11 additions & 0 deletions examples/1.25/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: lando-nginx-125
services:
defaults:
type: nginx:1.25
build_as_root:
- apt-get update && apt-get install -y curl

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

This example exists primarily to test the following documentation:

* [nginx Service](https://docs.devwithlando.io/tutorials/nginx.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 1.25.x as the default version
lando ssh -s defaults -c "nginx -v 2>&1 | grep 1.25"

# Should serve from the app root by default
lando ssh -s defaults -c "curl http://localhost | grep ROOTDIR"

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

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
```
1 change: 1 addition & 0 deletions examples/1.25/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ROOTDIR

0 comments on commit 0b6d872

Please sign in to comment.