Skip to content

Commit

Permalink
ssh: use the new container name format
Browse files Browse the repository at this point in the history
The supervisor is changing the container name format from

`<serviceName>_<imageId>_<releaseId>_<commit>` to
`<serviceName>_<commit>`. This updates the SSH command to work with both
formats.

Change-type: minor
Depends-on: balena-os/balena-supervisor#2136
  • Loading branch information
pipex committed Dec 6, 2023
1 parent 29ade0f commit 1485514
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/utils/device/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ export async function getContainerIdForService(
.filter((l) => l);

const { escapeRegExp } = await import('lodash');
const regex = new RegExp(`(?:^|\\/)${escapeRegExp(opts.service)}_\\d+_\\d+`);
const regex = new RegExp(
`(?:^|\\/)${escapeRegExp(
opts.service,
)}_(?:\\d+_)?(?:\\d+_)?(?:[a-f0-9]*)?$`,
);
// Old balenaOS container name pattern:
// main_1234567_2345678
// New balenaOS container name patterns:
// main_1234567_2345678_a000b111c222d333e444f555a666b777
// main_1_1_localrelease
const nameRegex = /(?:^|\/)([a-zA-Z0-9_-]+)_\d+_\d+(?:_.+)?$/;
// Newer balenaOS container names just use commit
// main_a000b111c222d333e444f555a666b777
// main_10ca12e1ea5e
const nameRegex =
/(?:^|\/)([a-zA-Z0-9_-]+?)_(?:\d+_)?(?:\d+_)?(?:[a-f0-9]*)?$/;

const serviceNames: string[] = [];
const containerNames: string[] = [];
Expand Down Expand Up @@ -116,7 +124,9 @@ export async function getContainerIdForService(
throw new ExpectedError(
`Could not find a container matching service name "${s}" on device "${d}".${
serviceNames.length > 0
? `\nAvailable services:\n\t${serviceNames.join('\n\t')}`
? `\nAvailable services:\n\t${serviceNames
.map((n) => `'${n}'`)
.join('\n\t')}`
: ''
}`,
);
Expand Down

0 comments on commit 1485514

Please sign in to comment.