Skip to content

Commit

Permalink
added pre and post as syntactical sugar for l337 group override syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Jan 30, 2025
1 parent 37effb2 commit 27f3ef8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Added `pre-` and `post-` as syntactical sugar for `L337` service `group` override syntax
* Fixed bug causing `v4` services to be unnecessarily rebuilt on non-rebuildy commands eg `lando start`

## v3.24.0-beta.12 - [January 24, 2025](https://github.com/lando/core/releases/tag/v3.24.0-beta.12)
Expand Down
14 changes: 9 additions & 5 deletions components/l337-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,14 @@ class L337ServiceV4 extends EventEmitter {

// gets group overrides or returns false if there are none
getGroupOverrides(group) {
// break the group into parts
const parts = group.replace(`${this.getOverrideGroup(group)}`, '').split('-');
// there will always be a leading '' element so dump it
parts.shift();
// break the group into parts and remove empty strings
const parts = group.replace(`${this.getOverrideGroup(group)}`, '').split('-').filter(part => part && part !== '');

// translate pre|post syntax
if (['pre', 'post'].includes(parts[0])) {
parts[0] = parts[0] === 'pre' ? 'before' : 'after';
if (parts.length === 1) parts.push('1');
}

// if we have nothing then lets return false at this point
if (parts.length === 0) return false;
Expand Down Expand Up @@ -705,7 +709,7 @@ class L337ServiceV4 extends EventEmitter {
// this should ensure we end up with an ordered by closest match list
const candidates = Object.keys(this.#data.groups)
.sort((a, b) => b.length - a.length)
.filter(group => data.startsWith(group));
.filter(group => data.startsWith(group) || data.startsWith(`pre-${group}`) || data.startsWith(`post-${group}`));

// if there is a closest match that is not the group itself then its an override otherwise fise
return candidates.length > 0 && candidates[0] !== data ? candidates[0] : false;
Expand Down
13 changes: 12 additions & 1 deletion docs/services/l337.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,25 @@ While you _can_ use `COPY` and `ADD` instructions here we recommend you use [`co

#### Override syntax

The group override syntax is flexible as long as the parent group is first. For example the following overrides are equivalent:
You can also override _any_ group with a `before|after`, `user` and `offset` to gain more flexible on _when_ and _who_ runs a given step. The group override syntax is flexible as long as the parent group is first.

All the group overrides in the example below are equivalent. Any step using them will run as the `root` user at `+2` weight (eg after) to the weight provided by the `system` group.

```bash
system-2
system-2-after
system-root-after-2
system-2-after-root
system-root-2-after
post-system-2
```

Similarly, all of the below run as the `nginx` user but at `-2` weight (eg before) to the `system` group.

```bash
system-2-before-nginx
system-nginx-before-2
pre-system-2-nginx
```

That said, we like the `GROUP-OFFSET-DIRECTION-USER` format. ;)
Expand Down
9 changes: 9 additions & 0 deletions examples/l337/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ services:
# direct group usage
- instructions: RUN echo "${LANDO_IMAGE_USER}-${LANDO_IMAGE_GROUP}-$(whoami)" >> /tmp/groups
group: "val-jean"
- instructions: RUN echo "${LANDO_IMAGE_USER}-${LANDO_IMAGE_GROUP}-$(whoami)" >> /tmp/groups
group: "pre-val-jean"
- instructions: RUN echo "${LANDO_IMAGE_USER}-${LANDO_IMAGE_GROUP}-$(whoami)" >> /tmp/groups
group: "post-val-jean"
- instructions: RUN echo "${LANDO_IMAGE_USER}-${LANDO_IMAGE_GROUP}-$(whoami)" >> /tmp/groups
group: "pre-val-jean-4"
- instructions: RUN echo "${LANDO_IMAGE_USER}-${LANDO_IMAGE_GROUP}-$(whoami)" >> /tmp/groups
group: "post-val-jean-5"
- instructions: RUN echo "${LANDO_IMAGE_USER}-${LANDO_IMAGE_GROUP}-$(whoami)" >> /tmp/groups
group: "user"
- instructions: RUN echo "${LANDO_IMAGE_USER}-${LANDO_IMAGE_GROUP}-$(whoami)" >> /tmp/groups
Expand Down Expand Up @@ -397,6 +405,7 @@ services:
weight: 999
- instructions: RUN echo "first" >> /stuff
weight: 1

import:
api: 4
type: l337
Expand Down
35 changes: 23 additions & 12 deletions examples/l337/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,16 @@ lando groups | sed -n '11p' | grep root-default-1000-root-root
lando groups | sed -n '12p' | grep root-default-1000-root-root
lando groups | sed -n '13p' | grep nginx-user-10000-nginx-nginx
lando groups | sed -n '14p' | grep nginx-val-jean-24591-nginx-nginx
lando groups | sed -n '15p' | grep root-val-jean-24601-root-root
lando groups | sed -n '16p' | grep root-val-jean-24603-root-root
lando groups | sed -n '17p' | grep root-val-jean-24604-root-root
lando groups | sed -n '18p' | grep nginx-val-jean-24605-nginx-nginx
lando groups | sed -n '19p' | grep nginx-val-jean-24606-nginx-nginx
lando groups | sed -n '20p' | grep root-val-jean-24701-root-root
lando groups | sed -n '15p' | grep root-val-jean-24597-root-root
lando groups | sed -n '16p' | grep root-val-jean-24600-root-root
lando groups | sed -n '17p' | grep root-val-jean-24601-root-root
lando groups | sed -n '18p' | grep root-val-jean-24602-root-root
lando groups | sed -n '19p' | grep root-val-jean-24603-root-root
lando groups | sed -n '20p' | grep root-val-jean-24604-root-root
lando groups | sed -n '21p' | grep nginx-val-jean-24605-nginx-nginx
lando groups | sed -n '22p' | grep root-val-jean-24606-root-root
lando groups | sed -n '23p' | grep nginx-val-jean-24606-nginx-nginx
lando groups | sed -n '24p' | grep root-val-jean-24701-root-root

# should run build steps as the correct user
lando groups | sed -n '1p' | grep root-default--99999999-root-root
Expand All @@ -200,17 +204,24 @@ lando groups | sed -n '11p' | grep root-default-1000-root-root
lando groups | sed -n '12p' | grep root-default-1000-root-root
lando groups | sed -n '13p' | grep nginx-user-10000-nginx-nginx
lando groups | sed -n '14p' | grep nginx-val-jean-24591-nginx-nginx
lando groups | sed -n '15p' | grep root-val-jean-24601-root-root
lando groups | sed -n '16p' | grep root-val-jean-24603-root-root
lando groups | sed -n '17p' | grep root-val-jean-24604-root-root
lando groups | sed -n '18p' | grep nginx-val-jean-24605-nginx-nginx
lando groups | sed -n '19p' | grep nginx-val-jean-24606-nginx-nginx
lando groups | sed -n '20p' | grep root-val-jean-24701-root-root
lando groups | sed -n '15p' | grep root-val-jean-24597-root-root
lando groups | sed -n '16p' | grep root-val-jean-24600-root-root
lando groups | sed -n '17p' | grep root-val-jean-24601-root-root
lando groups | sed -n '18p' | grep root-val-jean-24602-root-root
lando groups | sed -n '19p' | grep root-val-jean-24603-root-root
lando groups | sed -n '20p' | grep root-val-jean-24604-root-root
lando groups | sed -n '21p' | grep nginx-val-jean-24605-nginx-nginx
lando groups | sed -n '22p' | grep root-val-jean-24606-root-root
lando groups | sed -n '23p' | grep nginx-val-jean-24606-nginx-nginx
lando groups | sed -n '24p' | grep root-val-jean-24701-root-root

# Should run steps in all allowed formats
lando env --service steps-1 | grep VIBES | grep RISING
lando env --service steps-1 | grep KIRK | grep wesley
lando env --service steps-1 | grep SPOCK | grep peck
lando env --service import | grep LANDO_STRINGY_IMPORT_INSTRUCTIONS_1 | grep 1
lando env --service import | grep LANDO_STRINGY_IMPORT_INSTRUCTIONS_2 | grep 1
lando env --service import | grep LANDO_STRINGY_IMPORT_INSTRUCTIONS_3 | grep 1

# Should run unknown groups as the default group
lando exec steps-1 -- cat /tmp/val-jean-group | grep default-1000-root
Expand Down

0 comments on commit 27f3ef8

Please sign in to comment.