Skip to content

Commit

Permalink
feat: add support to overwrite PathSeparator
Browse files Browse the repository at this point in the history
Signed-off-by: lukeb2e <12938238+lukeb2e@users.noreply.github.com>
  • Loading branch information
lukeb2e committed Apr 9, 2019
1 parent b9c6ac5 commit 681e240
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 6 additions & 3 deletions api/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ package v1
import (
"bufio"
"fmt"
log "github.com/sirupsen/logrus"
"io"
"runtime"
"strings"
"time"

log "github.com/sirupsen/logrus"

"github.com/ivanilves/lstags/api/v1/collection"
dockerclient "github.com/ivanilves/lstags/docker/client"
dockerconfig "github.com/ivanilves/lstags/docker/config"
Expand Down Expand Up @@ -49,6 +50,8 @@ type PushConfig struct {
Registry string
// UpdateChanged tells us if we will re-push (update/overwrite) images having same tag, but different digest
UpdateChanged bool
// PathSeperator defines which path seperator to use (default: "/")
PathSeperator string
}

// API represents configured application API instance,
Expand Down Expand Up @@ -240,7 +243,7 @@ func (api *API) CollectPushTags(cn *collection.Collection, push PushConfig) (*co
pushRef := fmt.Sprintf(
"%s%s~/.*/",
push.Registry,
getPushPrefix(push.Prefix, repo.PushPrefix())+repo.Path(),
getPushPrefix(push.Prefix, repo.PushPrefix())+repo.PushPath(push.PathSeperator),
)

log.Debugf("%s 'push' reference: %+v", fn(repo.Ref()), pushRef)
Expand Down Expand Up @@ -382,7 +385,7 @@ func (api *API) PushTags(cn *collection.Collection, push PushConfig) error {
go func(repo *repository.Repository, tags []*tag.Tag, done chan error) {
for _, tg := range tags {
srcRef := repo.Name() + ":" + tg.Name()
dstRef := push.Registry + getPushPrefix(push.Prefix, repo.PushPrefix()) + repo.Path() + ":" + tg.Name()
dstRef := push.Registry + getPushPrefix(push.Prefix, repo.PushPrefix()) + repo.PushPath(push.PathSeperator) + ":" + tg.Name()

log.Infof("[PULL/PUSH] PUSHING %s => %s", srcRef, dstRef)

Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/jessevdk/go-flags"

"github.com/ivanilves/lstags/api/v1"
v1 "github.com/ivanilves/lstags/api/v1"
"github.com/ivanilves/lstags/config"
)

Expand All @@ -21,6 +21,7 @@ type Options struct {
PushRegistry string `short:"r" long:"push-registry" description:"[Re]Push pulled images to a specified remote registry" env:"PUSH_REGISTRY"`
PushPrefix string `short:"R" long:"push-prefix" description:"[Re]Push pulled images with a specified repo path prefix" env:"PUSH_PREFIX"`
PushUpdate bool `short:"U" long:"push-update" description:"Update our pushed images if remote image digest changes" env:"PUSH_UPDATE"`
PathSeperator string `short:"s" long:"path-seperator" default:"/" description:"Configure path seperator for registries that only allow single folder depth" env:"PATH_SEPERATOR"`
ConcurrentRequests int `short:"c" long:"concurrent-requests" default:"32" description:"Limit of concurrent requests to the registry" env:"CONCURRENT_REQUESTS"`
WaitBetween time.Duration `short:"w" long:"wait-between" default:"0" description:"Time to wait between batches of requests (incl. pulls and pushes)" env:"WAIT_BETWEEN"`
RetryRequests int `short:"y" long:"retry-requests" default:"2" description:"Number of retries for failed Docker registry requests" env:"RETRY_REQUESTS"`
Expand Down Expand Up @@ -162,6 +163,7 @@ func main() {
Registry: o.PushRegistry,
Prefix: o.PushPrefix,
UpdateChanged: o.PushUpdate,
PathSeperator: o.PathSeperator,
}

pushCollection, err := api.CollectPushTags(collection, pushConfig)
Expand Down
9 changes: 9 additions & 0 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ func (r *Repository) Path() string {
return path
}

// PushPath gives us sanitized repository path and checks if subdirectories are allowed
func (r *Repository) PushPath(pathSeperator string) string {
path := r.Path()

path = strings.Join(strings.Split(path, "/"), pathSeperator)

return path
}

// HasTags tells us if we've specified some concrete tags for this repository
func (r *Repository) HasTags() bool {
return r.repoTags != nil && len(r.repoTags) != 0
Expand Down

0 comments on commit 681e240

Please sign in to comment.