Skip to content

Commit 41f7d7b

Browse files
wswsmaoimeoer
authored andcommitted
Support zstdchunked conversion
Signed-off-by: abushwang <abushwangs@gmail.com>
1 parent 3fae33b commit 41f7d7b

File tree

5 files changed

+110
-6
lines changed

5 files changed

+110
-6
lines changed

.github/workflows/integration-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ jobs:
9393
run: |
9494
./script/integration/estargz/test.sh ${{ env.OCI_IMAGE_NAME }}
9595
96+
- name: Test eStargz Driver (zstdchunked)
97+
run: |
98+
./script/integration/estargz/test-zstdchunked.sh ${{ env.OCI_IMAGE_NAME }}
99+
96100
- name: Test one-time mode
97101
run: |
98102
./script/integration/one-time.sh ${{ env.OCI_IMAGE_NAME }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Acceleration Service
22

33
Acceleration Service provides a general service to Harbor with the ability to automatically convert user images to accelerated images. When a user does something such as artifact push, Harbor will request the service to complete the corresponding image conversion through its integrated [Nydus](https://github.com/dragonflyoss/image-service),
4-
[eStargz](https://github.com/containerd/stargz-snapshotter), etc. drivers.
4+
[eStargz, zstdchunked](https://github.com/containerd/stargz-snapshotter) etc. drivers.
55

66
[![Release Version](https://img.shields.io/github/v/release/goharbor/acceleration-service?style=flat)](https://github.com/goharbor/acceleration-service/releases)
77
[![Docker Pulls](https://img.shields.io/docker/pulls/goharbor/harbor-acceld.svg)](https://hub.docker.com/r/goharbor/harbor-acceld/)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Configuration file of Harbor Acceleration Service
2+
3+
# http related config
4+
server:
5+
name: API
6+
# listened host for http
7+
host: 0.0.0.0
8+
# port for http
9+
port: 2077
10+
11+
metric:
12+
# export metrics on `/metrics` endpoint
13+
enabled: true
14+
15+
provider:
16+
source:
17+
# hostname of harbor service
18+
hub.harbor.com:
19+
# base64 encoded `<robot-name>:<robot-secret>` for robot
20+
# account created in harbor
21+
# auth: YTpiCg==
22+
# skip verifying server certs for HTTPS source registry
23+
insecure: false
24+
webhook:
25+
# webhook request auth header configured in harbor
26+
auth_header: header
27+
localhost:
28+
# If auth is not provided, it will attempt to read from docker config
29+
# auth: YWRtaW46SGFyYm9yMTIzNDU=
30+
# work directory of acceld
31+
work_dir: /tmp
32+
gcpolicy:
33+
# size threshold that triggers GC, the oldest used blobs will be reclaimed if exceeds the size.
34+
threshold: 1000MB
35+
36+
converter:
37+
# number of worker for executing conversion task
38+
worker: 5
39+
# enable to add harbor specified annotations to converted image for tracking.
40+
harbor_annotation: true
41+
# only convert images for specific platforms, leave empty for all platforms.
42+
# platforms: linux/amd64,linux/arm64
43+
driver:
44+
# accelerator driver type: `estargz`
45+
type: estargz
46+
config:
47+
docker2oci: true
48+
# compress format: `zstdchunked`
49+
compression: zstdchunked
50+
rules:
51+
# add suffix to tag of source image reference as target image reference
52+
- tag_suffix: -estargz-zstdchunked

pkg/driver/estargz/estargz.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,35 @@ package estargz
1616

1717
import (
1818
"context"
19+
"fmt"
1920
"strconv"
2021

2122
"github.com/containerd/containerd/images/converter"
2223
"github.com/containerd/platforms"
2324
"github.com/containerd/stargz-snapshotter/estargz"
2425
estargzconvert "github.com/containerd/stargz-snapshotter/nativeconverter/estargz"
26+
zstdchunkedconvert "github.com/containerd/stargz-snapshotter/nativeconverter/zstdchunked"
2527
"github.com/goharbor/acceleration-service/pkg/content"
2628
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2729
"github.com/pkg/errors"
2830
)
2931

32+
const (
33+
DefaultCompressFormat = "estargz"
34+
ZstdChunkedFormat = "zstdchunked"
35+
)
36+
37+
type layerConverter func([]estargz.Option) converter.ConvertFunc
38+
39+
var compressFormatConverters = map[string]layerConverter{
40+
DefaultCompressFormat: func(opts []estargz.Option) converter.ConvertFunc {
41+
return estargzconvert.LayerConvertFunc(opts...)
42+
},
43+
ZstdChunkedFormat: func(opts []estargz.Option) converter.ConvertFunc {
44+
return zstdchunkedconvert.LayerConvertFunc(opts...)
45+
},
46+
}
47+
3048
type Driver struct {
3149
cfg map[string]string
3250
platformMC platforms.MatchComparer
@@ -37,15 +55,22 @@ func New(cfg map[string]string, platformMC platforms.MatchComparer) (*Driver, er
3755
}
3856

3957
func (d *Driver) Convert(ctx context.Context, p content.Provider, ref string) (*ocispec.Descriptor, error) {
40-
opts, docker2oci, err := getESGZConvertOpts(d.cfg)
58+
opts, docker2oci, compressFormat, err := getConvertOpts(d.cfg)
4159
if err != nil {
42-
return nil, errors.Wrap(err, "parse estargz conversion options")
60+
return nil, errors.Wrap(err, "parse conversion options")
4361
}
62+
63+
layerConv, ok := compressFormatConverters[compressFormat]
64+
if !ok {
65+
return nil, fmt.Errorf("unsupported compress format: %s", compressFormat)
66+
}
67+
4468
image, err := p.Image(ctx, ref)
4569
if err != nil {
4670
return nil, errors.Wrap(err, "get source image")
4771
}
48-
return converter.DefaultIndexConvertFunc(estargzconvert.LayerConvertFunc(opts...), docker2oci, d.platformMC)(
72+
73+
return converter.DefaultIndexConvertFunc(layerConv(opts), docker2oci, d.platformMC)(
4974
ctx, p.ContentStore(), *image)
5075
}
5176

@@ -57,11 +82,16 @@ func (d *Driver) Version() string {
5782
return ""
5883
}
5984

60-
func getESGZConvertOpts(cfg map[string]string) (opts []estargz.Option, docker2oci bool, err error) {
85+
func getConvertOpts(cfg map[string]string) (opts []estargz.Option, docker2oci bool, compressFormat string, err error) {
86+
compressFormat = DefaultCompressFormat
87+
if format, ok := cfg["compression"]; ok && format != "" {
88+
compressFormat = format
89+
}
90+
6191
if s, ok := cfg["docker2oci"]; ok {
6292
b, err := strconv.ParseBool(s)
6393
if err != nil {
64-
return nil, false, err
94+
return nil, false, "", err
6595
}
6696
docker2oci = b
6797
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
OCI_IMAGE_NAME=$1
6+
7+
# Start acceld service
8+
sudo nohup ./acceld --config ./misc/config/config.estargz.zstdchunked.yaml &> acceld.log &
9+
sleep 1
10+
11+
# Convert image by accelctl
12+
sudo ./accelctl task create --sync localhost/library/$OCI_IMAGE_NAME:latest
13+
14+
# Verify filesystem consistency for converted image
15+
# TODO
16+
17+
# Gracefully exit acceld
18+
sudo pkill -SIGINT acceld

0 commit comments

Comments
 (0)