Пример #1
0
func (aci *Aci) prepareBuildAci() (string, error) {
	logs.WithFields(aci.fields).Debug("Preparing builder")

	if err := os.MkdirAll(aci.target+pathBuilder+common.PathRootfs, 0777); err != nil {
		return "", errs.WithEF(err, aci.fields.WithField("path", aci.target+pathBuilder), "Failed to create builder aci path")
	}

	if err := ioutil.WriteFile(aci.target+pathBuilder+common.PathRootfs+"/.keep", []byte(""), 0644); err != nil {
		return "", errs.WithEF(err, aci.fields.WithField("file", aci.target+pathBuilder+common.PathRootfs+"/.keep"), "Failed to write keep file")
	}
	capa, err := types.NewLinuxCapabilitiesRetainSet("all")
	if err != nil {
		return "", errs.WithEF(err, aci.fields, "Failed to create all capability retain Set")
	}
	allIsolator, err := capa.AsIsolator()
	if err != nil {
		return "", errs.WithEF(err, aci.fields, "Failed to prepare all retain set isolator")
	}

	aci.manifest.Aci.App.Isolators = types.Isolators([]types.Isolator{*allIsolator})

	if err := common.WriteAciManifest(aci.manifest, aci.target+pathBuilder+common.PathManifest, common.PrefixBuilder+aci.manifest.NameAndVersion.Name(), BuildVersion); err != nil {
		return "", err
	}
	if err := aci.tarAci(aci.target + pathBuilder); err != nil {
		return "", err
	}

	logs.WithF(aci.fields.WithField("path", aci.target+pathBuilder+pathImageAci)).Info("Importing build to rkt")
	hash, err := Home.Rkt.FetchInsecure(aci.target + pathBuilder + pathImageAci)
	if err != nil {
		return "", errs.WithEF(err, aci.fields, "fetch of builder aci failed")
	}
	return hash, nil
}
Пример #2
0
func TestFindResources(t *testing.T) {
	tests := []struct {
		in types.Isolators

		wmem int64
		wcpu int64
	}{
		{
			types.Isolators{},

			defaultMem,
			0,
		},
		{
			types.Isolators([]types.Isolator{
				newIsolator(`
				{
					"name":     "resource/cpu",
					"value": {
						"limit": 100,
						"request": 100
						}
				}`),
			}),

			defaultMem,
			100,
		},
	}

	for i, tt := range tests {
		gmem, gcpu := findResources(tt.in)
		if gmem != tt.wmem {
			t.Errorf("#%d: got mem=%d, want %d", i, gmem, tt.wmem)
		}
		if gcpu != tt.wcpu {
			t.Errorf("#%d: got cpu=%d, want %d", i, gcpu, tt.wcpu)
		}
	}
}