~sircmpwn/builds.sr.ht

builds.sr.ht/worker/manifest.go -rw-r--r-- 1.2 KiB
73b24a38Simon Ser images/archlinux: skip compression for makepkg 8 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main

import (
	"io/ioutil"
	"os"
	"path"

	"gopkg.in/yaml.v2"
)

type Manifest struct {
	Arch         *string
	Artifacts    []string
	Environment  map[string]interface{}
	Image        string
	Packages     []string
	Repositories map[string]string
	Secrets      []string
	Shell        bool
	Sources      []string
	Tasks        []map[string]string
	Triggers     []map[string]interface{}
	OAuth        string
}

type ImageConfig struct {
	LoginCmd   string `yaml:"logincmd"`
	GitVariant string `yaml:"git_variant"`
	Homedir    string `yaml:"homedir"`
	Preamble   string `yaml:"preamble"`
}

func LoadImageConfig(image string) *ImageConfig {
	images, _ := config.Get("builds.sr.ht::worker", "images")
	iconf := &ImageConfig{
		LoginCmd:   "ssh",
		GitVariant: "git",
		Homedir:    "/home/build",
		Preamble:   `#!/usr/bin/env bash
. ~/.buildenv
set -xe

acurl() (
	set +x
	curl --oauth2-bearer "$OAUTH2_TOKEN" "$@"
)
`,
	}
	f, err := os.Open(path.Join(images, image, "config.yml"))
	if err != nil {
		return iconf
	}
	defer f.Close()
	b, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}
	err = yaml.Unmarshal(b, iconf)
	if err != nil {
		panic(err)
	}
	return iconf
}