From 3dd68aef13600861bef3c7c414d16c4829608f0f Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 27 Dec 2023 21:06:04 +0100 Subject: [PATCH] Allow the maximum artifact size to be configured Falls back to 1GB if the key isn't set in the config. This assumes that the value is set as an integer representing how many gigabytes are allowed. e.g. 5 for 5GB or 1 for 1GB (default) --- worker/tasks.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/worker/tasks.go b/worker/tasks.go index 31c3e2f..2e3b21f 100644 --- a/worker/tasks.go +++ b/worker/tasks.go @@ -688,6 +688,21 @@ func (ctx *JobContext) UploadArtifacts() error { if _, err := rand.Read(random); err != nil { return err } + + var ( + maxSizeGB int64 + sizeGB string + ) + // assumes the artifact size is specified as an int + // e.g. 2 for 2GB and 1 for 1GB + if sizeGB, ok = config.Get("builds.sr.ht::worker", "max-artifact-size"); !ok { + // default to old hardcoded value if the key wasn't found in the config file + artifactCount = "1" + } + if maxSizeGB, err = strconv.ParseInt(sizeGB, 10, 64); err != nil { + return errors.New("The maximum build-artifact size could not be read") + } + for _, src := range ctx.Manifest.Artifacts { ctx.Log.Printf("Uploading %s", src) name := path.Join(prefix, "~"+ctx.Job.Username, @@ -702,7 +717,7 @@ func (ctx *JobContext) UploadArtifacts() error { } return err } - if size > 1024*1024*1024 { // 1 GiB + if size > 1024*1024*1024*maxSizeGB { // 1 GiB * maximum size (in GB) err = errors.New("Artifact exceeds maximum file size") ctx.Log.Printf("%v", err) return err -- 2.38.5