Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/skpr/package/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewCommand() *cobra.Command {
cmd.Flags().BoolVar(&command.Params.NoPush, "no-push", command.Params.NoPush, "Do not push the image to the registry.")
cmd.Flags().BoolVar(&command.PrintManifest, "print-manifest", command.PrintManifest, "Print the manifest to stdout.")
cmd.Flags().StringVar(&command.PackageDir, "dir", ".skpr/package", "The location of the package directory.")
cmd.Flags().StringSliceVar(&command.BuildArgs, "build-arg", []string{}, "Additional build arguments.")
cmd.Flags().BoolVar(&command.Debug, "debug", command.Debug, "Enable debug output.")

return cmd
Expand Down
20 changes: 14 additions & 6 deletions internal/buildpack/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ type Image struct {

// Params used for building the applications.
type Params struct {
Auth docker.AuthConfiguration
Writer io.Writer
Context string
Registry string
NoPush bool
Version string
Auth docker.AuthConfiguration
Writer io.Writer
Context string
Registry string
NoPush bool
Version string
BuildArgs map[string]string
}

// Dockerfiles the docker build files.
Expand Down Expand Up @@ -100,6 +101,13 @@ func (b *Builder) Build(dockerfiles Dockerfiles, params Params) (BuildResponse,
},
}

for k, v := range params.BuildArgs {
args = append(args, docker.BuildArg{
Name: k,
Value: v,
})
}

start := time.Now()

// We build the compile image first, as it is the base image for other images.
Expand Down
6 changes: 6 additions & 0 deletions internal/command/package/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/skpr/cli/internal/buildpack/utils/finder"
"github.com/skpr/cli/internal/buildpack/utils/notation/utils"
"github.com/skpr/cli/internal/client"
"github.com/skpr/cli/internal/slice"
)

// Command to package an application.
Expand All @@ -32,6 +33,7 @@ type Command struct {
PackageDir string
Params buildpack.Params
PrintManifest bool
BuildArgs []string
Debug bool
}

Expand Down Expand Up @@ -66,6 +68,10 @@ func (cmd *Command) Run(ctx context.Context) error {
Password: client.Credentials.Password,
}

// Convert build args from slice to map.
// eg. --build-arg=KEY=VALUE to map[string]string{"KEY": "VALUE"}
cmd.Params.BuildArgs = slice.ToMap(cmd.BuildArgs, "=")

isECR := ecr.IsRegistry(cmd.Params.Registry)

// @todo, Consider abstracting this if another registry + credentials pair is required.
Expand Down
19 changes: 19 additions & 0 deletions internal/slice/slice.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package slice

import "strings"

// Contains a string within a slice.
func Contains(slice []string, s string) bool {
for _, item := range slice {
Expand Down Expand Up @@ -67,3 +69,20 @@ func AppendIfMissing(slice []string, i string) []string {

return append(slice, i)
}

// ToMap converts a slice of strings into a map using the provided delimiter.
func ToMap(slice []string, delimiter string) map[string]string {
m := make(map[string]string, len(slice))

for _, s := range slice {
sl := strings.Split(s, delimiter)

if len(sl) != 2 {
continue
}

m[sl[0]] = sl[1]
}

return m
}