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

0 commit comments

Comments
 (0)