Skip to content

Commit 620dd01

Browse files
authored
feat: Add --new-tag flag to override tag for immutable registries (#15)
Fixes #14
1 parent 32dbb11 commit 620dd01

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737
artifactsDbName = "artifacts.db"
3838
)
3939

40-
func indexAndPush(ctx context.Context, repo string, tag string, registryUrl string, authToken string) (string, error) {
40+
func indexAndPush(ctx context.Context, repo string, tag string, newTag string, registryUrl string, authToken string) (string, error) {
4141
ctx = context.WithValue(ctx, "RegistryURL", registryUrl)
4242

4343
registry, err := registryutils.Init(ctx, registryUrl, authToken)
@@ -86,7 +86,7 @@ func indexAndPush(ctx context.Context, repo string, tag string, registryUrl stri
8686
}
8787
ctx = context.WithValue(ctx, "SOCIIndexDigest", indexDescriptor.Digest.String())
8888

89-
err = registry.Push(ctx, sociStore, *indexDescriptor, repo, tag)
89+
err = registry.Push(ctx, sociStore, *indexDescriptor, repo, newTag)
9090
if err != nil {
9191
return logAndReturnError(ctx, PushFailedMessage, err)
9292
}

main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ var (
2020
)
2121

2222
var (
23-
auth string
23+
auth string
24+
newTag string
2425
)
2526

2627
func parseImageDesc(desc string) (repo, tag, registry string, err error) {
@@ -61,16 +62,21 @@ func main() {
6162
os.Exit(1)
6263
}
6364

64-
log.Info(ctx, fmt.Sprintf("Indexing and pushing %s:%s to %s", repo, tag, registry))
65+
if newTag == "" {
66+
newTag = tag
67+
}
68+
69+
log.Info(ctx, fmt.Sprintf("Indexing %s:%s and pushing with tag %s to %s", repo, tag, newTag, registry))
6570

66-
_, err = indexAndPush(ctx, repo, tag, registry, auth)
71+
_, err = indexAndPush(ctx, repo, tag, newTag, registry, auth)
6772
if err != nil {
6873
os.Exit(1)
6974
}
7075
},
7176
}
7277

7378
rootCmd.Flags().StringVarP(&auth, "auth", "a", "", "Registry authentication token (usually USER:PASSWORD)")
79+
rootCmd.Flags().StringVarP(&newTag, "new-tag", "t", "", "Push indexed image with this tag")
7480

7581
if err := rootCmd.Execute(); err != nil {
7682
_, _ = fmt.Fprintln(os.Stderr, err)

0 commit comments

Comments
 (0)