Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3398 from hashicorp/b-docker-pull-remote
Browse files Browse the repository at this point in the history
Fix `docker-pull` remote operations build & push
  • Loading branch information
paladin-devops authored Jun 6, 2022
2 parents d0a0af2 + c73d28a commit 0f4fc51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/3398.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
plugin/docker: fix issue with remote operations for `docker-pull` builder
```
35 changes: 26 additions & 9 deletions builtin/docker/pull/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package dockerpull
import (
"context"
"fmt"
"github.com/docker/cli/cli/command/image/build"
"github.com/docker/distribution/reference"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"
wpdocker "github.com/hashicorp/waypoint/builtin/docker"
"github.com/hashicorp/waypoint/internal/assets"
"github.com/hashicorp/waypoint/internal/pkg/epinject/ociregistry"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
empty "google.golang.org/protobuf/types/known/emptypb"
"net"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
)

Expand All @@ -35,9 +35,9 @@ func (b *Builder) pullWithKaniko(
}()

target := &wpdocker.Image{
Image: b.config.Image,
Tag: b.config.Tag,
Location: &wpdocker.Image_Docker{Docker: &empty.Empty{}},
Image: ai.Image,
Tag: ai.Tag,
Location: &wpdocker.Image_Registry{Registry: &wpdocker.Image_RegistryLocation{}},
}

var oci ociregistry.Server
Expand Down Expand Up @@ -79,7 +79,6 @@ func (b *Builder) pullWithKaniko(
// is "index.docker.io".
host = "index.docker.io"
}
log.Trace("auth host", "host", host)

if ai.Insecure {
oci.Upstream = "http://" + host
Expand All @@ -89,6 +88,11 @@ func (b *Builder) pullWithKaniko(

refPath := reference.Path(ref)

err = oci.Negotiate(ref.Name())
if err != nil {
return nil, errors.Wrapf(err, "unable to negotiate with upstream")
}

if !b.config.DisableCEB {
step.Update("Injecting entrypoint...")
// For Kaniko we can use our runtime arch because the image we build
Expand All @@ -103,13 +107,14 @@ func (b *Builder) pullWithKaniko(
if err != nil {
return nil, status.Errorf(codes.Internal, "unable to restore custom entrypoint binary: %s", err)
}
step.Done()

step = sg.Add("Testing registry and uploading entrypoint layer")

err = oci.SetupEntrypointLayer(refPath, data)
if err != nil {
return nil, status.Errorf(codes.Internal, "error setting up entrypoint layer: %s", err)
}
step.Done()
}

// Setting up local registry to which Kaniko will push
Expand All @@ -125,18 +130,29 @@ func (b *Builder) pullWithKaniko(

localRef := fmt.Sprintf("localhost:%d/%s:%s", port, refPath, ai.Tag)

dockerfileBS := []byte(fmt.Sprintf("FROM %s:%s\n", target.Image, target.Tag))
dockerfileBS := []byte(fmt.Sprintf("FROM %s:%s\n", b.config.Image, b.config.Tag))
err = os.WriteFile("Dockerfile", dockerfileBS, 0644)
if err != nil {
return nil, err
}

contextDir, relDockerfile, err := build.GetContextFromLocalDir(".", "Dockerfile")
if err != nil {
return nil, status.Errorf(codes.FailedPrecondition, "unable to create Docker context: %s", err)
}

// Start constructing our arg string for img
args := []string{
"/kaniko/executor",
"-f", filepath.Dir("Dockerfile"),
"--context", "dir://" + contextDir,
"-f", relDockerfile,
"-d", localRef,
}

if ai.Insecure {
args = append(args, "--insecure-registry")
}

log.Debug("executing kaniko", "args", args)
step.Update("Executing Kaniko...")

Expand All @@ -153,6 +169,7 @@ func (b *Builder) pullWithKaniko(
step.Done()

step = sg.Add("Image pull completed.")
step.Status(terminal.StatusOK)
step.Done()

return target, nil
Expand Down

1 comment on commit 0f4fc51

@vercel
Copy link

@vercel vercel bot commented on 0f4fc51 Jun 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

waypoint-ui – ./ui

waypoint-ui-hashicorp.vercel.app
waypoint-ui.vercel.app
waypoint-ui-git-main-hashicorp.vercel.app

Please sign in to comment.