Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.

Commit 4a998c7

Browse files
committed
Use the first tag from the list of tags in the Webhook.
This assumes that only a single tag is sent (which from a perusal of the code is a correct assumption).
1 parent d5e5248 commit 4a998c7

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ $ kubectl create secret generic quay-imager-client --from-literal=token=$GITHUB_
5353

5454
A k8s `Deployment` is provided in [./deploy/deployment.yaml](./deploy/deployment.yaml).
5555

56+
## Exposing the Handler
57+
58+
The Service exposes a Hook handler at `/` on port 8080 that handles the hooks.
59+
5660
## Building
5761

5862
A `Dockerfile` is provided for building a container, but otherwise:

pkg/cmd/http.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func makeHTTPCmd() *cobra.Command {
3131

3232
sugar := logger.Sugar()
3333

34-
f, err := os.Open(viper.GetString("config-file"))
34+
f, err := os.Open(viper.GetString("config"))
3535
if err != nil {
3636
return err
3737
}
@@ -40,7 +40,7 @@ func makeHTTPCmd() *cobra.Command {
4040

4141
updater := hook.New(sugar, client.New(scmClient), repos)
4242
handler := hook.NewHandler(sugar, updater)
43-
http.Handle("/hook", handler)
43+
http.Handle("/", handler)
4444
listen := fmt.Sprintf(":%d", viper.GetInt("port"))
4545
sugar.Infow("quay-hooks http starting", "port", viper.GetInt("port"))
4646
return http.ListenAndServe(listen, nil)
@@ -62,11 +62,11 @@ func makeHTTPCmd() *cobra.Command {
6262
logIfError(viper.BindPFlag("driver", cmd.Flags().Lookup("driver")))
6363

6464
cmd.Flags().String(
65-
"config-file",
65+
"config",
6666
"/etc/quay-imager/config.yaml",
6767
"repository configuration",
6868
)
69-
logIfError(viper.BindPFlag("config-file", cmd.Flags().Lookup("config-file")))
69+
logIfError(viper.BindPFlag("config", cmd.Flags().Lookup("config")))
7070
return cmd
7171
}
7272

pkg/hook/update.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ func (u *Updater) Update(ctx context.Context, h *quay.RepositoryPushHook) error
4444
return err
4545
}
4646
u.log.Infow("got existing file", "sha", current.Sha)
47-
updated, err := syaml.SetBytes(current.Data, cfg.UpdateKey, h.DockerURL)
47+
newURL := fmt.Sprintf("%s:%s", h.DockerURL, h.UpdatedTags[0])
48+
49+
u.log.Infow("new image reference", "image", newURL)
50+
updated, err := syaml.SetBytes(current.Data, cfg.UpdateKey, newURL)
4851

4952
masterRef, err := u.gitClient.GetBranchHead(ctx, cfg.SourceRepo, cfg.SourceBranch)
5053
newBranchName := u.nameGenerator(cfg.BranchGenerateName)

pkg/hook/update_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestUpdaterWithKnownRepo(t *testing.T) {
3939
updater.Update(context.Background(), hook)
4040

4141
updated := m.GetUpdatedContents(testGitHubRepo, testFilePath, "known-branch")
42-
want := "test:\n image: quay.io/testorg/repo\n"
42+
want := "test:\n image: quay.io/testorg/repo:production\n"
4343
if s := string(updated); s != want {
4444
t.Fatalf("update failed, got %#v, want %#v", s, want)
4545
}
@@ -54,8 +54,9 @@ func TestUpdaterWithKnownRepo(t *testing.T) {
5454

5555
func createHook() *quay.RepositoryPushHook {
5656
return &quay.RepositoryPushHook{
57-
Repository: testQuayRepo,
58-
DockerURL: "quay.io/testorg/repo",
57+
Repository: testQuayRepo,
58+
DockerURL: "quay.io/testorg/repo",
59+
UpdatedTags: []string{"production"},
5960
}
6061
}
6162

0 commit comments

Comments
 (0)