Add a mode to save to a tarball instead of pushing. (#178)
This commit is contained in:
parent
f8aa88b119
commit
347d835781
|
|
@ -39,6 +39,7 @@ var (
|
|||
logLevel string
|
||||
force bool
|
||||
buildArgs buildArg
|
||||
tarPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -52,6 +53,7 @@ func init() {
|
|||
RootCmd.PersistentFlags().BoolVarP(&dockerInsecureSkipTLSVerify, "insecure-skip-tls-verify", "", false, "Push to insecure registry ignoring TLS verify")
|
||||
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic")
|
||||
RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container")
|
||||
RootCmd.PersistentFlags().StringVarP(&tarPath, "tarPath", "", "", "Path to save the image in as a tarball instead of pushing")
|
||||
}
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
|
|
@ -82,7 +84,7 @@ var RootCmd = &cobra.Command{
|
|||
logrus.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := executor.DoPush(ref, image, destination); err != nil {
|
||||
if err := executor.DoPush(ref, image, destination, tarPath); err != nil {
|
||||
logrus.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ package executor
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/snapshot"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/snapshot"
|
||||
|
||||
"github.com/google/go-containerregistry/v1/empty"
|
||||
|
||||
"github.com/google/go-containerregistry/v1/tarball"
|
||||
|
|
@ -36,13 +37,14 @@ import (
|
|||
"github.com/google/go-containerregistry/v1/mutate"
|
||||
"github.com/google/go-containerregistry/v1/remote"
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/commands"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||
"github.com/docker/docker/builder/dockerfile/instructions"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func DoBuild(dockerfilePath, srcContext, snapshotMode string, args []string) (name.Reference, v1.Image, error) {
|
||||
|
|
@ -168,12 +170,17 @@ func DoBuild(dockerfilePath, srcContext, snapshotMode string, args []string) (na
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
func DoPush(ref name.Reference, image v1.Image, destination string) error {
|
||||
func DoPush(ref name.Reference, image v1.Image, destination, tarPath string) error {
|
||||
// Push the image
|
||||
destRef, err := name.ParseReference(destination, name.WeakValidation)
|
||||
destRef, err := name.NewTag(destination, name.WeakValidation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if tarPath != "" {
|
||||
return tarball.WriteToFile(tarPath, destRef, image, nil)
|
||||
}
|
||||
|
||||
wo := remote.WriteOptions{}
|
||||
if ref != nil {
|
||||
wo.MountPaths = []name.Repository{ref.Context()}
|
||||
|
|
|
|||
Loading…
Reference in New Issue