Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cross #9189

Closed
wants to merge 14 commits into from
3 changes: 2 additions & 1 deletion .github/workflows/integration-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
ko_version: [0.4.0]
kompose_version: [1.21.0]
kpt_version: [1.0.0-beta.24]
minikube_version: [1.30.1]
minikube_version: [1.32.0]
gcloud_sdk_version: [410.0.0]
container_structure_tests_version: [1.8.0]
integration_test_partitions: [0, 1, 2, 3]
Expand Down Expand Up @@ -118,6 +118,7 @@ jobs:
curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v${{ matrix.minikube_version }}/minikube-linux-amd64
sudo install minikube /usr/local/bin/minikube
minikube start --profile=minikube --driver=docker
minikube ssh "docker run --privileged --rm tonistiigi/binfmt --install all"

- name: Make and install Skaffold binary from current PR
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }} # non docs files were changed, skaffold build needed
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ integration-in-k3d: skaffold-builder

.PHONY: integration-in-docker
integration-in-docker: skaffold-builder-ci
docker run --rm \
@ ./upgrade-docker.sh
docker run --rm --privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(HOME)/.config/gcloud:/root/.config/gcloud \
-v $(GOOGLE_APPLICATION_CREDENTIALS):$(GOOGLE_APPLICATION_CREDENTIALS) \
Expand Down
2 changes: 1 addition & 1 deletion deploy/skaffold/Dockerfile.deps
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ RUN apt-get update && \
git python unzip && \
rm -rf /var/lib/apt/lists/*

COPY --from=docker:23.0.1 /usr/local/bin/docker /usr/local/bin/
COPY --from=docker:24.0.7 /usr/local/bin/docker /usr/local/bin/
# From Docker Engine version 23.0.0, Buildx is distributed in a separate package: docker-buildx-plugin. In earlier versions, Buildx was included in the docker-ce-cli package
COPY --from=docker/buildx-bin:0.10.4 /buildx /usr/libexec/docker/cli-plugins/docker-buildx
COPY --from=download-kubectl kubectl /usr/local/bin/
Expand Down
19 changes: 8 additions & 11 deletions pkg/skaffold/build/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
if err := b.pullCacheFromImages(ctx, out, a.ArtifactType.DockerArtifact, pl); err != nil {
return "", cacheFromPullErr(err, a.ImageName)
}
opts := docker.BuildOptions{Tag: tag, Mode: b.cfg.Mode(), ExtraBuildArgs: docker.ResolveDependencyImages(a.Dependencies, b.artifacts, true)}
opts := docker.BuildOptions{Tag: tag, Mode: b.cfg.Mode(), ExtraBuildArgs: docker.ResolveDependencyImages(a.Dependencies, b.artifacts, true), Platform: pl.String()}

var imageID string

// ignore useCLI boolean if buildkit is enabled since buildkit is only implemented for docker CLI at the moment in skaffold.
// we might consider a different approach in the future.
// use CLI for cross-platform builds
if b.useCLI || (b.useBuildKit != nil && *b.useBuildKit) || len(a.DockerArtifact.CliFlags) > 0 || matcher.IsCrossPlatform() {
imageID, err = b.dockerCLIBuild(ctx, output.GetUnderlyingWriter(out), a.ImageName, a.Workspace, dockerfile, a.ArtifactType.DockerArtifact, opts, pl)
if b.useCLI || (b.useBuildKit != nil && *b.useBuildKit) || len(a.DockerArtifact.CliFlags) > 0 {
imageID, err = b.dockerCLIBuild(ctx, output.GetUnderlyingWriter(out), a.ImageName, a.Workspace, dockerfile, a.ArtifactType.DockerArtifact, opts)
} else {
imageID, err = b.localDocker.Build(ctx, out, a.Workspace, a.ImageName, a.ArtifactType.DockerArtifact, opts)
}
Expand All @@ -91,7 +88,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
return imageID, nil
}

func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string, workspace string, dockerfilePath string, a *latest.DockerArtifact, opts docker.BuildOptions, pl v1.Platform) (string, error) {
func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string, workspace string, dockerfilePath string, a *latest.DockerArtifact, opts docker.BuildOptions) (string, error) {
args := []string{"build", workspace, "--file", dockerfilePath, "-t", opts.Tag}
imgRef, err := docker.ParseReference(opts.Tag)
if err != nil {
Expand All @@ -116,8 +113,8 @@ func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string
args = append(args, "--force-rm")
}

if pl.String() != "" {
args = append(args, "--platform", pl.String())
if opts.Platform != "" {
args = append(args, "--platform", opts.Platform)
}

cmd := exec.CommandContext(ctx, "docker", args...)
Expand All @@ -128,8 +125,8 @@ func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string
} else {
cmd.Env = append(cmd.Env, "DOCKER_BUILDKIT=0")
}
} else if pl.String() != "" { // cross-platform builds require buildkit
log.Entry(ctx).Debugf("setting DOCKER_BUILDKIT=1 for docker build for artifact %q since it targets platform %q", name, pl.String())
} else if opts.Platform != "" { // cross-platform builds require buildkit
log.Entry(ctx).Debugf("setting DOCKER_BUILDKIT=1 for docker build for artifact %q since it targets platform %q", name, opts.Platform)
cmd.Env = append(cmd.Env, "DOCKER_BUILDKIT=1")
}
cmd.Stdout = out
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type BuildOptions struct {
Tag string
Mode config.RunMode
ExtraBuildArgs map[string]*string
Platform string
}

type localDaemon struct {
Expand Down Expand Up @@ -365,6 +366,7 @@ func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string
ExtraHosts: a.AddHost,
NoCache: a.NoCache,
PullParent: a.PullParent,
Platform: opts.Platform,
})
if err != nil {
return "", fmt.Errorf("docker build: %w", err)
Expand Down
30 changes: 30 additions & 0 deletions upgrade-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2023 The Skaffold Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Loading