Skip to content

Commit e997d4f

Browse files
authored
feat(erofs): initial commit for erofs support (#626)
* feat: add support for erofs layers - atomfs has added support for additional filesystem types such as erofs. * fix: use atomfs v1.2.0 * ci: use our own cached images instead of upstream Signed-off-by: Ramkumar Chinchani <[email protected]>
1 parent c34ba3a commit e997d4f

16 files changed

+236
-48
lines changed

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
echo "running kernel is: $(uname -a)"
7171
- name: docker-clone
7272
run: |
73-
make docker-clone "STACKER_DOCKER_BASE=docker://" CLONE_D="$PWD/.build/oci-clone"
73+
make docker-clone "STACKER_DOCKER_BASE=docker://ghcr.io/project-stacker/" CLONE_D="$PWD/.build/oci-clone"
7474
- name: Go-download
7575
run: |
7676
make go-download

.github/workflows/coverage.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ on:
3232

3333
jobs:
3434
build:
35-
runs-on: ubuntu-22.04
35+
runs-on: ubuntu-24.04
3636
services:
3737
registry:
3838
image: ghcr.io/project-stacker/registry:2
@@ -71,7 +71,7 @@ jobs:
7171
echo "running kernel is: $(uname -a)"
7272
- name: docker-clone
7373
run: |
74-
make docker-clone "STACKER_DOCKER_BASE=docker://" CLONE_D="$PWD/.build/oci-clone"
74+
make docker-clone "STACKER_DOCKER_BASE=docker://ghcr.io/project-stacker/" CLONE_D="$PWD/.build/oci-clone"
7575
- name: Go-download
7676
run: |
7777
make go-download

cmd/stacker/build.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55

66
cli "github.com/urfave/cli/v2"
7-
"machinerun.io/atomfs/squashfs"
7+
"machinerun.io/atomfs/pkg/verity"
88
"stackerbuild.io/stacker/pkg/stacker"
99
"stackerbuild.io/stacker/pkg/types"
1010
)
@@ -52,12 +52,13 @@ func initCommonBuildFlags() []cli.Flag {
5252
},
5353
&cli.StringSliceFlag{
5454
Name: "layer-type",
55-
Usage: "set the output layer type (supported values: tar, squashfs); can be supplied multiple times",
55+
Usage: "set the output layer type (supported values: tar, squashfs, erofs); can be supplied multiple times",
5656
Value: cli.NewStringSlice("tar"),
5757
},
5858
&cli.BoolFlag{
59-
Name: "no-squashfs-verity",
60-
Usage: "do not append dm-verity data to squashfs archives",
59+
Name: "no-verity",
60+
Usage: "do not append dm-verity data to fs archives",
61+
Aliases: []string{"no-squashfs-verity"},
6162
},
6263
&cli.BoolFlag{
6364
Name: "require-hash",
@@ -103,7 +104,7 @@ func newBuildArgs(ctx *cli.Context) (stacker.BuildArgs, error) {
103104
AnnotationsNamespace: ctx.String("annotations-namespace"),
104105
}
105106
var err error
106-
verity := squashfs.VerityMetadata(!ctx.Bool("no-squashfs-verity"))
107+
verity := verity.VerityMetadata(!ctx.Bool("no-verity"))
107108
args.LayerTypes, err = types.NewLayerTypes(ctx.StringSlice("layer-type"), verity)
108109
return args, err
109110
}

cmd/stacker/inspect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/opencontainers/umoci/oci/casext"
1212
"github.com/pkg/errors"
1313
cli "github.com/urfave/cli/v2"
14-
stackeroci "machinerun.io/atomfs/oci"
14+
stackeroci "machinerun.io/atomfs/pkg/oci"
1515
)
1616

