-
Notifications
You must be signed in to change notification settings - Fork 10
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
[ENG-9500] Implement save-cache and restore-cache functions #289
base: main
Are you sure you want to change the base?
[ENG-9500] Implement save-cache and restore-cache functions #289
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #289 +/- ##
==========================================
+ Coverage 88.51% 91.43% +2.92%
==========================================
Files 23 23
Lines 1114 1085 -29
Branches 247 229 -18
==========================================
+ Hits 986 992 +6
+ Misses 128 93 -35 ☔ View full report in Codecov by Sentry. |
155ed7f
to
569cd61
Compare
4c39620
to
9685659
Compare
9685659
to
9eb71f1
Compare
packages/steps/src/cacheUtils.ts
Outdated
saveCache(ctx: any, cache?: Cache): Promise<boolean | void>; | ||
// TOOD: Change any to CacheableContext | ||
restoreCache(ctx: any, cache: Cache): Promise<boolean | void>; |
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.
When does it return boolean
and when does it return void
? Suggestion: make it either one or the other.
Why saveCache
doesn't require the cache
argument?
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.
void
is here only to keep compatibility with GCSCacheManager
in turtle (https://github.com/expo/turtle-v2/blob/9e6fd370c862869fec034d7e1be1074f7d3e3105/src/services/worker/src/CacheManager.ts#L18) and will be changed when changes to turtle land
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.
My suggestion to make development of this feature easier will be to do as follows:
- make all necessary changes in
eas-build
. They can break API. We shouldn't try to deployturtle-v2
with new cache changes (bumped dependencies), but without your adjusting changes (makingGCSCacheManager
conform to newrestoreCache
. - submit a pull request with upgraded dependencies and updated
turtle-v2
code.
This is the flow I used when developing generic artifacts:
- made a couple breaking changes to
eas-build
(Refactor uploading artifacts #306, ChangeuploadArtifacts
intouploadArtifact
#309, Add support for generic artifacts #307) - updated dependencies and adjusted
turtle-v2
in one PR (https://github.com/expo/turtle-v2/pull/1609).
This removes the complexity of trying to maintain two interfaces at the same time. What do you think, do you foresee any problems?
Suggestion also applies to other comments like #289 (comment).
packages/steps/src/cacheUtils.ts
Outdated
saveCache(ctx: any, cache?: Cache): Promise<boolean | void>; | ||
// TOOD: Change any to CacheableContext | ||
restoreCache(ctx: any, cache: Cache): Promise<boolean | void>; | ||
generateUrls?: boolean; |
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.
What does this do? Is this like a feature-enabling flag?
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.
Yes, it will tell new GCSCacheManager whether to use pregenerated upload/download urls or to generate new ones.
disabled: boolean; | ||
clear: boolean; |
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.
What do these do?
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.
Unresolving discussion. It remains unclear what does disabled
or clear
mean in this context.
@@ -0,0 +1,31 @@ | |||
import { bunyan } from '@expo/logger'; | |||
|
|||
export interface Cache { |
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.
Do we need to have two Cache
s, one here and another one in eas-build-job
?
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.
It is part of the transition process: in order to avoid circular dependencies Cache
should be defined in steps
, but to keep compatibility I kept it in both places. It will be consolidated after changes to turtle
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.
Is this still true after recent changes to Turtle? Why would we get a circular dependency if we used Cache
from eas-build-job
?
@@ -56,6 +59,9 @@ export class CustomBuildContext implements ExternalBuildContextProvider { | |||
this.runtimeApi = { | |||
uploadArtifacts: (...args) => buildCtx['uploadArtifacts'](...args), | |||
}; | |||
this.cacheManager = buildCtx.cacheManager; |
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.
We could consider rolling cacheManager
into runtimeApi
for simplicity. Like, how many functions may we put into runtimeApi
? I don't think the list will be too long.
6615c81
to
db0ebe4
Compare
b119c69
to
9800877
Compare
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.
Very cool, some questions and suggestions!
], | ||
outputProviders: [ | ||
BuildStepOutput.createProvider({ | ||
id: 'cache_key', |
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.
nit: I think key
should be sufficient, same for paths
.
Or, we could not add it because however users are providing us key
and paths
, they should be able to use the same technique anywhere else? This is not a strong opinion.
return; | ||
} | ||
|
||
const job = stepsCtx.global.staticContext.job as BuildJob; |
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.
If the function only makes sense for a BuildJob
let's define argument to this function like
export function createResolveBuildConfigBuildFunction( | |
ctx: CustomBuildContext<BuildJob> | |
): BuildFunction { |
BuildJob
and we don't need to cast.
However, I think the bigger thing to update here is that I think this doesn't take into consideration updates to https://github.com/expo/turtle-v2/pull/1715, e.g. that cache download URLs are to be requested dynamically from the launcher?
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.
However, I think the bigger thing to update here is that I think this doesn't take into consideration updates to https://github.com/expo/turtle-v2/pull/1715, e.g. that cache download URLs are to be requested dynamically from the launcher?
What makes you think so?
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.
- call to
restoreCache
depends onjob.cache
existence restoreCache
receivesjob.cache
I thought dynamic caches are completely separate from job.cache
.
packages/steps/build.sh
Outdated
@@ -11,6 +11,7 @@ if [[ "$npm_lifecycle_event" == "prepack" ]]; then | |||
echo 'Removing "dist_commonjs" and "dist_esm" folders...' | |||
rm -rf dist_commonjs dist_esm | |||
fi | |||
rm -rf dist_commonjs dist_esm |
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.
Why did you need to add this? Can we remove it or submit a different pull request explaining the reason for this addition?
disabled: boolean; | ||
clear: boolean; |
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.
Unresolving discussion. It remains unclear what does disabled
or clear
mean in this context.
9800877
to
a3dcacf
Compare
a3dcacf
to
fdb4f77
Compare
Why
ENG-9500
User should be able to save and restore files in their custom builds as steps.
This is part 1 of this feature. It provides two new custom build functions:
eas/save-cache
andeas/restore-cache
.Future PR will allow passing lists of files to
paths
parameter and define dynamic cache-key.How
This PR implements
eas/reastore-cache
andeas/save-cache
functions and lays foundations for future PRs.Cache
type is enhanced withdownloadUrls
attribute which will store mappings between cache keys and signed urls with cached files. Field will be populated bylauncher
.CacheManager
now accepts two parameters: build context (which is eitherBuildStepContext
orBuildContext<Job>
) andCache
. Implementation ofCacheManager
using dynamic cache urls will be provided in future PRs. Until this happens, for compatibility, build context is usingany
type.Test Plan
These changes are not meant to provide working functionality, but to provide foundation for new
GCSCacheManager
implementation.