Skip to content

Commit 3db15c2

Browse files
authored
Merge pull request #17 from coderbirju/add-soci-convert
add soci convert feature
2 parents 694c405 + dda79d3 commit 3db15c2

File tree

22 files changed

+312
-117
lines changed

22 files changed

+312
-117
lines changed

.github/workflows/ghcr-image-build-and-publish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ jobs:
6161
# Build and push Docker image with Buildx (don't push on PR)
6262
# https://github.com/docker/build-push-action
6363
- name: Build and push Docker image
64-
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0
64+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
6565
with:
6666
context: .
6767
platforms: linux/amd64,linux/arm64
6868
push: ${{ github.event_name != 'pull_request' }}
6969
tags: ${{ steps.meta.outputs.tags }}
7070
labels: ${{ steps.meta.outputs.labels }}
71+
secrets: |
72+
github_token=${{ secrets.GITHUB_TOKEN }}

.github/workflows/job-test-dependencies.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
4040

4141
- name: "Run: build dependencies for the integration test environment image"
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4244
run: |
4345
# Cache is sharded per-architecture
4446
arch=${{ env.RUNNER_ARCH == 'ARM64' && 'arm64' || 'amd64' }}
@@ -49,6 +51,7 @@ jobs:
4951
args=(--build-arg CONTAINERD_VERSION=${{ inputs.containerd-version }})
5052
fi
5153
docker buildx build \
54+
--secret id=github_token,env=GITHUB_TOKEN \
5255
--cache-to type=gha,compression=zstd,mode=max,scope=test-integration-dependencies-"$arch" \
5356
--cache-from type=gha,scope=test-integration-dependencies-"$arch" \
5457
--target build-dependencies "${args[@]}" .

.github/workflows/job-test-in-container.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ jobs:
8686
canary::build::integration
8787
- if: ${{ ! inputs.canary }}
8888
name: "Init: prepare test image"
89+
env:
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8991
run: |
9092
buildargs=()
9193
# If the runner is old, use old ubuntu inside the container as well
@@ -104,6 +106,7 @@ jobs:
104106
arch=${{ env.RUNNER_ARCH == 'ARM64' && 'arm64' || 'amd64' }}
105107
docker buildx create --name with-gha --use
106108
docker buildx build \
109+
--secret id=github_token,env=GITHUB_TOKEN \
107110
--output=type=docker \
108111
--cache-from type=gha,scope=test-integration-dependencies-"$arch" \
109112
-t "$target" --target "$target" \

.github/workflows/job-test-in-lima.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
fetch-depth: 1
3232

3333
- name: "Init: lima"
34-
uses: lima-vm/lima-actions/setup@be564a1408f84557d067b099a475652288074b2e # v1.0.0
34+
uses: lima-vm/lima-actions/setup@03b96d61959e83b2c737e44162c3088e81de0886 # v1.0.1
3535
id: lima-actions-setup
3636

3737
- name: "Init: Cache"
@@ -79,6 +79,8 @@ jobs:
7979
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
8080

8181
- name: "Init: prepare integration tests"
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8284
run: |
8385
set -eux
8486
@@ -88,6 +90,7 @@ jobs:
8890
[ "$TARGET" = "rootless" ] && TARGET=test-integration-rootless || TARGET=test-integration
8991
docker buildx create --name with-gha --use
9092
docker buildx build \
93+
--secret id=github_token,env=GITHUB_TOKEN \
9194
--output=type=docker \
9295
--cache-from type=gha,scope=test-integration-dependencies-amd64 \
9396
-t test-integration --target "${TARGET}" \

Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ENV DEBIAN_FRONTEND=noninteractive
6161
RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
6262
make \
6363
git \
64+
jq \
6465
curl \
6566
dpkg-dev
6667
ARG TARGETARCH
@@ -75,6 +76,7 @@ RUN xx-apt-get update -qq && xx-apt-get install -qq --no-install-recommends \
7576
pkg-config
7677
RUN git config --global advice.detachedHead false
7778
ADD hack/git-checkout-tag-with-hash.sh /usr/local/bin/
79+
ADD hack/scripts/lib.sh /usr/local/bin/http::helper
7880

