~comcloudway/builds.sr.ht

3dd68aef13600861bef3c7c414d16c4829608f0f — Jakob Meier 9 months ago d910c23
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)
1 files changed, 16 insertions(+), 1 deletions(-)

M worker/tasks.go
M worker/tasks.go => worker/tasks.go +16 -1
@@ 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