Skip to content

Commit 1a4160e

Browse files
authored
Merge pull request #12081 from spowelljr/buildkitSocket
buildkit socket: Add systemd unit
2 parents 4c6f03c + eef6130 commit 1a4160e

File tree

15 files changed

+76
-34
lines changed

15 files changed

+76
-34
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ KUBERNETES_VERSION ?= $(shell egrep "DefaultKubernetesVersion =" pkg/minikube/co
2323
KIC_VERSION ?= $(shell egrep "Version =" pkg/drivers/kic/types.go | cut -d \" -f2)
2424

2525
# Default to .0 for higher cache hit rates, as build increments typically don't require new ISO versions
26-
ISO_VERSION ?= v1.23.1
26+
ISO_VERSION ?= v1.23.1-1633115168-12081
2727
# Dashes are valid in semver, but not Linux packaging. Use ~ to delimit alpha/beta
2828
DEB_VERSION ?= $(subst -,~,$(RAW_VERSION))
2929
DEB_REVISION ?= 0
@@ -286,7 +286,7 @@ minikube_iso: deploy/iso/minikube-iso/board/coreos/minikube/rootfs-overlay/usr/b
286286
if [ ! -d $(BUILD_DIR)/buildroot ]; then \
287287
mkdir -p $(BUILD_DIR); \
288288
git clone --depth=1 --branch=$(BUILDROOT_BRANCH) https://github.com/buildroot/buildroot $(BUILD_DIR)/buildroot; \
289-
cp $(PWD)/deploy/iso/minikube-iso/go.hash $(BUILD_DIR)/buildroot/package/go/go.hash; \
289+
cp deploy/iso/minikube-iso/go.hash $(BUILD_DIR)/buildroot/package/go/go.hash; \
290290
fi;
291291
$(MAKE) BR2_EXTERNAL=../../deploy/iso/minikube-iso minikube_defconfig -C $(BUILD_DIR)/buildroot $(BUILDROOT_OPTIONS)
292292
$(MAKE) -C $(BUILD_DIR)/buildroot $(BUILDROOT_OPTIONS) host-python
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
docker 1000 docker 1000 =tcuser /home/docker /bin/bash wheel,vboxsf,podman -
1+
docker 1000 docker 1000 =tcuser /home/docker /bin/bash wheel,vboxsf,podman,buildkit -
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable buildkit.service

deploy/iso/minikube-iso/package/buildkit-bin/buildkit-bin.mk

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ BUILDKIT_BIN_SOURCE = buildkit-$(BUILDKIT_BIN_VERSION).linux-amd64.tar.gz
1212
# https://github.com/opencontainers/runc.git
1313
BUILDKIT_RUNC_VERSION = 12644e614e25b05da6fd08a38ffa0cfe1903fdec
1414

15+
define BUILDKIT_BIN_USERS
16+
- -1 buildkit -1 - - - - -
17+
endef
18+
1519
define BUILDKIT_BIN_INSTALL_TARGET_CMDS
1620
$(INSTALL) -D -m 0755 \
1721
$(@D)/buildctl \
@@ -25,6 +29,24 @@ define BUILDKIT_BIN_INSTALL_TARGET_CMDS
2529
$(INSTALL) -D -m 0755 \
2630
$(@D)/buildkitd \
2731
$(TARGET_DIR)/usr/sbin
32+
$(INSTALL) -D -m 644 \
33+
$(BUILDKIT_BIN_PKGDIR)/buildkit.conf \
34+
$(TARGET_DIR)/usr/lib/tmpfiles.d/buildkit.conf
35+
$(INSTALL) -D -m 644 \
36+
$(BUILDKIT_BIN_PKGDIR)/buildkitd.toml \
37+
$(TARGET_DIR)/etc/buildkit/buildkitd.toml
38+
endef
39+
40+
define BUILDKIT_BIN_INSTALL_INIT_SYSTEMD
41+
$(INSTALL) -D -m 644 \
42+
$(BUILDKIT_BIN_PKGDIR)/buildkit.service \
43+
$(TARGET_DIR)/usr/lib/systemd/system/buildkit.service
44+
$(INSTALL) -D -m 644 \
45+
$(BUILDKIT_BIN_PKGDIR)/buildkit.socket \
46+
$(TARGET_DIR)/usr/lib/systemd/system/buildkit.socket
47+
$(INSTALL) -D -m 644 \
48+
$(BUILDKIT_BIN_PKGDIR)/51-buildkit.preset \
49+
$(TARGET_DIR)/usr/lib/systemd/system-preset/51-buildkit.preset
2850
endef
2951

3052
$(eval $(generic-package))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d /run/buildkit 0770 root buildkit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=BuildKit
3+
Requires=buildkit.socket
4+
After=buildkit.socket
5+
Documentation=https://github.com/moby/buildkit
6+
7+
[Service]
8+
ExecStart=/usr/sbin/buildkitd --addr fd://
9+
10+
[Install]
11+
WantedBy=multi-user.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=BuildKit
3+
Documentation=https://github.com/moby/buildkit
4+
5+
[Socket]
6+
ListenStream=%t/buildkit/buildkitd.sock
7+
SocketMode=0660
8+
SocketUser=root
9+
SocketGroup=buildkit
10+
11+
[Install]
12+
WantedBy=sockets.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[worker.oci]
2+
enabled = false
3+
[worker.containerd]
4+
enabled = true
5+
namespace = "k8s.io"

deploy/iso/minikube-iso/package/crio-bin/crio-bin.hash

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ sha256 74a4e916acddc6cf47ab5752bdebb6732ce2c028505ef57b7edc21d2da9039b6 v1.18.4.
2121
sha256 fc8a8e61375e3ce30563eeb0fd6534c4f48fc20300a72e6ff51cc99cb2703516 v1.19.0.tar.gz
2222
sha256 6165c5b8212ea03be2a465403177318bfe25a54c3e8d66d720344643913a0223 v1.19.1.tar.gz
2323
sha256 76fd7543bc92d4364a11060f43a5131893a76c6e6e9d6de3a6bb6292c110b631 v1.20.0.tar.gz
24-
sha256 1c01d4a76cdcfe3ac24147eb1d5f6ebd782bd98fb0ac0c19b79bd5a6560b1481 v1.20.2.tar.gz
24+
sha256 36d9f4cf4966342e2d4099e44d8156c55c6a10745c67ce4f856aa9f6dcc2d9ba v1.20.2.tar.gz
2525
sha256 bc53ea8977e252bd9812974c33ff654ee22076598e901464468c5c105a5ef773 v1.22.0.tar.gz

deploy/kicbase/Dockerfile

+9-1
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,21 @@ COPY deploy/kicbase/containerd-fuse-overlayfs.service /etc/systemd/system/contai
142142
# install buildkit
143143
RUN export ARCH=$(dpkg --print-architecture | sed 's/ppc64el/ppc64le/' | sed 's/armhf/arm-v7/') \
144144
&& echo "Installing buildkit ..." \
145+
&& addgroup --system buildkit \
145146
&& export BUILDKIT_BASE_URL="https://github.com/moby/buildkit/releases/download/${BUILDKIT_VERSION}" \
146147
&& curl -sSL --retry 5 --output /tmp/buildkit.tgz "${BUILDKIT_BASE_URL}/buildkit-${BUILDKIT_VERSION}.linux-${ARCH}.tar.gz" \
147148
&& tar -C /usr/local -xzvf /tmp/buildkit.tgz \
148149
&& rm -rf /tmp/buildkit.tgz \
150+
&& mkdir -p /usr/local/lib/systemd/system \
151+
&& curl -L --retry 5 --output /usr/local/lib/systemd/system/buildkit.service "https://raw.githubusercontent.com/moby/buildkit/${BUILDKIT_VERSION}/examples/systemd/buildkit.service" \
152+
&& curl -L --retry 5 --output /usr/local/lib/systemd/system/buildkit.socket "https://raw.githubusercontent.com/moby/buildkit/${BUILDKIT_VERSION}/examples/systemd/buildkit.socket" \
153+
&& mkdir -p /etc/buildkit \
154+
&& echo "[worker.oci]\n enabled = false\n[worker.containerd]\n enabled = true\n namespace = \"k8s.io\"" > /etc/buildkit/buildkitd.toml \
149155
&& chmod 755 /usr/local/bin/buildctl \
150156
&& chmod 755 /usr/local/bin/buildkit-runc \
151157
&& chmod 755 /usr/local/bin/buildkit-qemu-* \
152-
&& chmod 755 /usr/local/bin/buildkitd
158+
&& chmod 755 /usr/local/bin/buildkitd \
159+
&& systemctl enable buildkit.socket
153160

154161
# Install cri-o/podman dependencies:
155162
RUN sh -c "echo 'deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list" && \
@@ -210,6 +217,7 @@ EXPOSE 22
210217
RUN adduser --ingroup docker --disabled-password --gecos '' docker
211218
RUN adduser docker sudo
212219
RUN adduser docker podman
220+
RUN adduser docker buildkit
213221
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
214222
USER docker
215223
RUN mkdir /home/docker/.ssh

pkg/drivers/kic/types.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import (
2424

2525
const (
2626
// Version is the current version of kic
27-
Version = "v0.0.27"
27+
Version = "v0.0.27-1633027942-12081"
2828
// SHA of the kic base image
29-
baseImageSHA = "89b4738ee74ba28684676e176752277f0db46f57d27f0e08c3feec89311e22de"
29+
baseImageSHA = "4780f1897569d2bf77aafb3d133a08d42b4fe61127f06fcfc90c2c5d902d893c"
3030
// The name of the GCR kicbase repository
31-
gcrRepo = "gcr.io/k8s-minikube/kicbase"
31+
gcrRepo = "gcr.io/k8s-minikube/kicbase-builds"
3232
// The name of the Dockerhub kicbase repository
33-
dockerhubRepo = "docker.io/kicbase/stable"
33+
dockerhubRepo = "docker.io/kicbase/build"
3434
)
3535

3636
var (

pkg/minikube/cruntime/containerd.go

-22
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,6 @@ func downloadRemote(cr CommandRunner, src string) (string, error) {
393393

394394
// BuildImage builds an image into this runtime
395395
func (r *Containerd) BuildImage(src string, file string, tag string, push bool, env []string, opts []string) error {
396-
if err := r.initBuildkitDaemon(); err != nil {
397-
return fmt.Errorf("failed to init buildkit daemon: %v", err)
398-
}
399-
400396
// download url if not already present
401397
dir, err := downloadRemote(r.Runner, src)
402398
if err != nil {
@@ -456,24 +452,6 @@ func (r *Containerd) PushImage(name string) error {
456452
}
457453
return nil
458454
}
459-
func (r *Containerd) initBuildkitDaemon() error {
460-
// if daemon is already running, do nothing
461-
cmd := exec.Command("pgrep", "buildkitd")
462-
if _, err := r.Runner.RunCmd(cmd); err == nil {
463-
return nil
464-
}
465-
466-
// otherwise, start daemon
467-
cmd = exec.Command("/bin/bash", "-c", "sudo -b buildkitd --oci-worker false --containerd-worker true --containerd-worker-namespace k8s.io &> /dev/null")
468-
if _, err := r.Runner.RunCmd(cmd); err != nil {
469-
return fmt.Errorf("failed to start buildkit daemon: %v", err)
470-
}
471-
472-
// give the daemon time to finish starting up or image build will fail
473-
time.Sleep(1 * time.Second)
474-
475-
return nil
476-
}
477455

478456
// CGroupDriver returns cgroup driver ("cgroupfs" or "systemd")
479457
func (r *Containerd) CGroupDriver() (string, error) {

pkg/minikube/download/iso.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const fileScheme = "file"
4040
// DefaultISOURLs returns a list of ISO URL's to consult by default, in priority order
4141
func DefaultISOURLs() []string {
4242
v := version.GetISOVersion()
43-
isoBucket := "minikube/iso"
43+
isoBucket := "minikube-builds/iso/12081"
4444
return []string{
4545
fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", isoBucket, v),
4646
fmt.Sprintf("https://github.com/kubernetes/minikube/releases/download/%s/minikube-%s.iso", v, v),

site/content/en/docs/commands/start.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ minikube start [flags]
2626
--apiserver-names strings A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine
2727
--apiserver-port int The apiserver listening port (default 8443)
2828
--auto-update-drivers If set, automatically updates drivers to the latest version. Defaults to true. (default true)
29-
--base-image string The base image to use for docker/podman drivers. Intended for local development. (default "gcr.io/k8s-minikube/kicbase:v0.0.27@sha256:89b4738ee74ba28684676e176752277f0db46f57d27f0e08c3feec89311e22de")
29+
--base-image string The base image to use for docker/podman drivers. Intended for local development. (default "gcr.io/k8s-minikube/kicbase-builds:v0.0.27-1633027942-12081@sha256:4780f1897569d2bf77aafb3d133a08d42b4fe61127f06fcfc90c2c5d902d893c")
3030
--cache-images If true, cache docker images for the current bootstrapper and load them into the machine. Always false with --driver=none. (default true)
3131
--cert-expiration duration Duration until minikube certificate expiration, defaults to three years (26280h). (default 26280h0m0s)
3232
--cni string CNI plug-in to use. Valid options: auto, bridge, calico, cilium, flannel, kindnet, or path to a CNI manifest (default: auto)
@@ -66,7 +66,7 @@ minikube start [flags]
6666
--insecure-registry strings Insecure Docker registries to pass to the Docker daemon. The default service CIDR range will automatically be added.
6767
--install-addons If set, install addons. Defaults to true. (default true)
6868
--interactive Allow user prompts for more information (default true)
69-
--iso-url strings Locations to fetch the minikube ISO from. (default [https://storage.googleapis.com/minikube/iso/minikube-v1.23.1.iso,https://github.com/kubernetes/minikube/releases/download/v1.23.1/minikube-v1.23.1.iso,https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.23.1.iso])
69+
--iso-url strings Locations to fetch the minikube ISO from. (default [https://storage.googleapis.com/minikube-builds/iso/12081/minikube-v1.23.1-1633115168-12081.iso,https://github.com/kubernetes/minikube/releases/download/v1.23.1-1633115168-12081/minikube-v1.23.1-1633115168-12081.iso,https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.23.1-1633115168-12081.iso])
7070
--keep-context This will keep the existing kubectl context and will create a minikube context.
7171
--kubernetes-version string The Kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for v1.22.2, 'latest' for v1.22.3-rc.0). Defaults to 'stable'.
7272
--kvm-gpu Enable experimental NVIDIA GPU support in minikube

test/integration/functional_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ func validateImageCommands(ctx context.Context, t *testing.T, profile string) {
255255
t.Run("ImageBuild", func(t *testing.T) {
256256
MaybeParallel(t)
257257

258+
if _, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "pgrep", "buildkitd")); err == nil {
259+
t.Errorf("buildkitd process is running, should not be running until `minikube image build` is ran")
260+
}
261+
258262
newImage := fmt.Sprintf("localhost/my-image:%s", profile)
259263

260264
// try to build the new image with minikube

0 commit comments

Comments
 (0)