-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- CTA: add state prop to `/tunnels` API endpoint. checks that all compose services have been started by docker, and that all potential tunnels for these services have been started by the CTA. - CLI: check new prop in `up` and `urls` commands. can be disabled with the `--no-wait` flag Compatible with compose services which have no ports, e.g, one-off services such as DB init
- Loading branch information
1 parent
3f5b31d
commit 8074b71
Showing
14 changed files
with
143 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,4 +123,4 @@ | |
"preview" | ||
], | ||
"types": "dist/index.d.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { inspect } from 'util' | ||
import { ComposeTunnelAgentState } from '@preevy/common' | ||
import { RunningService } from './docker/index.js' | ||
|
||
const findPendingComposeServiceTunnels = ({ | ||
composeProject, | ||
composeModel, | ||
runningServices, | ||
}: { | ||
composeProject: string | ||
composeModel: { services: Record<string, unknown> } | ||
runningServices: Pick<RunningService, 'name' | 'project'>[] | ||
}) => { | ||
const composeServiceNames = Object.keys(composeModel.services) | ||
|
||
const runningServiceNames = new Set( | ||
runningServices | ||
.filter(({ project }) => project === composeProject) | ||
.map(({ name }) => name) | ||
) | ||
|
||
return composeServiceNames.filter(service => !runningServiceNames.has(service)) | ||
} | ||
|
||
export const tunnelsStateCalculator = ({ | ||
composeProject, | ||
composeModelReader, | ||
}: { | ||
composeProject?: string | ||
composeModelReader: () => Promise<{ services: Record<string, unknown> }> | ||
}) => async ( | ||
runningServices: Pick<RunningService, 'name' | 'project'>[] | ||
): Promise<ComposeTunnelAgentState> => { | ||
if (!composeProject) { | ||
return { state: 'unknown', reason: 'COMPOSE_PROJECT not set' } | ||
} | ||
|
||
let composeModel: { services: Record<string, unknown> } | ||
try { | ||
composeModel = await composeModelReader() | ||
} catch (e) { | ||
return { state: 'unknown', reason: `Could not read compose file: ${inspect(e)}` } | ||
} | ||
|
||
const pendingServices = findPendingComposeServiceTunnels({ composeProject, composeModel, runningServices }) | ||
if (pendingServices.length) { | ||
return { state: 'pending', pendingServices } | ||
} | ||
|
||
return { state: 'stable' } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters