Skip to content

Commit 85f59fb

Browse files
committed
replace podman for prometheus
1 parent 6b630b3 commit 85f59fb

File tree

4 files changed

+537
-62
lines changed

4 files changed

+537
-62
lines changed

core/oci.go

+22-14
Original file line numberDiff line numberDiff line change
@@ -17,76 +17,84 @@ import (
1717
"errors"
1818
"os"
1919
"path/filepath"
20+
21+
"github.com/vanilla-os/prometheus"
2022
)
2123

2224
// GenerateRootfs generates a rootfs from a image recipe file
2325
func OciExportRootFs(buildImageName string, imageRecipe *ImageRecipe, transDir string, dest string) error {
2426
PrintVerbose("Podman.GenerateRootfs: running...")
2527

28+
pt, err := prometheus.NewPrometheus("/var/lib/abroot/storage", "overlay")
29+
if err != nil {
30+
PrintVerbose("Podman.GenerateRootfs:err: %s", err)
31+
return err
32+
}
33+
2634
imageRecipePath := filepath.Join(transDir, "imageRecipe")
2735

2836
if transDir == dest {
2937
err := errors.New("transDir and dest cannot be the same")
30-
PrintVerbose("Podman.GenerateRootfs:err: %s", err)
38+
PrintVerbose("Podman.GenerateRootfs:err(2): %s", err)
3139
return err
3240
}
3341

3442
// cleanup dest
35-
err := os.RemoveAll(dest)
43+
err = os.RemoveAll(dest)
3644
if err != nil {
37-
PrintVerbose("Podman.GenerateRootfs:err: %s", err)
45+
PrintVerbose("Podman.GenerateRootfs:err(3): %s", err)
3846
return err
3947
}
4048
err = os.MkdirAll(dest, 0755)
4149
if err != nil {
42-
PrintVerbose("Podman.GenerateRootfs:err(2): %s", err)
50+
PrintVerbose("Podman.GenerateRootfs:err(4): %s", err)
4351
return err
4452
}
4553

4654
// cleanup transDir
4755
err = os.RemoveAll(transDir)
4856
if err != nil {
49-
PrintVerbose("Podman.GenerateRootfs:err(3): %s", err)
57+
PrintVerbose("Podman.GenerateRootfs:err(5): %s", err)
5058
return err
5159
}
5260
err = os.MkdirAll(transDir, 0755)
5361
if err != nil {
54-
PrintVerbose("Podman.GenerateRootfs:err(4): %s", err)
62+
PrintVerbose("Podman.GenerateRootfs:err(6): %s", err)
5563
return err
5664
}
5765

5866
// write imageRecipe
5967
err = imageRecipe.Write(imageRecipePath)
6068
if err != nil {
61-
PrintVerbose("Podman.GenerateRootfs:err(5): %s", err)
69+
PrintVerbose("Podman.GenerateRootfs:err(7): %s", err)
6270
return err
6371
}
6472

6573
// build image
66-
imageBuild, err := PodBuildImage(buildImageName, imageRecipePath)
74+
imageBuild, err := pt.BuildContainerFile(imageRecipePath, buildImageName)
6775
if err != nil {
68-
PrintVerbose("Podman.GenerateRootfs:err(6): %s", err)
76+
PrintVerbose("Podman.GenerateRootfs:err(8): %s", err)
6977
return err
7078
}
7179

7280
// mount image
73-
mountDir, err := PodMountImage(imageBuild)
81+
mountDir, err := pt.MountImage(imageBuild.TopLayer)
7482
if err != nil {
75-
PrintVerbose("Podman.GenerateRootfs:err(7): %s", err)
83+
PrintVerbose("Podman.GenerateRootfs:err(9): %s", err)
7684
return err
7785
}
7886

7987
// copy mount dir contents to dest
8088
err = rsyncCmd(mountDir+"/", dest, []string{}, false)
8189
if err != nil {
82-
PrintVerbose("Podman.GenerateRootfs:err(8): %s", err)
90+
PrintVerbose("Podman.GenerateRootfs:err(10): %s", err)
8391
return err
8492
}
8593

8694
// unmount image
87-
err = PodUnmountImage(imageBuild)
95+
_, err = pt.UnMountImage(imageBuild.TopLayer, true)
8896
if err != nil {
89-
PrintVerbose("Podman.GenerateRootfs:err(9): %s", err)
97+
PrintVerbose("Podman.GenerateRootfs:err(11): %s", err)
9098
return err
9199
}
92100

core/system.go

+21-42
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ func (s *ABSystem) CheckAll() error {
7878
}
7979

8080
// CheckUpdate checks if there is an update available
81-
func (s *ABSystem) CheckUpdate() bool {
81+
func (s *ABSystem) CheckUpdate() (string, bool) {
8282
PrintVerbose("ABSystem.CheckUpdate: running...")
8383
return s.Registry.HasUpdate(s.CurImage.Digest)
8484
}
8585

8686
// SyncEtc syncs /.system/etc -> /part-future/.system/etc
87-
func (s *ABSystem) SyncEtc(present ABRootPartition, future ABRootPartition) error {
88-
PrintVerbose("ABSystem.SyncEtc: SyncEtc running...")
87+
func (s *ABSystem) SyncEtc(newEtc string) error {
88+
PrintVerbose("ABSystem.SyncEtc: syncing /.system/etc -> %s", newEtc)
8989

9090
etcFiles := []string{
9191
"passwd",
@@ -96,18 +96,12 @@ func (s *ABSystem) SyncEtc(present ABRootPartition, future ABRootPartition) erro
9696
"subgid",
9797
}
9898

99-
etcDir := "/var/lib/abroot/etc" + present.Label
99+
etcDir := "/.system/etc"
100100
if _, err := os.Stat(etcDir); os.IsNotExist(err) {
101101
PrintVerbose("ABSystem.SyncEtc:err: %s", err)
102102
return err
103103
}
104104

105-
newEtc := "/var/lib/abroot/etc" + future.Label
106-
if _, err := os.Stat(newEtc); os.IsNotExist(err) {
107-
PrintVerbose("ABSystem.SyncEtc:err(2): %s", err)
108-
return err
109-
}
110-
111105
for _, file := range etcFiles {
112106
sourceFile := etcDir + "/" + file
113107
destFile := newEtc + "/" + file
@@ -234,17 +228,16 @@ func (s *ABSystem) GenerateFstab(rootPath string, root ABRootPartition) error {
234228
# <file system> <mount point> <type> <options> <dump> <pass>
235229
UUID=%s / %s defaults 0 0
236230
UUID=%s /var %s defaults 0 0
237-
/var/home /home none bind 0 0
238-
/var/opt /opt none bind 0 0
239-
/var/lib/abroot/etc/%s /etc none bind 0 0
231+
/var/home /home x-systemd.after=/var bind 0 0
232+
/var/opt /opt x-systemd.after=/var bind 0 0
233+
/.system/usr /.system/usr none bind,ro 0 0
240234
}`
241235
fstab := fmt.Sprintf(
242236
template,
243237
root.Partition.Uuid,
244238
root.Partition.FsType,
245239
s.RootM.VarPartition.Uuid,
246240
s.RootM.VarPartition.FsType,
247-
root.IdentifiedAs,
248241
)
249242

250243
err := ioutil.WriteFile(rootPath+"/etc/fstab", []byte(fstab), 0644)
@@ -263,46 +256,41 @@ func (s *ABSystem) Upgrade() error {
263256

264257
s.ResetQueue()
265258

266-
// Stage 0: Check if there is an update available
259+
// Stage 1: Check if there is an update available
267260
// ------------------------------------------------
268-
PrintVerbose("[Stage 0] -------- ABSystemUpgrade")
261+
PrintVerbose("[Stage 1] -------- ABSystemUpgrade")
269262

270-
if !s.CheckUpdate() {
263+
newDigest, res := s.CheckUpdate()
264+
if !res {
271265
err := errors.New("no update available")
272-
PrintVerbose("ABSystemUpgrade:err(0): %s", err)
266+
PrintVerbose("ABSystemUpgrade:err(1): %s", err)
273267
return err
274268
}
275269

276-
// Stage 1: Get the future root and boot partitions,
270+
// Stage 2: Get the future root and boot partitions,
277271
// mount future to /part-future and clean up
278272
// old .system_new and abimage-new.abr (it is
279273
// possible that last transaction was interrupted
280274
// before the clean up was done). Finally run
281275
// the IntegrityCheck on the future root.
282276
// ------------------------------------------------
283-
PrintVerbose("[Stage 1] -------- ABSystemUpgrade")
277+
PrintVerbose("[Stage 2] -------- ABSystemUpgrade")
284278

285279
partFuture, err := s.RootM.GetFuture()
286280
if err != nil {
287-
PrintVerbose("ABSystem.Upgrade:err(1): %s", err)
288-
return err
289-
}
290-
291-
partPresent, err := s.RootM.GetPresent()
292-
if err != nil {
293-
PrintVerbose("ABSystem.Upgrade:err(1.1): %s", err)
281+
PrintVerbose("ABSystem.Upgrade:err(2): %s", err)
294282
return err
295283
}
296284

297285
partBoot, err := s.RootM.GetBoot()
298286
if err != nil {
299-
PrintVerbose("ABSystem.Upgrade:err(1.2): %s", err)
287+
PrintVerbose("ABSystem.Upgrade:err(2.2): %s", err)
300288
return err
301289
}
302290

303291
err = partFuture.Partition.Mount("/part-future/")
304292
if err != nil {
305-
PrintVerbose("ABSystem.Upgrade:err(1.3: %s", err)
293+
PrintVerbose("ABSystem.Upgrade:err(2.3: %s", err)
306294
return err
307295
}
308296

@@ -313,17 +301,7 @@ func (s *ABSystem) Upgrade() error {
313301

314302
_, err = NewIntegrityCheck(partFuture, settings.Cnf.AutoRepair)
315303
if err != nil {
316-
PrintVerbose("ABSystem.Upgrade:err(1.4): %s", err)
317-
return err
318-
}
319-
320-
// Stage 2: Pull the new image
321-
// ------------------------------------------------
322-
PrintVerbose("[Stage 2] -------- ABSystemUpgrade")
323-
324-
podmanImage, err := PodPull(settings.Cnf.FullImageName)
325-
if err != nil {
326-
PrintVerbose("ABSystem.Upgrade:err(2): %s", err)
304+
PrintVerbose("ABSystem.Upgrade:err(2.4): %s", err)
327305
return err
328306
}
329307

@@ -368,7 +346,7 @@ func (s *ABSystem) Upgrade() error {
368346
// ------------------------------------------------
369347
PrintVerbose("[Stage 5] ABSystemUpgrade")
370348

371-
abimage := NewABImage(podmanImage.Digest, settings.Cnf.FullImageName)
349+
abimage := NewABImage(newDigest, settings.Cnf.FullImageName)
372350
err = abimage.WriteTo(partFuture.Partition.MountPoint, "new")
373351
if err != nil {
374352
PrintVerbose("ABSystem.Upgrade:err(5): %s", err)
@@ -428,7 +406,8 @@ func (s *ABSystem) Upgrade() error {
428406
// ------------------------------------------------
429407
PrintVerbose("[Stage 8] -------- ABSystemUpgrade")
430408

431-
err = s.SyncEtc(partPresent, partFuture)
409+
newEtc := filepath.Join(systemNew, "/etc")
410+
err = s.SyncEtc(newEtc)
432411
if err != nil {
433412
PrintVerbose("ABSystem.Upgrade:err(8): %s", err)
434413
return err

go.mod

+100-3
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,125 @@ go 1.18
55
require (
66
github.com/spf13/cobra v1.7.0
77
github.com/vanilla-os/orchid v0.4.0
8+
github.com/vanilla-os/prometheus v0.1.4
89
golang.org/x/sys v0.7.0
910
)
1011

1112
require (
13+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
14+
github.com/BurntSushi/toml v1.2.1 // indirect
15+
github.com/Microsoft/go-winio v0.6.0 // indirect
16+
github.com/Microsoft/hcsshim v0.10.0-rc.7 // indirect
17+
github.com/VividCortex/ewma v1.2.0 // indirect
18+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
19+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
20+
github.com/chzyer/readline v1.5.1 // indirect
21+
github.com/container-orchestrated-devices/container-device-interface v0.5.4 // indirect
22+
github.com/containerd/cgroups v1.1.0 // indirect
23+
github.com/containerd/containerd v1.7.0 // indirect
1224
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
25+
github.com/containernetworking/cni v1.1.2 // indirect
26+
github.com/containernetworking/plugins v1.2.0 // indirect
27+
github.com/containers/buildah v1.30.0 // indirect
28+
github.com/containers/common v0.52.0 // indirect
29+
github.com/containers/image/v5 v5.25.0 // indirect
30+
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
31+
github.com/containers/ocicrypt v1.1.7 // indirect
32+
github.com/containers/storage v1.46.1 // indirect
33+
github.com/cyberphone/json-canonicalization v0.0.0-20220623050100-57a0ce2678a7 // indirect
34+
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
35+
github.com/davecgh/go-spew v1.1.1 // indirect
36+
github.com/disiqueira/gotree/v3 v3.0.2 // indirect
1337
github.com/docker/cli v23.0.4+incompatible // indirect
1438
github.com/docker/distribution v2.8.1+incompatible // indirect
1539
github.com/docker/docker v23.0.4+incompatible // indirect
1640
github.com/docker/docker-credential-helpers v0.7.0 // indirect
41+
github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 // indirect
42+
github.com/docker/go-units v0.5.0 // indirect
1743
github.com/frankban/quicktest v1.14.4 // indirect
44+
github.com/fsouza/go-dockerclient v1.9.7 // indirect
45+
github.com/go-openapi/analysis v0.21.4 // indirect
46+
github.com/go-openapi/errors v0.20.3 // indirect
47+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
48+
github.com/go-openapi/jsonreference v0.20.0 // indirect
49+
github.com/go-openapi/loads v0.21.2 // indirect
50+
github.com/go-openapi/runtime v0.25.0 // indirect
51+
github.com/go-openapi/spec v0.20.8 // indirect
52+
github.com/go-openapi/strfmt v0.21.7 // indirect
53+
github.com/go-openapi/swag v0.22.3 // indirect
54+
github.com/go-openapi/validate v0.22.1 // indirect
55+
github.com/gogo/protobuf v1.3.2 // indirect
56+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
57+
github.com/golang/protobuf v1.5.3 // indirect
58+
github.com/google/go-intervals v0.0.2 // indirect
59+
github.com/gorilla/mux v1.8.0 // indirect
60+
github.com/hashicorp/errwrap v1.1.0 // indirect
61+
github.com/hashicorp/go-multierror v1.1.1 // indirect
62+
github.com/imdario/mergo v0.3.15 // indirect
63+
github.com/jinzhu/copier v0.3.5 // indirect
64+
github.com/josharian/intern v1.0.0 // indirect
65+
github.com/json-iterator/go v1.1.12 // indirect
1866
github.com/klauspost/compress v1.16.5 // indirect
67+
github.com/klauspost/pgzip v1.2.6-0.20220930104621-17e8dac29df8 // indirect
68+
github.com/letsencrypt/boulder v0.0.0-20230213213521-fdfea0d469b6 // indirect
69+
github.com/mailru/easyjson v0.7.7 // indirect
70+
github.com/manifoldco/promptui v0.9.0 // indirect
71+
github.com/mattn/go-shellwords v1.0.12 // indirect
72+
github.com/miekg/pkcs11 v1.1.1 // indirect
73+
github.com/mistifyio/go-zfs/v3 v3.0.0 // indirect
1974
github.com/mitchellh/go-homedir v1.1.0 // indirect
75+
github.com/moby/patternmatcher v0.5.0 // indirect
76+
github.com/moby/sys/mountinfo v0.6.2 // indirect
77+
github.com/moby/sys/sequential v0.5.0 // indirect
78+
github.com/moby/term v0.0.0-20221120202655-abb19827d345 // indirect
79+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
80+
github.com/modern-go/reflect2 v1.0.2 // indirect
81+
github.com/morikuni/aec v1.0.0 // indirect
82+
github.com/oklog/ulid v1.3.1 // indirect
2083
github.com/opencontainers/go-digest v1.0.0 // indirect
2184
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b //indirect
85+
github.com/opencontainers/runc v1.1.5 // indirect
86+
github.com/opencontainers/runtime-spec v1.1.0-rc.1 // indirect
87+
github.com/opencontainers/runtime-tools v0.9.1-0.20230317050512-e931285f4b69 // indirect
88+
github.com/opencontainers/selinux v1.11.0 // indirect
89+
github.com/openshift/imagebuilder v1.2.4-0.20230309135844-a3c3f8358ca3 // indirect
90+
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f // indirect
2291
github.com/pkg/errors v0.9.1 // indirect
23-
github.com/rogpeppe/go-internal v1.10.0 // indirect
92+
github.com/pmezard/go-difflib v1.0.0 // indirect
93+
github.com/proglottis/gpgme v0.1.3 // indirect
94+
github.com/seccomp/libseccomp-golang v0.10.0 // indirect
95+
github.com/sigstore/fulcio v1.2.0 // indirect
96+
github.com/sigstore/rekor v1.1.0 // indirect
97+
github.com/sigstore/sigstore v1.6.0 // indirect
2498
github.com/sirupsen/logrus v1.9.0 // indirect
25-
github.com/stretchr/testify v1.8.2 // indirect
99+
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980 // indirect
100+
github.com/sylabs/sif/v2 v2.11.1 // indirect
101+
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
102+
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
103+
github.com/theupdateframework/go-tuf v0.5.2 // indirect
104+
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
105+
github.com/ulikunitz/xz v0.5.11 // indirect
26106
github.com/vbatts/tar-split v0.11.3 // indirect
107+
github.com/vbauerster/mpb/v8 v8.3.0 // indirect
108+
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
109+
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
110+
go.etcd.io/bbolt v1.3.7 // indirect
111+
go.mongodb.org/mongo-driver v1.11.3 // indirect
112+
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
113+
go.opencensus.io v0.24.0 // indirect
114+
golang.org/x/crypto v0.8.0 // indirect
27115
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
116+
golang.org/x/mod v0.10.0 // indirect
117+
golang.org/x/net v0.9.0 // indirect
28118
golang.org/x/sync v0.1.0 // indirect
29-
gotest.tools/v3 v3.4.0 // indirect
119+
golang.org/x/tools v0.8.0 // indirect
120+
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
121+
google.golang.org/grpc v1.54.0 // indirect
122+
google.golang.org/protobuf v1.30.0 // indirect
123+
gopkg.in/go-jose/go-jose.v2 v2.6.1 // indirect
124+
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
125+
gopkg.in/yaml.v2 v2.4.0 // indirect
126+
sigs.k8s.io/yaml v1.3.0 // indirect
30127
)
31128

32129
require (

0 commit comments

Comments
 (0)