Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ jobs:
include:
- os: windows-latest
# The Compose variants need Linux containers: not run, not "passed".
skip: --skip lifecycle_with_compose --skip a_lane_has_its_own_containers --skip an_announced_port_moves_inside_a_lanes_container
skip: --skip lifecycle_with_compose --skip a_lane_has_its_own_containers --skip an_announced_port_moves_inside_a_lanes_container --skip a_profile_leaves_out_containers
- os: ubuntu-latest
skip: ''
# No Docker on the macOS runners (ADR-0054).
- os: macos-14
skip: --skip lifecycle_with_compose --skip a_lane_has_its_own_containers --skip an_announced_port_moves_inside_a_lanes_container
skip: --skip lifecycle_with_compose --skip a_lane_has_its_own_containers --skip an_announced_port_moves_inside_a_lanes_container --skip a_profile_leaves_out_containers
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ and listed with their assets on the

## [Unreleased]

### Added

- **A profile can leave out containers, whole Compose groups and services**
(ADR-0058, #244). `[profiles.<name>] skip = ["compose.search",
"compose.app.scanner", "indexer"]` makes a light profile for daily work:
what it skips does not start with the tree, a skipped container an earlier
start left running is stopped, and each still starts on demand (`devstack
start compose.app.scanner`). A service that starts with the profile and
uses a skipped container's address is an error in the profile's check. A
lane on a node does not create what its profile skips. A file with `skip`
wants `requires = "0.21.0"`.

## [0.20.0] - 2026-10-23

macOS as a developer platform in preview, installed with Homebrew on macOS
Expand Down
12 changes: 12 additions & 0 deletions crates/devstack-compose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,18 @@ impl Docker {
self.run_group(g, &a, budget::STOP).map(|_| ())
}

/// Stop the group's selected services (`g.services`) where they run;
/// none selected: nothing (Compose would stop every one).
pub fn stop_selected(&self, g: &Group) -> Result<()> {
if g.services.is_empty() {
return Ok(());
}
let mut a = g.base_args();
a.extend(["stop".into(), "--timeout".into(), "10".into()]);
a.extend(g.services.iter().map(OsString::from));
self.run_group(g, &a, budget::STOP).map(|_| ())
}

/// Stop a container by its name (`docker stop`), whether or not the
/// loaded Compose model knows its service.
pub fn stop_container(&self, dir: &Path, name: &str) -> Result<()> {
Expand Down
4 changes: 4 additions & 0 deletions crates/devstack-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub const REVIEWED_SINCE: &str = "0.20.0";
/// (ADR-0057): a file that sets it wants `requires` at least this.
pub const ANNOUNCED_SINCE: &str = "0.20.0";

/// The first devstack that knows `[profiles.<name>] skip` (ADR-0058): a
/// file that sets it wants `requires` at least this.
pub const SKIP_SINCE: &str = "0.21.0";

/// `"1.2.3"`, `"v1.2"`, `"1"` as numbers; `None` when malformed. A
/// pre-release or build suffix (`1.2.3-rc1`, `1.2.3+abc`) is ignored here;
/// [`version_order`] takes it into account.
Expand Down
82 changes: 81 additions & 1 deletion crates/devstack-config/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use schemars::JsonSchema;
use serde::Deserialize;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use std::path::PathBuf;
use std::time::Duration;

Expand Down Expand Up @@ -96,6 +96,11 @@ pub struct Profile {
/// The services that start, instead of each service's own `autostart`.
#[serde(default)]
pub autostart: Option<Vec<String>>,
/// What does not start with this profile (ADR-0058): a container
/// (`compose.<group>.<service>`), every container of a group
/// (`compose.<group>`), or a service. Still started on demand.
#[serde(default)]
pub skip: Vec<String>,
/// How single services run with this profile.
#[serde(default)]
pub services: BTreeMap<String, ServiceProfile>,
Expand Down Expand Up @@ -142,9 +147,48 @@ pub struct Active {
pub data: DataMode,
pub env: BTreeMap<String, String>,
pub command: Option<String>,
/// The containers it leaves out, `(group, service)`, a skipped group's
/// every one (ADR-0058).
pub skip: BTreeSet<(String, String)>,
}

impl Stack {
/// The tree's start leaves container `service` of `group` out: the
/// profile it runs with skips it (ADR-0058).
pub fn skips(&self, group: &str, service: &str) -> bool {
self.profile
.as_ref()
.is_some_and(|p| p.skip.contains(&(group.to_string(), service.to_string())))
}

/// The containers profile `name` leaves out, `(group, service)`: what
/// [`Active::skip`] holds once it is applied. Entries that name nothing
/// are left out of it ([`Self::with_profile`] reports them).
pub fn skipped_containers(&self, name: &str) -> BTreeSet<(String, String)> {
let mut out = BTreeSet::new();
let Some(p) = self.profiles.get(name) else {
return out;
};
for e in &p.skip {
let Some(rest) = e.strip_prefix("compose.") else {
continue;
};
let (group, one) = match rest.split_once('.') {
Some((g, s)) => (g, Some(s)),
None => (rest, None),
};
let Some(g) = self.compose.get(group) else {
continue;
};
for s in &g.services {
if one.is_none_or(|o| o == s) {
out.insert((group.to_string(), s.clone()));
}
}
}
out
}

/// The stack as profile `name` runs it (ADR-0041), checked like a stack
/// file; the issues name the profile's keys.
/// What a lane needs at least with `profile` (ADR-0049 point 5):
Expand Down Expand Up @@ -270,6 +314,41 @@ impl Stack {
svc.autostart = list.contains(n);
}
}
for (i, e) in p.skip.iter().enumerate() {
let at = format!("profiles.{name}.skip[{i}]");
if let Some(rest) = e.strip_prefix("compose.") {
let (group, one) = match rest.split_once('.') {
Some((g, s)) => (g, Some(s)),
None => (rest, None),
};
match (self.compose.get(group), one) {
(None, _) => issues.push(issue(at, format!("no compose group `{group}`"))),
(Some(g), Some(one)) if !g.services.iter().any(|s| s == one) => {
issues.push(issue(
at,
format!("`{one}` is not started by compose group `{group}` (not in its `services`)"),
))
}
_ => {}
}
continue;
}
match s.services.get_mut(e) {
None => issues.push(issue(
at,
format!(
"no service `{e}` in `[services]` (a container is `compose.<group>.<service>`, a group `compose.<group>`)"
),
)),
Some(_) if p.autostart.as_ref().is_some_and(|l| l.contains(e)) => {
issues.push(issue(
at,
format!("`{e}` is in the profile's `autostart` too: it either starts or not"),
))
}
Some(svc) => svc.autostart = false,
}
}
if let Some(c) = &p.command
&& !s.commands.contains_key(c)
{
Expand All @@ -287,6 +366,7 @@ impl Stack {
data: p.data.unwrap_or_default(),
env: p.env.clone(),
command: p.command.clone(),
skip: self.skipped_containers(name),
});
Ok(s)
}
Expand Down
87 changes: 87 additions & 0 deletions crates/devstack-config/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,70 @@ impl Check<'_> {
}
}

/// What a service that starts with the profile needs of a container the
/// profile leaves out (ADR-0058 point 4): an address in its `run`, `env`,
/// worker switches or `ensure_dirs`, or a host it rewrites. Its start would
/// fail on it. `after` is not: the service starts without waiting.
fn skipped_needs(c: &mut Check, stack: &Stack) {
let Some(skip) = stack.profile.as_ref().map(|p| &p.skip) else {
return;
};
if skip.is_empty() {
return;
}
let skipped = |g: &str, s: &str| skip.contains(&(g.to_string(), s.to_string()));
for (s, svc) in stack.services.iter().filter(|(_, svc)| svc.autostart) {
let p = format!("services.{s}");
let why = |g: &str, svc: &str| {
format!(
"the profile leaves `compose.{g}.{svc}` out, so it has no address here (skip `{s}` too, or keep the container)"
)
};
let mut texts: Vec<(String, &str)> = vec![(format!("{p}.run"), svc.run.as_str())];
texts.extend(
svc.env
.iter()
.map(|(k, v)| (format!("{p}.env.{k}"), v.as_str())),
);
if let Some(w) = &svc.workers {
texts.extend(
w.env
.iter()
.map(|(k, v)| (format!("{p}.workers.env.{k}"), v.as_str())),
);
}
texts.extend(
svc.ensure_dirs
.iter()
.enumerate()
.map(|(i, d)| (format!("{p}.ensure_dirs[{i}]"), d.as_str())),
);
for (at, t) in texts {
let Ok(segs) = interpolate::parse(t) else {
continue; // reported where the text is checked
};
for ph in interpolate::placeholders(&segs) {
if let Placeholder::ComposePort { group, service, .. } = ph
&& skipped(group, service)
{
c.err(&at, format!("`{ph}`: {}", why(group, service)));
}
}
}
if let Some(r) = &svc.compose {
for (i, h) in svc.rewrite_hosts.iter().enumerate() {
let (group, service) = h.split_once('.').unwrap_or((r.group.as_str(), h.as_str()));
if skipped(group, service) {
c.err(
format!("{p}.rewrite_hosts[{i}]"),
format!("`{h}`: {}", why(group, service)),
);
}
}
}
}
}

pub fn validate(stack: &Stack) -> Vec<Issue> {
let mut c = Check {
stack,
Expand Down Expand Up @@ -802,6 +866,7 @@ pub fn validate(stack: &Stack) -> Vec<Issue> {
format!("`after` forms a cycle: {}", cycle.join(" -> ")),
);
}
skipped_needs(&mut c, stack);

// ---------------------------------------------------------------- commands
for (n, cmd) in &stack.commands {
Expand Down Expand Up @@ -971,6 +1036,28 @@ pub fn warnings(stack: &Stack) -> Vec<Issue> {
});
}
}
let skip = crate::version_order(crate::SKIP_SINCE);
if stack
.stack
.requires
.as_deref()
.is_none_or(|r| crate::version_order(r) < skip)
{
for name in stack
.profiles
.iter()
.filter(|(_, p)| !p.skip.is_empty())
.map(|(n, _)| n)
{
out.push(Issue {
path: format!("profiles.{name}.skip"),
message: format!(
"a devstack before {v} does not know this key and fails on it with \"unknown field\": `requires = \"{v}\"` makes it ask to be updated instead",
v = crate::SKIP_SINCE
),
});
}
}
if step == 0 {
return out;
}
Expand Down
Loading
Loading