runservice: add CacheGroup field to runconfig

The cache group fields defines under which cache group the run cache data will
belong. This is needed/useful for some next changes:

* Make cache correctly work for user direct runs. Since the user direct runs all
belong to the same run group (the user id) all the use direct runs will share the
same caches. To distinguish between the different caches we need to use something
in addition to the user id (the local repo uuid generated by the direct run
start command)
* Share the cache between multiple projects
This commit is contained in:
Simone Gotti 2019-07-03 15:16:37 +02:00
parent 504f538c6e
commit 87a472aaaf
4 changed files with 13 additions and 1 deletions

View File

@ -135,6 +135,7 @@ type RunCreateRequest struct {
Group string
SetupErrors []string
StaticEnvironment map[string]string
CacheGroup string
// existing run fields
RunID string
@ -210,6 +211,7 @@ func (h *ActionHandler) newRun(ctx context.Context, req *RunCreateRequest) (*typ
StaticEnvironment: req.StaticEnvironment,
Environment: req.Environment,
Annotations: req.Annotations,
CacheGroup: req.CacheGroup,
}
run := genRun(rc)

View File

@ -515,6 +515,7 @@ type RunCreateRequest struct {
Group string `json:"group"`
SetupErrors []string `json:"setup_errors"`
StaticEnvironment map[string]string `json:"static_environment"`
CacheGroup string `json:"cache_group"`
// existing run fields
RunID string `json:"run_id"`
@ -556,6 +557,7 @@ func (h *RunCreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Group: req.Group,
SetupErrors: req.SetupErrors,
StaticEnvironment: req.StaticEnvironment,
CacheGroup: req.CacheGroup,
RunID: req.RunID,
FromStart: req.FromStart,

View File

@ -335,6 +335,11 @@ func (s *Runservice) genExecutorTask(ctx context.Context, r *types.Run, rt *type
// run config Environment variables ovverride every other environment variable
mergeEnv(environment, rc.Environment)
cachePrefix := store.OSTRootGroup(r.Group)
if rc.CacheGroup != "" {
cachePrefix = rc.CacheGroup
}
et := &types.ExecutorTask{
// The executorTask ID must be the same as the runTask ID so we can detect if
// there's already an executorTask scheduled for that run task and we can get
@ -349,7 +354,7 @@ func (s *Runservice) genExecutorTask(ctx context.Context, r *types.Run, rt *type
Shell: rct.Shell,
User: rct.User,
Steps: rct.Steps,
CachePrefix: store.OSTRootGroup(r.Group),
CachePrefix: cachePrefix,
Status: types.ExecutorTaskStatus{
Phase: types.ExecutorTaskPhaseNotStarted,
Steps: make([]*types.ExecutorTaskStepStatus, len(rct.Steps)),

View File

@ -306,6 +306,9 @@ type RunConfig struct {
Environment map[string]string `json:"environment,omitempty"`
Tasks map[string]*RunConfigTask `json:"tasks,omitempty"`
// CacheGroup is the cache group where the run caches belongs
CacheGroup string `json:"cache_group,omitempty"`
}
func (rc *RunConfig) DeepCopy() *RunConfig {