Skip to content

Commit 47cc9eb

Browse files
committed
add model package
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 6e5bcd5 commit 47cc9eb

File tree

16 files changed

+786
-0
lines changed

16 files changed

+786
-0
lines changed

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ area/pkg/docker-engine:
3737
- changed-files:
3838
- any-glob-to-any-file: 'pkg/docker-engine/**'
3939

40+
area/pkg/model:
41+
- changed-files:
42+
- any-glob-to-any-file: 'pkg/model/**'
43+
4044
area/pkg/sbom:
4145
- changed-files:
4246
- any-glob-to-any-file: 'pkg/sbom/**'

.github/workflows/build-model.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: build-model
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
branches:
10+
- 'main'
11+
- 'model/[0-9]+.[0-9]+'
12+
paths:
13+
- '.github/workflows/.build.yml'
14+
- '.github/workflows/build-model.yml'
15+
- 'hack/scripts/**'
16+
- 'pkg/model/**'
17+
- 'docker-bake.hcl'
18+
pull_request:
19+
branches:
20+
- 'main'
21+
- 'model/[0-9]+.[0-9]+'
22+
paths:
23+
- '.github/workflows/.build.yml'
24+
- '.github/workflows/build-model.yml'
25+
- 'hack/scripts/**'
26+
- 'pkg/model/**'
27+
- 'docker-bake.hcl'
28+
29+
jobs:
30+
run:
31+
uses: ./.github/workflows/.build.yml
32+
with:
33+
name: model
34+
secrets: inherit
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: release-model
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
ref:
11+
description: 'Ref (e.g. v0.1.30)'
12+
required: true
13+
type: string
14+
repo:
15+
description: 'Override default repo'
16+
required: false
17+
type: string
18+
release:
19+
description: 'Push image and create release'
20+
required: false
21+
type: boolean
22+
23+
jobs:
24+
release:
25+
uses: ./.github/workflows/.build.yml
26+
with:
27+
name: model
28+
release: ${{ inputs.release }}
29+
push: ${{ inputs.release }}
30+
envs: |
31+
PKG_REPO=${{ inputs.repo }}
32+
PKG_REF=${{ inputs.ref }}
33+
secrets: inherit

docker-bake.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ variable "PKGS" {
4040
"credential-helpers",
4141
"docker-cli",
4242
"docker-engine",
43+
"model",
4344
"sbom",
4445
"scan"
4546
]
@@ -401,6 +402,17 @@ target "_pkg-docker-engine" {
401402
}
402403
}
403404

