Skip to content
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

Add meta configuration option to tell Hercules what binary cache to push to #589

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Hercules.API.Agent.Evaluate.ImmutableInput qualified as API.ImmutableInpu
import Hercules.API.DayOfWeek (DayOfWeek (..))
import Hercules.Agent.NixFile (HerculesCISchema, InputsSchema, OutputsSchema, getHerculesCI, homeExprRawValue, loadNixFile, parseExtraInputs)
import Hercules.Agent.NixFile qualified as NixFile
import Hercules.Agent.NixFile.HerculesCIArgs (CISystems (CISystems), HerculesCIMeta (HerculesCIMeta), fromGitSource)
import Hercules.Agent.NixFile.HerculesCIArgs (BinaryCaches (BinaryCaches), CISystems (CISystems), HerculesCIMeta (HerculesCIMeta), fromGitSource)
import Hercules.Agent.NixFile.HerculesCIArgs qualified
import Hercules.Agent.Worker.Env (HerculesState (..))
import Hercules.Agent.Worker.Error (ExceptionText (exceptionTextDerivationPath), exceptionTextMessage, exceptionTextTrace, renderException, throwBuildError)
Expand Down Expand Up @@ -292,7 +292,7 @@ runEval st@HerculesState {herculesStore = hStore, drvsCompleted = drvsCompl} eva
do
homeExpr <- getHomeExpr evalState eval
let hargs = fromGitSource (coerce $ Eval.gitSource eval) meta
meta = HerculesCIMeta {apiBaseUrl = Eval.apiBaseUrl eval, ciSystems = CISystems (Eval.ciSystems eval)}
meta = HerculesCIMeta {apiBaseUrl = Eval.apiBaseUrl eval, ciSystems = CISystems (Eval.ciSystems eval), pushToBinaryCaches = BinaryCaches (Eval.pushToBinaryCaches eval)}
liftIO (flip runReaderT evalState $ getHerculesCI homeExpr hargs) >>= \case
Nothing ->
-- legacy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,12 @@ produceEvaluationTaskEvents sendLogItems store task writeToBatch = UnliftIO.hand
Just (_, _, _, _, _, file_) -> file_

let uploadDrvs paths = do
caches <- activePushCaches
caches <-
case EvaluateTask.pushToBinaryCaches task of
Nothing -> activePushCaches
Just desiredPushCaches -> do
availablePushCaches <- activePushCaches
pure . M.keys $ desiredPushCaches `M.intersection` (M.fromList $ (,()) <$> availablePushCaches)
forM_ caches $ \cache -> do
withNamedContext "cache" cache $ logLocM DebugS "Pushing derivations"

Expand Down Expand Up @@ -650,6 +655,7 @@ runEvalProcess sendLogItems store projectDir file autoArguments nixPath emit upl
Eval.srcInput = ViaJSON <$> srcInput,
Eval.apiBaseUrl = apiBaseUrl,
Eval.ciSystems = EvaluateTask.ciSystems task,
Eval.pushToBinaryCaches = EvaluateTask.pushToBinaryCaches task,
Eval.selector = ViaJSON $ EvaluateTask.selector task,
Eval.isFlakeJob = EvaluateTask.isFlakeJob task,
Eval.allowInsecureBuiltinFetchers = Config.allowInsecureBuiltinFetchers cfg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import Protolude
-- | Documented in @docs/modules/ROOT/pages/evaluation.adoc@.
data HerculesCIMeta = HerculesCIMeta
{ apiBaseUrl :: Text,
ciSystems :: CISystems
ciSystems :: CISystems,
pushToBinaryCaches :: BinaryCaches
}
deriving (Generic, ToJSON)

Expand All @@ -34,6 +35,11 @@ newtype CISystems = CISystems (Maybe (Map Text ()))
deriving anyclass (ToJSON)
deriving (ToRawValue) via (ViaJSON CISystems)

newtype BinaryCaches = BinaryCaches (Maybe (Map Text ()))
deriving (Generic)
deriving anyclass (ToJSON)
deriving (ToRawValue) via (ViaJSON BinaryCaches)

fromGitSource :: GitSource -> HerculesCIMeta -> HerculesCIArgs
fromGitSource primary hci =
HerculesCIArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data Eval = Eval
selector :: ViaJSON EvaluateTask.Selector,
isFlakeJob :: Bool,
ciSystems :: Maybe (Map Text ()),
pushToBinaryCaches :: Maybe (Map Text ()),
allowInsecureBuiltinFetchers :: Bool,
allowedPaths :: [ByteString]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data EvaluateTask = EvaluateTask
logToken :: Text,
selector :: Selector,
ciSystems :: Maybe (Map Text ()),
pushToBinaryCaches :: Maybe (Map Text ()),
extraGitCredentials :: Maybe [Credential],
-- | Whether to use Nix's fetching mechanism for everything.
--
Expand Down