7981
FROM build-base AS build-containerd
8082
ARG TARGETARCH
@@ -174,10 +176,11 @@ RUN cd /out/lib/systemd/system && \
174176
echo "" >> buildkit.service && \
175177
echo "# This file was converted from containerd.service, with \`sed -E '${sedcomm}'\`" >> buildkit.service
176178
ARG STARGZ_SNAPSHOTTER_VERSION
177-
RUN STARGZ_SNAPSHOTTER_VERSION=${STARGZ_SNAPSHOTTER_VERSION%%@*}; \
179+
RUN --mount=type=secret,id=github_token,env=GITHUB_TOKEN \
180+
STARGZ_SNAPSHOTTER_VERSION=${STARGZ_SNAPSHOTTER_VERSION%%@*}; \
178181
fname="stargz-snapshotter-${STARGZ_SNAPSHOTTER_VERSION}-${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.gz" && \
179182
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/containerd/stargz-snapshotter/releases/download/${STARGZ_SNAPSHOTTER_VERSION}/${fname}" && \
180-
curl -o "stargz-snapshotter.service" -fsSL --proto '=https' --tlsv1.2 "https://raw.githubusercontent.com/containerd/stargz-snapshotter/${STARGZ_SNAPSHOTTER_VERSION}/script/config/etc/systemd/system/stargz-snapshotter.service" && \
183+
http::helper github::file containerd/stargz-snapshotter script/config/etc/systemd/system/stargz-snapshotter.service "${STARGZ_SNAPSHOTTER_VERSION}" > "stargz-snapshotter.service" && \
181184
grep "${fname}" "/SHA256SUMS.d/stargz-snapshotter-${STARGZ_SNAPSHOTTER_VERSION}" | sha256sum -c - && \
182185
grep "stargz-snapshotter.service" "/SHA256SUMS.d/stargz-snapshotter-${STARGZ_SNAPSHOTTER_VERSION}" | sha256sum -c - && \
183186
tar xzf "${fname}" -C /out/bin && \
@@ -245,6 +248,10 @@ RUN ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION%%@*}; \
245248
ARG GOMODJAIL_VERSION
246249
COPY --from=build-gomodjail /out/${TARGETARCH:-amd64}/* /out/bin/
247250
RUN echo "- gomodjail: ${GOMODJAIL_VERSION}" >> /out/share/doc/nerdctl-full/README.md
251+
ARG CONTAINERIZED_SYSTEMD_VERSION
252+
RUN --mount=type=secret,id=github_token,env=GITHUB_TOKEN \
253+
http::helper github::file AkihiroSuda/containerized-systemd docker-entrypoint.sh "${CONTAINERIZED_SYSTEMD_VERSION}" > /docker-entrypoint.sh && \
254+
chmod +x /docker-entrypoint.sh
248255

249256
RUN echo "" >> /out/share/doc/nerdctl-full/README.md && \
250257
echo "## License" >> /out/share/doc/nerdctl-full/README.md && \
@@ -281,9 +288,7 @@ RUN apt-get update -qq && apt-get install -qq -y --no-install-recommends \
281288
iproute2 iptables \
282289
dbus dbus-user-session systemd systemd-sysv \
283290
fuse3
284-
ARG CONTAINERIZED_SYSTEMD_VERSION
285-
RUN curl -o /docker-entrypoint.sh -fsSL --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/${CONTAINERIZED_SYSTEMD_VERSION}/docker-entrypoint.sh && \
286-
chmod +x /docker-entrypoint.sh
291+
COPY --from=build-full /docker-entrypoint.sh /docker-entrypoint.sh
287292
COPY --from=out-full / /usr/local/
288293
RUN perl -pi -e 's/multi-user.target/docker-entrypoint.target/g' /usr/local/lib/systemd/system/*.service && \
289294
systemctl enable containerd buildkit stargz-snapshotter && \

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ TAR_OWNER0_FLAGS=--owner=0 --group=0
253253
TAR_FLATTEN_FLAGS=--transform 's/.*\///g'
254254

255255
define make_artifact_full_linux
256-
$(DOCKER) build --output type=tar,dest=$(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar --target out-full --platform $(1) --build-arg GO_VERSION -f $(MAKEFILE_DIR)/Dockerfile $(MAKEFILE_DIR)
256+
$(DOCKER) build --secret id=github_token,env=GITHUB_TOKEN --output type=tar,dest=$(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar --target out-full --platform $(1) --build-arg GO_VERSION -f $(MAKEFILE_DIR)/Dockerfile $(MAKEFILE_DIR)
257257
gzip -9 $(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar
258258
endef
259259

cmd/nerdctl/container/container_create.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ func createOptions(cmd *cobra.Command) (types.ContainerCreateOptions, error) {
371371
// #endregion
372372

373373
// #region for metadata flags
374-
opt.NameChanged = cmd.Flags().Changed("name")
375374
opt.Name, err = cmd.Flags().GetString("name")
376375
if err != nil {
377376
return opt, err

cmd/nerdctl/image/image_convert.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ func convertCommand() *cobra.Command {
8989
cmd.Flags().String("overlaybd-dbstr", "", "Database config string for overlaybd")
9090
// #endregion
9191

92+
// #region soci flags
93+
cmd.Flags().Bool("soci", false, "Convert image to SOCI Index V2 format.")
94+
cmd.Flags().Int64("soci-min-layer-size", -1, "The minimum size of layers that will be converted to SOCI Index V2 format")
95+
cmd.Flags().Int64("soci-span-size", -1, "The size of SOCI spans")
96+
// #endregion
97+
9298
// #region generic flags
9399
cmd.Flags().Bool("uncompress", false, "Convert tar.gz layers to uncompressed tar layers")
94100
cmd.Flags().Bool("oci", false, "Convert Docker media types to OCI media types")
@@ -213,6 +219,21 @@ func convertOptions(cmd *cobra.Command) (types.ImageConvertOptions, error) {
213219
}
214220
// #endregion
215221

222+
// #region soci flags
223+
soci, err := cmd.Flags().GetBool("soci")
224+
if err != nil {
225+
return types.ImageConvertOptions{}, err
226+
}
227+
sociMinLayerSize, err := cmd.Flags().GetInt64("soci-min-layer-size")
228+
if err != nil {
229+
return types.ImageConvertOptions{}, err
230+
}
231+
sociSpanSize, err := cmd.Flags().GetInt64("soci-span-size")
232+
if err != nil {
233+
return types.ImageConvertOptions{}, err
234+
}
235+
// #endregion
236+
216237
// #region generic flags
217238
uncompress, err := cmd.Flags().GetBool("uncompress")
218239
if err != nil {
@@ -268,6 +289,13 @@ func convertOptions(cmd *cobra.Command) (types.ImageConvertOptions, error) {
268289
OverlayFsType: overlaybdFsType,
269290
OverlaydbDBStr: overlaybdDbstr,
270291
// #endregion
292+
// #region soci flags
293+
Soci: soci,
294+
SociOptions: types.SociOptions{
295+
SpanSize: sociSpanSize,
296+
MinLayerSize: sociMinLayerSize,
297+
},
298+
// #endregion
271299
// #region generic flags
272300
Uncompress: uncompress,
273301
Oci: oci,

cmd/nerdctl/image/image_convert_linux_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ func TestImageConvert(t *testing.T) {
8888
},
8989
Expected: test.Expects(0, nil, nil),
9090
},
91+
{
92+
Description: "soci",
93+
Require: require.All(
94+
require.Not(nerdtest.Docker),
95+
nerdtest.Soci,
96+
nerdtest.SociVersion("0.10.0"),
97+
),
98+
Cleanup: func(data test.Data, helpers test.Helpers) {
99+
helpers.Anyhow("rmi", "-f", data.Identifier("converted-image"))
100+
},
101+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
102+
return helpers.Command("image", "convert", "--soci",
103+
"--soci-span-size", "2097152",
104+
"--soci-min-layer-size", "20971520",
105+
testutil.CommonImage, data.Identifier("converted-image"))
106+
},
107+
Expected: test.Expects(0, nil, nil),
108+
},
91109
},
92110
}
93111

docs/command-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,11 @@ Flags:
960960
- `--oci` : convert Docker media types to OCI media types
961961
- `--platform=<PLATFORM>` : convert content for a specific platform
962962
- `--all-platforms` : convert content for all platforms (default: false)
963+
- `--soci`: generate SOCI v2 Indices to oci images.
964+
*[**Note**: content is converted for all platforms by default when using this flag, use the `--platorm` flag to limit this behavior]*
965+
- `--soci-min-layer-size` : Span size in bytes that soci index uses to segment layer data. Default is 4 MiB.
966+
- `--soci-min-layer-size`: Minimum layer size in bytes to build zTOC for. Smaller layers won't have zTOC and not lazy pulled. Default is 10 MiB.
967+
963968

964969
### :nerd_face: nerdctl image encrypt
965970

docs/soci.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,18 @@ For images that already have SOCI indices, see https://gallery.ecr.aws/soci-work
4545
nerdctl push --snapshotter=soci --soci-span-size=2097152 --soci-min-layer-size=20971520 public.ecr.aws/my-registry/my-repo:latest
4646
```
4747
--soci-span-size and --soci-min-layer-size are two properties to customize the SOCI index. See [Command Reference](https://github.com/containerd/nerdctl/blob/377b2077bb616194a8ef1e19ccde32aa1ffd6c84/docs/command-reference.md?plain=1#L773) for further details.
48+
49+
50+
## Enable SOCI for `nerdctl image convert`
51+
52+
| :zap: Requirement | nerdctl >= 2.2.0 |
53+
| ----------------- | ---------------- |
54+
55+
| :zap: Requirement | soci-snapshotter >= 0.10.0 |
56+
| ----------------- | ---------------- |
57+
58+
- Convert an image to generate SOCI Index artifacts v2. Running the `nerdctl image convert` with the `--soci` flag and a `srcImg` and `dstImg`, `nerdctl` will create the SOCI v2 indices and the new image will be present in the `dstImg` address.
59+
```console
60+
nerdctl image convert --soci --soci-span-size=2097152 --soci-min-layer-size=20971520 public.ecr.aws/my-registry/my-repo:latest public.ecr.aws/my-registry/my-repo:soci
61+
```
62+
--soci-span-size and --soci-min-layer-size are two properties to customize the SOCI index. See [Command Reference](https://github.com/containerd/nerdctl/blob/377b2077bb616194a8ef1e19ccde32aa1ffd6c84/docs/command-reference.md?plain=1#L773) for further details.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/Masterminds/semver/v3 v3.3.1
88
github.com/Microsoft/go-winio v0.6.2
99
github.com/Microsoft/hcsshim v0.13.0
10-
github.com/compose-spec/compose-go/v2 v2.6.3 //gomodjail:unconfined
10+
github.com/compose-spec/compose-go/v2 v2.6.4 //gomodjail:unconfined
1111
github.com/containerd/accelerated-container-image v1.3.0
1212
github.com/containerd/cgroups/v3 v3.0.5 //gomodjail:unconfined
1313
github.com/containerd/console v1.0.5 //gomodjail:unconfined

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ github.com/cilium/ebpf v0.16.0 h1:+BiEnHL6Z7lXnlGUsXQPPAE7+kenAd4ES8MQ5min0Ok=
1919
github.com/cilium/ebpf v0.16.0/go.mod h1:L7u2Blt2jMM/vLAVgjxluxtBKlz3/GWjB0dMOEngfwE=
2020
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
2121
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
22-
github.com/compose-spec/compose-go/v2 v2.6.3 h1:zfW1Qp605ESySyth/zR+6yLr55XE0AiOAUlZLHKMoW0=
23-
github.com/compose-spec/compose-go/v2 v2.6.3/go.mod h1:vPlkN0i+0LjLf9rv52lodNMUTJF5YHVfHVGLLIP67NA=
22+
github.com/compose-spec/compose-go/v2 v2.6.4 h1:Gjv6x8eAhqwwWvoXIo0oZ4bDQBh0OMwdU7LUL9PDLiM=
23+
github.com/compose-spec/compose-go/v2 v2.6.4/go.mod h1:vPlkN0i+0LjLf9rv52lodNMUTJF5YHVfHVGLLIP67NA=
2424
github.com/containerd/accelerated-container-image v1.3.0 h1:sFbTgSuMboeKHa9f7MY11hWF1XxVWjFoiTsXYtOtvdU=
2525
github.com/containerd/accelerated-container-image v1.3.0/go.mod h1:EvKVWor6ZQNUyYp0MZm5hw4k21ropuz7EegM+m/Jb/Q=
2626
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=

hack/scripts/lib.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ github::settoken(){
226226
}
227227

228228
github::request(){
229-
local endpoint="$1"
229+
local accept="$1"
230+
local endpoint="$2"
230231
local args=(
231-
"Accept: application/vnd.github+json"
232+
"Accept: $accept"
232233
"X-GitHub-Api-Version: 2022-11-28"
233234
)
234235

@@ -237,21 +238,30 @@ github::request(){
237238
http::get /dev/stdout https://api.github.com/"$endpoint" "${args[@]}"
238239
}
239240

241+
github::file(){
242+
local repo="$1"
243+
local path="$2"
244+
local ref="${3:-main}"
245+
github::request "application/vnd.github.v3.raw" "repos/$repo/contents/$path?ref=$ref"
246+
}
247+
240248
github::tags::latest(){
241249
local repo="$1"
242-
github::request "repos/$repo/tags" | jq -rc .[0].name
250+
github::request "application/vnd.github+json" "repos/$repo/tags" | jq -rc .[0].name
243251
}
244252

245253
github::releases(){
246254
local repo="$1"
247-
github::request "repos/$repo/releases" |
255+
github::request "application/vnd.github+json" "repos/$repo/releases" |
248256
jq -rc .[]
249257
}
250258

251259
github::releases::latest(){
252260
local repo="$1"
253-
github::request "repos/$repo/releases/latest" | jq -rc .
261+
github::request "application/vnd.github+json" "repos/$repo/releases/latest" | jq -rc .
254262
}
255263

256264
log::init
257265
host::require jq tar curl shasum
266+
267+
[[ "${1:-}" != "github"* ]] || "$@"

pkg/api/types/container_types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ type ContainerCreateOptions struct {
237237
// #endregion
238238

239239
// #region for metadata flags
240-
// NameChanged specifies whether the name has been changed
241-
NameChanged bool
242240
// Name assign a name to the container
243241
Name string
244242
// Label set meta data on a container

pkg/api/types/image_types.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package types
1919
import (
2020
"io"
2121

22-
"github.com/opencontainers/image-spec/specs-go/v1"
22+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2323
)
2424

2525
// ImageListOptions specifies options for `nerdctl image list`.
@@ -124,6 +124,12 @@ type ImageConvertOptions struct {
124124
OverlaydbDBStr string
125125
// #endregion
126126

127+
// #region soci flags
128+
// Soci convert image to SOCI format.eiifc
129+
Soci bool
130+
// SociOptions contains SOCI-specific options
131+
SociOptions SociOptions
132+
// #endregion
127133
}
128134

129135
// ImageCryptOptions specifies options for `nerdctl image encrypt` and `nerdctl image decrypt`.
@@ -200,7 +206,7 @@ type ImagePullOptions struct {
200206
// If nil, it will unpack automatically if only 1 platform is specified.
201207
Unpack *bool
202208
// Content for specific platforms. Empty if `--all-platforms` is true
203-
OCISpecPlatform []v1.Platform
209+
OCISpecPlatform []ocispec.Platform
204210
// Pull mode
205211
Mode string
206212
// Suppress verbose output

0 commit comments

Comments
 (0)