405+
target "_pkg-model" {
406+
args = {
407+
PKG_NAME = PKG_NAME != null ? PKG_NAME : "docker-model-plugin"
408+
PKG_REPO = PKG_REPO != null ? PKG_REPO : "https://github.com/docker/model-cli.git"
409+
PKG_REF = PKG_REF != null ? PKG_REF : "main"
410+
GO_VERSION = GO_VERSION != null ? GO_VERSION : "1.24.4" # https://github.com/docker/model-cli/blob/main/Dockerfile#L3
411+
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null ? GO_IMAGE_VARIANT : "bookworm"
412+
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null ? PKG_DEB_EPOCH : "5"
413+
}
414+
}
415+
404416
target "_pkg-sbom" {
405417
args = {
406418
PKG_NAME = PKG_NAME != null ? PKG_NAME : "docker-sbom-plugin"
@@ -439,6 +451,8 @@ function "pkgPlatforms" {
439451
docker-cli = ["darwin/amd64", "darwin/arm64", "linux/386", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", "windows/amd64", "windows/arm64"]
440452
# https://github.com/moby/moby/blob/master/docker-bake.hcl#L93-L101
441453
docker-engine = ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/s390x", "windows/amd64", "windows/arm64"]
454+
# https://github.com/docker/model-cli/blob/main/Makefile#L36-L40
455+
model = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "windows/amd64", "windows/arm64"]
442456
# https://github.com/docker/sbom-cli-plugin/blob/main/.goreleaser.yaml#L7-L13
443457
sbom = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "windows/amd64", "windows/arm64"]
444458
# https://github.com/docker/scan-cli-plugin/blob/main/builder.Makefile#L63-L67

pkg/docker-cli/deb/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Architecture: linux-any
1818
Depends: ${shlibs:Depends}
1919
Recommends: docker-buildx-plugin,
2020
docker-compose-plugin
21+
Suggests: docker-model-plugin
2122
Conflicts: docker (<< 1.5~),
2223
docker-engine,
2324
docker.io

pkg/docker-cli/rpm/docker-ce-cli.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Requires: /usr/sbin/groupadd
1818
Recommends: docker-buildx-plugin
1919
Recommends: docker-compose-plugin
2020

21+
Suggests: docker-model-plugin
22+
2123
BuildRequires: gcc
2224
BuildRequires: libtool-ltdl-devel
2325
BuildRequires: make

pkg/model/Dockerfile

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Copyright 2025 Docker Packaging authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
ARG XX_VERSION="1.6.1"
18+
ARG DEBIAN_FRONTEND="noninteractive"
19+
20+
ARG DISTRO_NAME="debian12"
21+
ARG DISTRO_TYPE="deb"
22+
ARG DISTRO_RELEASE="debian"
23+
ARG DISTRO_SUITE="bookworm"
24+
ARG DISTRO_ID="12"
25+
ARG DISTRO_IMAGE="debian:bookworm"
26+
27+
ARG PKG_NAME="docker-model-plugin"
28+
ARG PKG_REPO="https://github.com/docker/model-cli.git"
29+
ARG PKG_REF="main"
30+
31+
ARG GO_IMAGE="golang"
32+
ARG GO_VERSION="1.24.4"
33+
ARG GO_IMAGE_VARIANT="bookworm"
34+
35+
# stage used as named context that mounts hack/scripts
36+
# see pkg target in docker-bake.hcl
37+
FROM scratch AS scripts
38+
39+
# cross compilation helper
40+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
41+
42+
# osxcross contains the MacOSX SDK for xx
43+
FROM dockercore/golang-cross:xx-sdk-extras AS osxsdk
44+
45+
# go base image to retrieve /usr/local/go
46+
FROM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS go
47+
FROM --platform=$BUILDPLATFORM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS gocross
48+
49+
# src
50+
FROM --platform=$BUILDPLATFORM alpine AS src-base
51+
RUN apk add --no-cache bash curl file git zip tar
52+
53+
FROM src-base AS src
54+
WORKDIR /src
55+
ARG PKG_REPO
56+
RUN git init . && git remote add origin "${PKG_REPO}"
57+
ARG PKG_REF
58+
RUN git fetch origin "${PKG_REF}" +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
59+
60+
FROM src-base AS src-tgz
61+
RUN --mount=from=src,source=/src,target=/model \
62+
mkdir /out && tar -C / -zcf /out/model.tgz --exclude .git model
63+
64+
# metadata
65+
FROM src-base AS metadata-builder
66+
ARG PKG_REPO
67+
ARG PKG_REF
68+
ARG NIGHTLY_BUILD
69+
RUN --mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
70+
--mount=type=bind,from=src,source=/src,target=/src <<EOT
71+
set -e
72+
mkdir -p /out
73+
for l in $(gen-ver "/src"); do
74+
export "${l?}"
75+
done
76+
cat > "/out/metadata.env" <<-EOF
77+
REPO=${PKG_REPO%.*}
78+
REF=${PKG_REF}
79+
VERSION=${GENVER_VERSION}
80+
COMMIT=${GENVER_COMMIT}
81+
EOF
82+
EOT
83+
84+
FROM scratch AS metadata
85+
COPY --from=metadata-builder /out /
86+
87+
# deb
88+
FROM ${DISTRO_IMAGE} AS builder-deb
89+
COPY --from=xx / /
90+
ARG DEBIAN_FRONTEND
91+
ENV GOPROXY="https://proxy.golang.org|direct"
92+
ENV GOPATH="/go"
93+
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
94+
ENV GOTOOLCHAIN="local"
95+
ENV GO111MODULE="on"
96+
ENV CGO_ENABLED="0"
97+
ARG DISTRO_NAME
98+
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils bash ca-certificates curl devscripts equivs git
99+
COPY deb /root/package/debian
100+
ARG TARGETPLATFORM
101+
RUN mk-build-deps -t "xx-apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" -i /root/package/debian/control
102+
WORKDIR /root/package
103+
ARG NIGHTLY_BUILD
104+
ARG DISTRO_RELEASE
105+
ARG DISTRO_ID
106+
ARG DISTRO_SUITE
107+
ARG PKG_NAME
108+
ARG PKG_REF
109+
ARG PKG_PACKAGER
110+
ARG PKG_DEB_BUILDFLAGS
111+
ARG PKG_DEB_REVISION
112+
ARG PKG_DEB_EPOCH
113+
ARG SOURCE_DATE_EPOCH
114+
RUN --mount=type=bind,source=scripts/pkg-deb-build.sh,target=/usr/local/bin/pkg-deb-build \
115+
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
116+
--mount=type=bind,from=scripts,source=gen-deb-changelog.sh,target=/usr/local/bin/gen-deb-changelog \
117+
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
118+
--mount=type=bind,from=src,source=/src,target=/root/package/model,rw \
119+
--mount=type=bind,from=go,source=/usr/local/go,target=/usr/local/go \
120+
OUTDIR=/out SRCDIR=./model pkg-deb-build
121+
122+
# rpm
123+
FROM ${DISTRO_IMAGE} AS builder-rpm
124+
COPY --from=xx / /
125+
ENV GOPROXY="https://proxy.golang.org|direct"
126+
ENV GOPATH="/go"
127+
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
128+
ENV GOTOOLCHAIN="local"
129+
ENV GO111MODULE="on"
130+
ENV CGO_ENABLED="0"
131+
ARG DISTRO_NAME
132+
RUN --mount=type=bind,from=scripts,source=rpm-init.sh,target=/usr/local/bin/rpm-init \
133+
rpm-init $DISTRO_NAME
134+
COPY rpm /root/rpmbuild/SPECS
135+
ARG TARGETPLATFORM
136+
RUN --mount=type=bind,from=scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \
137+
rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS
138+
WORKDIR /root/rpmbuild
139+
ARG NIGHTLY_BUILD
140+
ARG DISTRO_RELEASE
141+
ARG DISTRO_ID
142+
ARG DISTRO_SUITE
143+
ARG PKG_NAME
144+
ARG PKG_REF
145+
ARG PKG_PACKAGER
146+
ARG PKG_RPM_BUILDFLAGS
147+
ARG PKG_RPM_RELEASE
148+
ARG SOURCE_DATE_EPOCH
149+
RUN --mount=type=bind,source=scripts/pkg-rpm-build.sh,target=/usr/local/bin/pkg-rpm-build \
150+
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
151+
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
152+
--mount=type=bind,from=src-tgz,source=/out/model.tgz,target=/root/rpmbuild/SOURCES/model.tgz \
153+
--mount=type=bind,from=src,source=/src,target=/usr/local/src/model \
154+
--mount=type=bind,from=go,source=/usr/local/go,target=/usr/local/go \
155+
OUTDIR=/out SRCDIR=/usr/local/src/model pkg-rpm-build
156+
157+
# static
158+
FROM --platform=$BUILDPLATFORM ${DISTRO_IMAGE} AS builder-static-nosdk
159+
COPY --from=xx / /
160+
ARG DEBIAN_FRONTEND
161+
RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates file git zip tar \
162+
dpkg-dev clang lld llvm make pkg-config
163+
ENV GOPROXY="https://proxy.golang.org|direct"
164+
ENV GOPATH="/go"
165+
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
166+
ENV GOTOOLCHAIN="local"
167+
ENV GO111MODULE="on"
168+
ENV CGO_ENABLED="0"
169+
ARG PKG_NAME
170+
ARG PKG_REF
171+
ARG NIGHTLY_BUILD
172+
WORKDIR /build
173+
# download dependencies before "ARG TARGETPLATFORM" otherwise it will be cached
174+
# for each platform and that would take a lot of disk space
175+
RUN --mount=type=bind,from=src,source=/src/go.mod,target=/build/go.mod \
176+
--mount=type=bind,from=src,source=/src/go.sum,target=/build/go.sum,rw \
177+
--mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw \
178+
go mod download -x
179+
ARG TARGETPLATFORM
180+
RUN xx-apt-get install -y gcc libc6-dev
181+
RUN --mount=type=bind,source=scripts/pkg-static-build.sh,target=/usr/local/bin/pkg-static-build \
182+
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
183+
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
184+
--mount=type=bind,from=src,source=/src,target=/usr/local/src/model \
185+
--mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw \
186+
OUTDIR=/out BUILDDIR=/build SRCDIR=/usr/local/src/model pkg-static-build
187+
FROM builder-static-nosdk AS builder-static-linux
188+
FROM builder-static-nosdk AS builder-static-windows
189+
190+
FROM --platform=$BUILDPLATFORM ${DISTRO_IMAGE} AS builder-static-darwin
191+
COPY --from=xx / /
192+
ARG DEBIAN_FRONTEND
193+
RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates file git zip tar \
194+
dpkg-dev clang lld llvm make pkg-config
195+
ENV GOPROXY="https://proxy.golang.org|direct"
196+
ENV GOPATH="/go"
197+
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
198+
ENV GOTOOLCHAIN="local"
199+
ENV GO111MODULE="on"
200+
ENV CGO_ENABLED="0"
201+
ARG PKG_NAME
202+
ARG PKG_REF
203+
ARG NIGHTLY_BUILD
204+
WORKDIR /build
205+
# download dependencies before "ARG TARGETPLATFORM" otherwise it will be cached
206+
# for each platform and that would take a lot of disk space
207+
RUN --mount=type=bind,from=src,source=/src/go.mod,target=/build/go.mod \
208+
--mount=type=bind,from=src,source=/src/go.sum,target=/build/go.sum,rw \
209+
--mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw \
210+
go mod download -x
211+
ARG TARGETPLATFORM
212+
RUN xx-apt-get install -y gcc libc6-dev
213+
RUN --mount=type=bind,source=scripts/pkg-static-build.sh,target=/usr/local/bin/pkg-static-build \
214+
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
215+
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
216+
--mount=type=bind,from=src,source=/src,target=/usr/local/src/model \
217+
--mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw \
218+
--mount=from=osxsdk,target=/xx-sdk,src=/xx-sdk \
219+
OUTDIR=/out BUILDDIR=/build SRCDIR=/usr/local/src/model pkg-static-build
220+
221+
FROM builder-static-$TARGETOS AS builder-static
222+
223+
FROM builder-${DISTRO_TYPE} AS build-pkg
224+
ARG BUILDKIT_SBOM_SCAN_STAGE=true
225+
226+
FROM scratch AS pkg
227+
COPY --from=build-pkg /out /

pkg/model/deb/control

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Source: docker-model-plugin
2+
Section: admin
3+
Priority: optional
4+
Maintainer: Docker <support@docker.com>
5+
Homepage: https://www.docker.com
6+
Vcs-Browser: https://github.com/docker/model-cli
7+
Vcs-Git: git://github.com/docker/model-cli.git
8+
Standards-Version: 3.9.6
9+
Build-Depends: bash,
10+
debhelper-compat (= 12)
11+
12+
Package: docker-model-plugin
13+
Priority: optional
14+
Architecture: linux-any
15+
Enhances: docker-ce-cli
16+
Description: Docker Model Runner plugin for the Docker CLI.
17+
.
18+
This plugin provides the 'docker model' subcommand.
19+
Homepage: https://docs.docker.com/model-runner/

pkg/model/deb/docs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
model/README.md

0 commit comments

Comments
 (0)