1717
var inspectCmd = cli.Command{

cmd/stacker/internal_go.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/pkg/errors"
1010
cli "github.com/urfave/cli/v2"
1111
"golang.org/x/sys/unix"
12-
"machinerun.io/atomfs"
12+
"machinerun.io/atomfs/pkg/molecule"
1313
"stackerbuild.io/stacker/pkg/lib"
1414
"stackerbuild.io/stacker/pkg/log"
1515
"stackerbuild.io/stacker/pkg/overlay"
@@ -176,14 +176,14 @@ func doAtomfsMount(ctx *cli.Context) error {
176176
tag := ctx.Args().Get(0)
177177
mountpoint := ctx.Args().Get(1)
178178

179-
opts := atomfs.MountOCIOpts{
179+
opts := molecule.MountOCIOpts{
180180
OCIDir: config.OCIDir,
181181
Tag: tag,
182182
Target: mountpoint,
183183
AllowMissingVerityData: true,
184184
}
185185

186-
mol, err := atomfs.BuildMoleculeFromOCI(opts)
186+
mol, err := molecule.BuildMoleculeFromOCI(opts)
187187
if err != nil {
188188
return err
189189
}
@@ -199,5 +199,5 @@ func doAtomfsUmount(ctx *cli.Context) error {
199199
}
200200

201201
mountpoint := ctx.Args().Get(0)
202-
return atomfs.Umount(mountpoint)
202+
return molecule.Umount(mountpoint)
203203
}

cmd/stacker/publish.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"github.com/pkg/errors"
55
cli "github.com/urfave/cli/v2"
6-
"machinerun.io/atomfs/squashfs"
6+
"machinerun.io/atomfs/pkg/verity"
77
"stackerbuild.io/stacker/pkg/lib"
88
"stackerbuild.io/stacker/pkg/stacker"
99
"stackerbuild.io/stacker/pkg/types"
@@ -69,7 +69,7 @@ var publishCmd = cli.Command{
6969
},
7070
&cli.StringSliceFlag{
7171
Name: "layer-type",
72-
Usage: "set the output layer type (supported values: tar, squashfs); can be supplied multiple times",
72+
Usage: "set the output layer type (supported values: tar, squashfs, erofs); can be supplied multiple times",
7373
Value: cli.NewStringSlice("tar"),
7474
},
7575
&cli.StringSliceFlag{
@@ -108,7 +108,7 @@ func beforePublish(ctx *cli.Context) error {
108108
}
109109

110110
func doPublish(ctx *cli.Context) error {
111-
verity := squashfs.VerityMetadata(!ctx.Bool("no-squashfs-verity"))
111+
verity := verity.VerityMetadata(!ctx.Bool("no-verity"))
112112
layerTypes, err := types.NewLayerTypes(ctx.StringSlice("layer-type"), verity)
113113
if err != nil {
114114
return err

cmd/stacker/validate.go

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func validateLayerTypeFlags(ctx *cli.Context) error {
5050
break
5151
case "squashfs":
5252
break
53+
case "erofs":
54+
break
5355
default:
5456
return errors.Errorf("unknown layer type: %s", layerType)
5557
}

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/mitchellh/hashstructure v1.1.0
2020
github.com/moby/buildkit v0.11.4
2121
github.com/opencontainers/go-digest v1.0.0
22-
github.com/opencontainers/image-spec v1.1.0-rc4
22+
github.com/opencontainers/image-spec v1.1.0
2323
github.com/opencontainers/umoci v0.4.8-0.20220412065115-12453f247749
2424
github.com/pkg/errors v0.9.1
2525
github.com/pkg/xattr v0.4.9
@@ -278,7 +278,7 @@ require (
278278
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
279279
gopkg.in/warnings.v0 v0.1.2 // indirect
280280
gopkg.in/yaml.v3 v3.0.1 // indirect
281-
machinerun.io/atomfs v1.1.3
281+
machinerun.io/atomfs v1.2.0
282282
modernc.org/libc v1.37.6 // indirect
283283
modernc.org/mathutil v1.6.0 // indirect
284284
modernc.org/memory v1.7.2 // indirect

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3ev
754754
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
755755
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
756756
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
757-
github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0=
758-
github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
757+
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
758+
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
759759
github.com/opencontainers/runc v1.2.3 h1:fxE7amCzfZflJO2lHXf4y/y8M1BoAqp+FVmG19oYB80=
760760
github.com/opencontainers/runc v1.2.3/go.mod h1:nSxcWUydXrsBZVYNSkTjoQ/N6rcyTtn+1SD5D4+kRIM=
761761
github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
@@ -1598,8 +1598,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
15981598
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
15991599
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
16001600
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
1601-
machinerun.io/atomfs v1.1.3 h1:oV1SH7VI2MqAks7FlirhLLKvyVcJkMB0NFevXF8EJaU=
1602-
machinerun.io/atomfs v1.1.3/go.mod h1:qXz4epm3/7vEpEyf9YaTCafp3CwbUeDa1XrYyx7qbPc=
1601+
machinerun.io/atomfs v1.2.0 h1:w2YtDncppFjOKWGeK0yfgCYcB5dJIZSngVHb6UWljv0=
1602+
machinerun.io/atomfs v1.2.0/go.mod h1:jrGbuGXiCPi4LFoMvcPRnqPGlxe3pW8UtLEnhUcGRmI=
16031603
modernc.org/libc v1.37.6 h1:orZH3c5wmhIQFTXF+Nt+eeauyd+ZIt2BX6ARe+kD+aw=
16041604
modernc.org/libc v1.37.6/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
16051605
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=

install-build-deps.sh

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ installdeps_ubuntu() {
4444
squashfuse
4545
libarchive-tools
4646
shellcheck
47+
erofs-utils
48+
erofsfuse
4749
)
4850

4951
case "$VERSION_ID" in
@@ -86,6 +88,11 @@ installdeps_ubuntu() {
8688
sudo apt -yy install golang-go
8789
go version
8890
fi
91+
92+
# cloud kernels, like linux-azure, don't include erofs in the linux-modules package and instead put it linux-modules-extra
93+
if ! modinfo erofs &>/dev/null; then
94+
sudo apt -yy install linux-modules-extra-$(uname -r)
95+
fi
8996
}
9097

9198
enable_userns() {

pkg/lib/image_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
"github.com/opencontainers/umoci/mutate"
1414
"github.com/opencontainers/umoci/oci/casext"
1515
"github.com/stretchr/testify/assert"
16-
"machinerun.io/atomfs/squashfs"
16+
"machinerun.io/atomfs/pkg/squashfs"
17+
"machinerun.io/atomfs/pkg/verity"
1718
)
1819

1920
func createImage(dir string, tag string) error {
@@ -48,7 +49,7 @@ func createImage(dir string, tag string) error {
4849

4950
// need *something* in the layer, why not just recursively include the
5051
// OCI image for maximum confusion :)
51-
layer, mediaType, _, err := squashfs.MakeSquashfs(dir, path.Join(dir, "oci"), nil, squashfs.VerityMetadataMissing)
52+
layer, mediaType, _, err := squashfs.MakeSquashfs(dir, path.Join(dir, "oci"), nil, verity.VerityMetadataMissing)
5253
if err != nil {
5354
return err
5455
}

pkg/overlay/metadata.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
ispec "github.com/opencontainers/image-spec/specs-go/v1"
1111
"github.com/opencontainers/umoci/oci/casext"
1212
"github.com/pkg/errors"
13-
stackeroci "machinerun.io/atomfs/oci"
13+
stackeroci "machinerun.io/atomfs/pkg/oci"
1414
"stackerbuild.io/stacker/pkg/log"
1515
"stackerbuild.io/stacker/pkg/types"
1616
)

pkg/overlay/pack.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import (
2222
"github.com/opencontainers/umoci/oci/layer"
2323
"github.com/pkg/errors"
2424
"github.com/pkg/xattr"
25-
stackeroci "machinerun.io/atomfs/oci"
26-
"machinerun.io/atomfs/squashfs"
25+
stackerfs "machinerun.io/atomfs/pkg/fs"
26+
stackeroci "machinerun.io/atomfs/pkg/oci"
27+
fstypes "machinerun.io/atomfs/pkg/types"
28+
"machinerun.io/atomfs/pkg/verity"
2729
"stackerbuild.io/stacker/pkg/lib"
2830
"stackerbuild.io/stacker/pkg/log"
2931
"stackerbuild.io/stacker/pkg/storage"
@@ -280,7 +282,8 @@ func generateBlob(layerType types.LayerType, contents string, ociDir string, low
280282
blob = layer.GenerateInsertLayer(contents, "/", false, &packOptions)
281283
mediaType = ispec.MediaTypeImageLayer
282284
} else {
283-
blob, mediaType, rootHash, err = squashfs.MakeSquashfs(ociDir, contents, nil, layerType.Verity)
285+
fsi := stackerfs.New(fstypes.FilesystemType(layerType.Type))
286+
blob, mediaType, rootHash, err = fsi.Make(ociDir, contents, nil, layerType.Verity)
284287
if err != nil {
285288
return nil, "", "", err
286289
}
@@ -303,7 +306,7 @@ func ociPutBlob(blob io.ReadCloser, config types.StackerConfig, layerMediaType s
303306

304307
annotations := map[string]string{}
305308
if rootHash != "" {
306-
annotations[squashfs.VerityRootHashAnnotation] = rootHash
309+
annotations[verity.VerityRootHashAnnotation] = rootHash
307310
}
308311

309312
desc := ispec.Descriptor{
@@ -443,7 +446,7 @@ func generateLayer(config types.StackerConfig, _ casext.Engine, mutators []*muta
443446
} else {
444447
annotations := map[string]string{}
445448
if rootHash != "" {
446-
annotations[squashfs.VerityRootHashAnnotation] = rootHash
449+
annotations[verity.VerityRootHashAnnotation] = rootHash
447450
}
448451
desc, err = mutator.Add(context.Background(), mediaType, blob, history, mutate.NoopCompressor, annotations)
449452
if err != nil {
@@ -693,10 +696,11 @@ func unpackOne(l ispec.Descriptor, ociDir string, extractDir string) error {
693696
return nil
694697
}
695698

696-
if squashfs.IsSquashfsMediaType(l.MediaType) {
697-
return squashfs.ExtractSingleSquash(
699+
if fsi := stackerfs.NewFromMediaType(l.MediaType); fsi != nil {
700+
return fsi.ExtractSingle(
698701
path.Join(ociDir, "blobs", "sha256", l.Digest.Encoded()), extractDir)
699702
}
703+
700704
switch l.MediaType {
701705
case ispec.MediaTypeImageLayer, ispec.MediaTypeImageLayerGzip:
702706
tarEx.Lock()

pkg/types/layer_type.go

+23-14
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import (
77

88
ispec "github.com/opencontainers/image-spec/specs-go/v1"
99
"github.com/pkg/errors"
10-
"machinerun.io/atomfs/squashfs"
10+
"machinerun.io/atomfs/pkg/erofs"
11+
"machinerun.io/atomfs/pkg/squashfs"
12+
"machinerun.io/atomfs/pkg/verity"
1113
)
1214

1315
var ErrEmptyLayers = errors.New("empty layers")
1416

1517
type LayerType struct {
1618
Type string
17-
Verity squashfs.VerityMetadata
19+
Verity verity.VerityMetadata
1820
}
1921

2022
func (lt LayerType) String() string {
@@ -44,14 +46,14 @@ func (lt *LayerType) UnmarshalText(text []byte) error {
4446
return errors.Wrapf(err, "bad verity bool: %s", fields[1])
4547
}
4648

47-
lt.Verity = squashfs.VerityMetadata(result)
49+
lt.Verity = verity.VerityMetadata(result)
4850

4951
return nil
5052
}
5153

52-
func NewLayerType(lt string, verity squashfs.VerityMetadata) (LayerType, error) {
54+
func NewLayerType(lt string, verity verity.VerityMetadata) (LayerType, error) {
5355
switch lt {
54-
case "squashfs":
56+
case "squashfs", "erofs":
5557
return LayerType{Type: lt, Verity: verity}, nil
5658
case "tar":
5759
return LayerType{Type: lt}, nil
@@ -62,31 +64,38 @@ func NewLayerType(lt string, verity squashfs.VerityMetadata) (LayerType, error)
6264

6365
func NewLayerTypeManifest(manifest ispec.Manifest) (LayerType, error) {
6466
if len(manifest.Layers) == 0 {
65-
return NewLayerType("tar", squashfs.VerityMetadataMissing)
67+
return NewLayerType("tar", verity.VerityMetadataMissing)
6668
}
6769

70+
_, verityMetadataPresent := manifest.Layers[0].Annotations[verity.VerityRootHashAnnotation]
71+
6872
switch manifest.Layers[0].MediaType {
6973
case squashfs.BaseMediaTypeLayerSquashfs:
7074
// older stackers generated media types without compression information
7175
fallthrough
72-
case squashfs.GenerateSquashfsMediaType(squashfs.GzipCompression, squashfs.VerityMetadataMissing):
76+
case squashfs.GenerateSquashfsMediaType(squashfs.GzipCompression):
77+
fallthrough
78+
case squashfs.GenerateSquashfsMediaType(squashfs.ZstdCompression):
79+
return NewLayerType("squashfs", verity.VerityMetadata(verityMetadataPresent))
80+
case erofs.BaseMediaTypeLayerErofs:
81+
// older stackers generated media types without compression information
82+
fallthrough
83+
case erofs.GenerateErofsMediaType(erofs.LZ4HCCompression):
7384
fallthrough
74-
case squashfs.GenerateSquashfsMediaType(squashfs.ZstdCompression, squashfs.VerityMetadataMissing):
75-
return NewLayerType("squashfs", squashfs.VerityMetadataMissing)
76-
case squashfs.GenerateSquashfsMediaType(squashfs.GzipCompression, squashfs.VerityMetadataPresent):
85+
case erofs.GenerateErofsMediaType(erofs.LZ4Compression):
7786
fallthrough
78-
case squashfs.GenerateSquashfsMediaType(squashfs.ZstdCompression, squashfs.VerityMetadataPresent):
79-
return NewLayerType("squashfs", squashfs.VerityMetadataPresent)
87+
case erofs.GenerateErofsMediaType(erofs.ZstdCompression):
88+
return NewLayerType("erofs", verity.VerityMetadata(verityMetadataPresent))
8089
case ispec.MediaTypeImageLayerGzip:
8190
fallthrough
8291
case ispec.MediaTypeImageLayer:
83-
return NewLayerType("tar", squashfs.VerityMetadataMissing)
92+
return NewLayerType("tar", verity.VerityMetadataMissing)
8493
default:
8594
return LayerType{}, errors.Errorf("invalid layer type %s", manifest.Layers[0].MediaType)
8695
}
8796
}
8897

89-
func NewLayerTypes(lts []string, verity squashfs.VerityMetadata) ([]LayerType, error) {
98+
func NewLayerTypes(lts []string, verity verity.VerityMetadata) ([]LayerType, error) {
9099
ret := []LayerType{}
91100
for _, lt := range lts {
92101
hoisted, err := NewLayerType(lt, verity)

0 commit comments

Comments
 (0)