-
Notifications
You must be signed in to change notification settings - Fork 222
[build-tools] Install ffmpeg for argent screen recording when missing #4110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
szdziedzic
wants to merge
4
commits into
main
Choose a base branch
from
szdziedzic-claude/argent-eas-simulator-recordings-1b6e3b
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fc1303c
[build-tools] Install ffmpeg for argent screen recording when missing
szdziedzic fe0d28d
update CHANGELOG.md
szdziedzic c0c0e7f
[build-tools] Mock ensureFfmpegInstalledAsync in the orchestration test
szdziedzic 418595b
[build-tools] Install ffmpeg with apt on Linux workers too
szdziedzic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { SystemError } from '@expo/eas-build-job'; | ||
| import { bunyan } from '@expo/logger'; | ||
| import { BuildStepEnv, spawnAsync } from '@expo/steps'; | ||
| import { asyncResult } from '@expo/results'; | ||
| import { BuildRuntimePlatform, BuildStepEnv, spawnAsync } from '@expo/steps'; | ||
| import spawn from '@expo/turtle-spawn'; | ||
| import * as ngrok from '@ngrok/ngrok'; | ||
| import { graphql } from 'gql.tada'; | ||
|
|
@@ -179,6 +180,96 @@ async function sleepUntilAbortedAsync( | |
| } | ||
| } | ||
|
|
||
| // Argent encodes screen recordings by piping simulator frames into `ffmpeg`, | ||
| // which it resolves from PATH and then from these prefixes. Keep the list in | ||
| // sync with argent so we never reinstall a binary it can already find. | ||
| const FFMPEG_FALLBACK_PATHS = [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a reason to do it like this. I think our list should only check our expected places for ffmpeg and our expected list is just $PATH? Does argent really not adhere to $PATH? |
||
| '/opt/homebrew/bin/ffmpeg', | ||
| '/usr/local/bin/ffmpeg', | ||
| '/usr/bin/ffmpeg', | ||
| ]; | ||
|
|
||
| async function isFfmpegAvailableAsync(env: BuildStepEnv): Promise<boolean> { | ||
| if (FFMPEG_FALLBACK_PATHS.some(ffmpegPath => fs.existsSync(ffmpegPath))) { | ||
| return true; | ||
| } | ||
| return (await asyncResult(spawn('sh', ['-c', 'command -v ffmpeg'], { env }))).ok; | ||
| } | ||
|
|
||
| async function installFfmpegWithHomebrewAsync({ | ||
| env, | ||
| logger, | ||
| }: { | ||
| env: BuildStepEnv; | ||
| logger: bunyan; | ||
| }): Promise<void> { | ||
| await spawn('brew', ['install', 'ffmpeg'], { | ||
| env: { ...env, HOMEBREW_NO_AUTO_UPDATE: '1' }, | ||
| logger, | ||
| }); | ||
| } | ||
|
|
||
| async function installFfmpegWithAptAsync({ | ||
| env, | ||
| logger, | ||
| }: { | ||
| env: BuildStepEnv; | ||
| logger: bunyan; | ||
| }): Promise<void> { | ||
| const aptEnv = { ...env, DEBIAN_FRONTEND: 'noninteractive' }; | ||
| // The worker's package index can be older than the image it booted from, which | ||
| // makes the install 404 on a moved package. Refreshing first avoids that; a | ||
| // failed refresh is not fatal because the existing index may still resolve. | ||
| await asyncResult(spawn('sudo', ['apt-get', 'update'], { env: aptEnv, logger })); | ||
| await spawn('sudo', ['apt-get', 'install', '-y', 'ffmpeg'], { env: aptEnv, logger }); | ||
| } | ||
|
|
||
| /** | ||
| * Install ffmpeg when the runtime does not already provide it, so argent's | ||
| * `screen-recording-start` tool can encode a video. The worker images do not | ||
| * ship ffmpeg yet, so without this the tool fails with "`ffmpeg` was not found | ||
| * on PATH" — on macOS (iOS simulators) and Linux (Android emulators) alike. | ||
| * | ||
| * Best-effort by design: screen recording is one optional argent tool, so a | ||
| * failure here is logged and the session continues without it. Never rejects, | ||
| * which is what lets the caller run it in the background. | ||
| */ | ||
| export async function ensureFfmpegInstalledAsync({ | ||
| runtimePlatform, | ||
| env, | ||
| logger, | ||
| }: { | ||
| runtimePlatform: BuildRuntimePlatform; | ||
| env: BuildStepEnv; | ||
| logger: bunyan; | ||
| }): Promise<void> { | ||
| if (await isFfmpegAvailableAsync(env)) { | ||
| logger.info('ffmpeg is already installed.'); | ||
| return; | ||
| } | ||
|
|
||
| const isDarwin = runtimePlatform === BuildRuntimePlatform.DARWIN; | ||
| logger.info( | ||
| `ffmpeg is not installed, installing it with ${ | ||
| isDarwin ? 'Homebrew' : 'apt' | ||
| } for argent screen recording.` | ||
| ); | ||
| const installResult = await asyncResult( | ||
| isDarwin | ||
| ? installFfmpegWithHomebrewAsync({ env, logger }) | ||
| : installFfmpegWithAptAsync({ env, logger }) | ||
| ); | ||
| if (!installResult.ok) { | ||
| Sentry.capture('Could not install ffmpeg for argent screen recording', installResult.reason); | ||
| logger.warn( | ||
| { err: installResult.reason }, | ||
| 'Could not install ffmpeg. Argent screen recording will not work in this session.' | ||
| ); | ||
| return; | ||
| } | ||
| logger.info('Installed ffmpeg.'); | ||
| } | ||
|
|
||
| const TurnIceServersResponseSchema = z.object({ | ||
| data: z.object({ | ||
| iceServers: TurnIceServersSchema, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably good for now but I wish we had easier time:
Then we wouldn't mix so much in this one function and one log group…
Going to wait for hooks and custom fns to land and see if adding
parallel: truewould be so hard